Skip to content

Commit

Permalink
- Fix failing unit tests
Browse files Browse the repository at this point in the history
- Use getLocations(true)
  • Loading branch information
Ronaldo Macapobre committed Feb 25, 2025
1 parent e80282e commit d07f189
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion web/src/components/courtlist/CourtListSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
const getListOfAvailableCourts = async () => {
locationsAndCourtRooms.value =
await locationsService?.getLocations();
await locationsService?.getLocations(true);
commonStore.updateCourtRoomsAndLocations(locationsAndCourtRooms.value);
isLocationDataMounted.value = true;
};
Expand Down
34 changes: 18 additions & 16 deletions web/tests/components/courtList/CourtListSearch.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import CourtListSearch from 'CMP/courtlist/CourtListSearch.vue';
import { LocationService } from '@/services';
import { HttpService } from '@/services/HttpService';
import { useCommonStore, useCourtListStore } from '@/stores';
import { mount } from '@vue/test-utils';
import CourtListSearch from 'CMP/courtlist/CourtListSearch.vue';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { nextTick } from 'vue';

Expand All @@ -27,11 +27,13 @@ describe('CourtListSearch.vue', () => {
},
};
locationService = {
getLocationsAndCourtRooms: vi
.fn()
.mockResolvedValue([
{ locationId: 1, locationNm: 'Location 1', courtRooms: ['Room 1'] },
]),
getLocations: vi.fn().mockResolvedValue([
{
locationId: 1,
name: 'Location 1',
courtRooms: [{ room: 'Room 1' }],
},
]),
};
httpService = {
get: vi.fn().mockResolvedValue({}),
Expand All @@ -57,17 +59,17 @@ describe('CourtListSearch.vue', () => {
});

it('fetches court locations on mount', async () => {
expect(locationService.getLocationsAndCourtRooms).toHaveBeenCalled();
expect(locationService.getLocations).toHaveBeenCalled();
expect(commonStore.updateCourtRoomsAndLocations).toHaveBeenCalledWith([
{ locationId: 1, locationNm: 'Location 1', courtRooms: ['Room 1'] },
{ locationId: 1, name: 'Location 1', courtRooms: [{ room: 'Room 1' }] },
]);
});

it('should pass form validation', async () => {
wrapper.vm.selectedCourtLocation = {
locationId: 1,
locationNm: 'Location 1',
courtRooms: ['Room 1'],
name: 'Location 1',
courtRooms: [{ room: 'Room 1' }],
};
wrapper.vm.selectedCourtRoom = 'Room 1';
expect(wrapper.vm.validateForm()).toBe(true);
Expand All @@ -92,8 +94,8 @@ describe('CourtListSearch.vue', () => {
it('searches for court list', async () => {
wrapper.vm.selectedCourtLocation = {
locationId: 1,
locationNm: 'Location 1',
courtRooms: ['Room 1'],
name: 'Location 1',
courtRooms: [{ room: 'Room 1' }],
};
wrapper.vm.selectedCourtRoom = 'Room 1';
wrapper.vm.date = new Date('2023-01-01');
Expand All @@ -104,23 +106,23 @@ describe('CourtListSearch.vue', () => {
'api/courtlist/court-list?agencyId=1&roomCode=Room 1&proceeding=2023-01-01'
);
await nextTick();

expect(courtListStore.courtListInformation.detailsData).toEqual({});
});

it('emits courtListSearched event', async () => {
wrapper.vm.selectedCourtLocation = {
locationId: 1,
locationNm: 'Location 1',
courtRooms: ['Room 1'],
name: 'Location 1',
courtRooms: [{ room: 'Room 1' }],
};
wrapper.vm.selectedCourtRoom = 'Room 1';
wrapper.vm.date = new Date('2023-01-01');
wrapper.vm.schedule = 'my_schedule';

await wrapper.vm.searchForCourtList();
await nextTick();

expect(wrapper.emitted().courtListSearched).toBeTruthy();
});
});

0 comments on commit d07f189

Please sign in to comment.