From d07f1898eb513b0d758e64c4933ec6400a3cf7e4 Mon Sep 17 00:00:00 2001 From: Ronaldo Macapobre Date: Tue, 25 Feb 2025 23:47:18 +0000 Subject: [PATCH] - Fix failing unit tests - Use getLocations(true) --- .../components/courtlist/CourtListSearch.vue | 2 +- .../courtList/CourtListSearch.test.ts | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/web/src/components/courtlist/CourtListSearch.vue b/web/src/components/courtlist/CourtListSearch.vue index 3dc049e9..093b6383 100644 --- a/web/src/components/courtlist/CourtListSearch.vue +++ b/web/src/components/courtlist/CourtListSearch.vue @@ -143,7 +143,7 @@ const getListOfAvailableCourts = async () => { locationsAndCourtRooms.value = - await locationsService?.getLocations(); + await locationsService?.getLocations(true); commonStore.updateCourtRoomsAndLocations(locationsAndCourtRooms.value); isLocationDataMounted.value = true; }; diff --git a/web/tests/components/courtList/CourtListSearch.test.ts b/web/tests/components/courtList/CourtListSearch.test.ts index cd53baa5..eb77f9a2 100644 --- a/web/tests/components/courtList/CourtListSearch.test.ts +++ b/web/tests/components/courtList/CourtListSearch.test.ts @@ -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'; @@ -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({}), @@ -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); @@ -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'); @@ -104,15 +106,15 @@ 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'); @@ -120,7 +122,7 @@ describe('CourtListSearch.vue', () => { await wrapper.vm.searchForCourtList(); await nextTick(); - + expect(wrapper.emitted().courtListSearched).toBeTruthy(); }); });