generated from MeasureAuthoringTool/madie-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
464e7e0
commit ae6f1b9
Showing
1 changed file
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as React from "react"; | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { cleanup, render, screen, waitFor } from "@testing-library/react"; | ||
import { CqlLibrary, Model } from "@madie/madie-models"; | ||
import CqlLibraryList from "./CqlLibraryList"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
@@ -35,14 +35,19 @@ const cqlLibrary: CqlLibrary[] = [ | |
librarySetId: "librarySetId1", | ||
cqlLibraryName: "testing1", | ||
model: Model.QICORE, | ||
createdAt: "", | ||
createdAt: "1", | ||
createdBy: "[email protected]", | ||
lastModifiedAt: "", | ||
lastModifiedBy: "", | ||
draft: true, | ||
version: "0.0.000", | ||
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'", | ||
cqlErrors: false, | ||
librarySet: { | ||
id: "1", | ||
librarySetId: "librarySetId1", | ||
owner: "[email protected]", | ||
}, | ||
}, | ||
{ | ||
id: "622e1f46d1fd3729d861e6c1", | ||
|
@@ -51,12 +56,17 @@ const cqlLibrary: CqlLibrary[] = [ | |
model: Model.QICORE, | ||
createdAt: "", | ||
createdBy: "[email protected]", | ||
lastModifiedAt: "", | ||
lastModifiedAt: "2", | ||
lastModifiedBy: "null", | ||
draft: true, | ||
version: "0.0.000", | ||
cql: "library AdvancedIllnessandFrailtyExclusion_QICore4 version '5.0.00'", | ||
cqlErrors: false, | ||
librarySet: { | ||
id: "2", | ||
librarySetId: "librarySetId2", | ||
owner: "[email protected]", | ||
}, | ||
}, | ||
]; | ||
|
||
|
@@ -71,10 +81,12 @@ const useCqlLibraryServiceMockResolved = { | |
createVersion: jest.fn().mockResolvedValue({}), | ||
createDraft: jest.fn().mockResolvedValue({}), | ||
deleteDraft: jest.fn().mockResolvedValue({}), | ||
fetchCqlLibrary: jest.fn().mockResolvedValue({}), | ||
} as unknown as CqlLibraryServiceApi; | ||
|
||
describe("CqlLibrary List component", () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
useCqlLibraryServiceMockResolved.createVersion = jest | ||
.fn() | ||
.mockResolvedValue({}); | ||
|
@@ -84,11 +96,17 @@ describe("CqlLibrary List component", () => { | |
useCqlLibraryServiceMockResolved.deleteDraft = jest | ||
.fn() | ||
.mockResolvedValue({}); | ||
useCqlLibraryServiceMock.mockImplementation(() => { | ||
useCqlLibraryServiceMockResolved.fetchCqlLibrary = jest | ||
.fn() | ||
.mockResolvedValue({}); | ||
useCqlLibraryServiceMock.mockReset().mockImplementation(() => { | ||
return useCqlLibraryServiceMockResolved; | ||
}); | ||
(checkUserCanEdit as jest.Mock).mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it("should display a list of Cql Libraries", () => { | ||
const { getByText, getByTestId } = render( | ||
|
@@ -133,7 +151,7 @@ describe("CqlLibrary List component", () => { | |
); | ||
}); | ||
|
||
it("should display version button for draft libraries and on click should render dialog", () => { | ||
it("should display version button for draft libraries and on click should render dialog", async () => { | ||
render( | ||
<CqlLibraryList | ||
cqlLibraryList={cqlLibrary} | ||
|
@@ -149,7 +167,7 @@ describe("CqlLibrary List component", () => { | |
`create-new-version-${cqlLibrary[0].id}-button` | ||
); | ||
|
||
userEvent.click(versionButton); | ||
await userEvent.click(versionButton); | ||
expect(screen.getByTestId("create-version-dialog")).toBeInTheDocument(); | ||
}); | ||
|
||
|
@@ -430,13 +448,31 @@ describe("CqlLibrary List component", () => { | |
`view/edit-cqlLibrary-button-${cqlLibrary[0].id}` | ||
); | ||
userEvent.click(viewEditButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId(`create-new-version-${cqlLibrary[0].id}-button`) | ||
).toBeInTheDocument(); | ||
}); | ||
const versionButton = screen.getByTestId( | ||
`create-new-version-${cqlLibrary[0].id}-button` | ||
); | ||
userEvent.click(versionButton); | ||
userEvent.click(screen.getByLabelText("Major")); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByLabelText("Major")).toBeInTheDocument(); | ||
}); | ||
const majorButton = screen.getByLabelText("Major"); | ||
userEvent.click(majorButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId("create-version-continue-button") | ||
).toBeInTheDocument(); | ||
}); | ||
const continueButton = screen.getByTestId("create-version-continue-button"); | ||
userEvent.click(continueButton); | ||
await waitFor(() => { | ||
userEvent.click(screen.getByTestId("create-version-continue-button")); | ||
expect(loadCqlLibraries).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
@@ -450,6 +486,7 @@ describe("CqlLibrary List component", () => { | |
}, | ||
}; | ||
const useCqlLibraryServiceMockRejected = { | ||
fetchCqlLibrary: jest.fn().mockResolvedValue(cqlLibrary[0]), | ||
createVersion: jest.fn().mockRejectedValue(error), | ||
} as unknown as CqlLibraryServiceApi; | ||
|
||
|
@@ -468,13 +505,31 @@ describe("CqlLibrary List component", () => { | |
); | ||
userEvent.click(viewEditButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId(`create-new-version-${cqlLibrary[0].id}-button`) | ||
).toBeInTheDocument(); | ||
}); | ||
const versionButton = screen.getByTestId( | ||
`create-new-version-${cqlLibrary[0].id}-button` | ||
); | ||
userEvent.click(versionButton); | ||
userEvent.click(screen.getByLabelText("Major")); | ||
|
||
await waitFor(() => { | ||
userEvent.click(screen.getByTestId("create-version-continue-button")); | ||
expect(screen.getByLabelText("Major")).toBeInTheDocument(); | ||
}); | ||
const majorButton = screen.getByLabelText("Major"); | ||
userEvent.click(majorButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId("create-version-continue-button") | ||
).toBeInTheDocument(); | ||
}); | ||
const continueButton = screen.getByTestId("create-version-continue-button"); | ||
|
||
await waitFor(() => { | ||
userEvent.click(continueButton); | ||
expect(screen.getByTestId("cql-library-list-snackBar")).toHaveTextContent( | ||
"Requested Cql Library cannot be versioned" | ||
); | ||
|
@@ -490,6 +545,7 @@ describe("CqlLibrary List component", () => { | |
}, | ||
}; | ||
const useCqlLibraryServiceMockRejected = { | ||
fetchCqlLibrary: jest.fn().mockResolvedValue(cqlLibrary[0]), | ||
createVersion: jest.fn().mockRejectedValue(error), | ||
} as unknown as CqlLibraryServiceApi; | ||
|
||
|
@@ -507,13 +563,31 @@ describe("CqlLibrary List component", () => { | |
`view/edit-cqlLibrary-button-${cqlLibrary[0].id}` | ||
); | ||
userEvent.click(viewEditButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId(`create-new-version-${cqlLibrary[0].id}-button`) | ||
).toBeInTheDocument(); | ||
}); | ||
const versionButton = screen.getByTestId( | ||
`create-new-version-${cqlLibrary[0].id}-button` | ||
); | ||
userEvent.click(versionButton); | ||
userEvent.click(screen.getByLabelText("Major")); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByLabelText("Major")).toBeInTheDocument(); | ||
}); | ||
const majorButton = screen.getByLabelText("Major"); | ||
userEvent.click(majorButton); | ||
|
||
await waitFor(() => { | ||
userEvent.click(screen.getByTestId("create-version-continue-button")); | ||
expect( | ||
screen.getByTestId("create-version-continue-button") | ||
).toBeInTheDocument(); | ||
}); | ||
const continueButton = screen.getByTestId("create-version-continue-button"); | ||
await waitFor(() => { | ||
userEvent.click(continueButton); | ||
expect(screen.getByTestId("cql-library-list-snackBar")).toHaveTextContent( | ||
"User is unauthorized to create a version" | ||
); | ||
|
@@ -531,6 +605,7 @@ describe("CqlLibrary List component", () => { | |
}; | ||
const useCqlLibraryServiceMockRejected = { | ||
createVersion: jest.fn().mockRejectedValue(error), | ||
fetchCqlLibrary: jest.fn().mockResolvedValue(cqlLibrary[0]), | ||
} as unknown as CqlLibraryServiceApi; | ||
|
||
useCqlLibraryServiceMock.mockImplementation(() => { | ||
|
@@ -547,13 +622,31 @@ describe("CqlLibrary List component", () => { | |
`view/edit-cqlLibrary-button-${cqlLibrary[0].id}` | ||
); | ||
userEvent.click(viewEditButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId(`create-new-version-${cqlLibrary[0].id}-button`) | ||
).toBeInTheDocument(); | ||
}); | ||
const versionButton = screen.getByTestId( | ||
`create-new-version-${cqlLibrary[0].id}-button` | ||
); | ||
userEvent.click(versionButton); | ||
userEvent.click(screen.getByLabelText("Major")); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByLabelText("Major")).toBeInTheDocument(); | ||
}); | ||
const majorButton = screen.getByLabelText("Major"); | ||
userEvent.click(majorButton); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId("create-version-continue-button") | ||
).toBeInTheDocument(); | ||
}); | ||
const continueButton = screen.getByTestId("create-version-continue-button"); | ||
await waitFor(() => { | ||
userEvent.click(screen.getByTestId("create-version-continue-button")); | ||
userEvent.click(continueButton); | ||
expect(screen.getByTestId("cql-library-list-snackBar")).toHaveTextContent( | ||
"Internal server error" | ||
); | ||
|