diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.test.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.test.js index 5db0872b198ec94f54070bbe582d30fafcf8ff70..239c78fc52ed7c4102c31fbde3a1a7c9ecb43010 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.test.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.test.js @@ -45,7 +45,11 @@ const setMockSpy = async () => { projectListSpy = jest.spyOn(ProjectService, 'getProjectList'); projectListSpy.mockImplementation(() => { return Promise.resolve(ProjectServiceMock.projectList)}); scheduleSetListSpy = jest.spyOn(ScheduleService, 'getSchedulingSets'); - scheduleSetListSpy.mockImplementation(() => { return Promise.resolve(SUServiceMock.scheduleSetList)}); + scheduleSetListSpy.mockImplementation((filter) => { + let allSUSets = SUServiceMock.scheduleSetList; + let project = filter.replace("project=",""); + return Promise.resolve(_.filter(allSUSets, {project_id: project})); + }); observStrategiesSpy = jest.spyOn(ScheduleService, 'getObservationStrategies'); // observStrategiesSpy.mockImplementation(() => { return Promise.resolve(SUServiceMock.observStrategies)}); observStrategiesSpy.mockImplementation(() => { return Promise.resolve(SUServiceMock.getObservStrategies())}); @@ -147,7 +151,6 @@ it(" 1. renders SU create page with all fields and default values", async() => { expect(content.queryByText('Scheduling Unit - Add')).not.toBe(null); // Page loaded successfully expect(projectListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(observStrategiesSpy).toHaveBeenCalled(); // Mock Spy called successfully - expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(taskTemplatesSpy).toHaveBeenCalled(); // Mock Spy called successfully const nameInputEl = content.queryByTestId('name'); @@ -159,9 +162,13 @@ it(" 1. renders SU create page with all fields and default values", async() => { expect(descInputEl.value).toBe("SU High 1 Desc"); const projInputEl = content.getAllByRole("listbox")[0].children[0] ; - fireEvent.click(projInputEl); + await act(async () => { + fireEvent.click(projInputEl); + await new Promise((r) => setTimeout(r, 500)); + }); expect(content.queryAllByText("high").length).toBe(3); - + expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully + const suSetInputEl = content.getAllByRole("listbox")[1].children[0] ; fireEvent.click(suSetInputEl); expect(content.queryAllByText("Test Scheduling Set").length).toBe(1); diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js index e946dd21ef80b306a78939ec7138f75be348c94a..6fa75aa39e3e0899ec0ad93b22d715ebf00e6fa3 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js @@ -43,7 +43,11 @@ const setMockSpy = () => { projectListSpy = jest.spyOn(ProjectService, 'getProjectList'); projectListSpy.mockImplementation(() => { return Promise.resolve(ProjectServiceMock.projectList)}); scheduleSetListSpy = jest.spyOn(ScheduleService, 'getSchedulingSets'); - scheduleSetListSpy.mockImplementation(() => { return Promise.resolve(SUServiceMock.scheduleSetList)}); + scheduleSetListSpy.mockImplementation((filter) => { + let allSUSets = SUServiceMock.scheduleSetList; + let project = filter.replace("project=",""); + return Promise.resolve(_.filter(allSUSets, {project_id: project})); + }); observStrategiesSpy = jest.spyOn(ScheduleService, 'getObservationStrategies'); observStrategiesSpy.mockImplementation(() => { return Promise.resolve(SUServiceMock.getObservStrategies())}); taskTemplatesSpy = jest.spyOn(TaskService, 'getTaskTemplates'); @@ -130,23 +134,28 @@ it("renders SU Set create page with all fields and default values", async() => { expect(content.queryByText('Scheduling Unit(s)')).toBe(null); // AG Grid not visible expect(projectListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(observStrategiesSpy).toHaveBeenCalled(); // Mock Spy called successfully - expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(taskTemplatesSpy).toHaveBeenCalled(); // Mock Spy called successfully //It is disabled before select any project expect(content.queryByTestId('addSet')).toHaveAttribute("disabled"); const projInputEl = content.getAllByRole("listbox")[0].children[0] ; - fireEvent.click(projInputEl); + await act( async() => { + fireEvent.click(projInputEl); + await new Promise((r) => setTimeout(r, 500)); + }); + expect(content.queryAllByText("high").length).toBe(3); - + expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully // It should be enabled after select project expect(content.queryByTestId('addSet').hasAttribute("disabled")).toBeFalsy(); - const suSetInputEl = content.getAllByRole("listbox")[1].children[0] ; - fireEvent.click(suSetInputEl); + expect(content.queryAllByText("Test Scheduling Set").length).toBe(1); + await act( async() => { + fireEvent.click(suSetInputEl); + await new Promise((r) => setTimeout(r, 500)); + }); expect(content.queryAllByText("Test Scheduling Set").length).toBe(3); - expect(content.queryByTestId('save-btn').hasAttribute("disabled")).toBeFalsy(); }); @@ -162,15 +171,19 @@ it("renders AG grid loaded in SU Set create Page", async() => { expect(content.queryByText('Scheduling Unit(s)')).toBe(null); // AG Grid not visible expect(projectListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(observStrategiesSpy).toHaveBeenCalled(); // Mock Spy called successfully - expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully expect(taskTemplatesSpy).toHaveBeenCalled(); // Mock Spy called successfully //It is disabled before select any project expect(content.queryByTestId('addSet')).toHaveAttribute("disabled"); const projInputEl = content.getAllByRole("listbox")[0].children[0] ; - fireEvent.click(projInputEl); + expect(content.queryAllByText("high").length).toBe(1); + await act( async() => { + fireEvent.click(projInputEl); + await new Promise((r) => setTimeout(r, 1000)); + }); expect(content.queryAllByText("high").length).toBe(3); + expect(scheduleSetListSpy).toHaveBeenCalled(); // Mock Spy called successfully // It should be enabled after select project expect(content.queryByTestId('addSet').hasAttribute("disabled")).toBeFalsy();