Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ class Instance {
type,
principal,
}: {
after: Date;
after?: Date;
type?: string;
principal?: string;
}) {
return this.axios.get(uri`actuator/auditevents`, {
params: {
after: after.toISOString(),
after: after?.toISOString(),
type: type,
principal: principal,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import userEvent from '@testing-library/user-event';
import { screen, waitFor } from '@testing-library/vue';
import { fireEvent, screen, waitFor } from '@testing-library/vue';
import { HttpResponse, http } from 'msw';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { applications } from '@/mocks/applications/data';
import { server } from '@/mocks/server';
import Application from '@/services/application';
import Instance from '@/services/instance';
import { render } from '@/test-utils';
import Auditevents from '@/views/instances/auditevents/index.vue';
Expand Down Expand Up @@ -73,3 +77,25 @@ describe('Auditevents', () => {
return instance;
}
});

it('sends the edited local date and omits after when the filter is cleared', async () => {
const dates: (string | null)[] = [];
server.use(
http.get('*/actuator/auditevents', ({ request }) => {
dates.push(new URL(request.url).searchParams.get('after'));
return HttpResponse.json({ events: [] });
}),
);
render(Auditevents, {
props: { instance: new Application(applications[0]).instances[0] },
});
const input = screen.getByPlaceholderText('Date');
await waitFor(() => expect(dates).toHaveLength(1));

await fireEvent.update(input, '2025-04-07T10:30');
await waitFor(() =>
expect(dates.at(-1)).toBe(new Date(2025, 3, 7, 10, 30).toISOString()),
);
await fireEvent.update(input, '');
await waitFor(() => expect(dates.at(-1)).toBeNull());
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
/>

<sba-input
:value="formatDate(filter.after)"
v-model="filter.after"
name="filter_datetime"
placeholder="Date"
type="datetime-local"
@input="filter.after = parseDate($event.target.value)"
/>
</div>
</sba-sticky-subnav>
Expand Down Expand Up @@ -128,7 +127,7 @@ export default {
error: null,
events: [],
filter: {
after: moment().startOf('day'),
after: moment().startOf('day').format(moment.HTML5_FMT.DATETIME_LOCAL),
type: null,
principal: null,
},
Expand All @@ -142,17 +141,16 @@ export default {
},
},
methods: {
formatDate(value) {
return value.format(moment.HTML5_FMT.DATETIME_LOCAL);
},
parseDate(value) {
return moment(value, moment.HTML5_FMT.DATETIME_LOCAL, true).toDate();
},
async fetchAuditevents() {
this.isLoading = !this.hasLoadedInitially;

try {
const response = await this.instance.fetchAuditevents(this.filter);
const response = await this.instance.fetchAuditevents({
...this.filter,
after: this.filter.after
? moment(this.filter.after).toDate()
: undefined,
});
const converted = response.data.events.map(
(event) => new Auditevent(event),
);
Expand Down
Loading