-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add tests for the provider list
- Loading branch information
Showing
9 changed files
with
101 additions
and
10 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
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 +1,2 @@ | ||
export { default } from "./DeleteProviderBtn"; | ||
export { TestId as DeleteProviderBtnTestId } from "./test-types"; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum TestId { | ||
COMPONENT = "DeleteProviderBtn", | ||
} |
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
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 +1,2 @@ | ||
export { default } from "./EditProviderBtn"; | ||
export { TestId as EditProviderBtnTestId } from "./test-types"; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum TestId { | ||
COMPONENT = "EditProviderBtn", | ||
} |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { screen } from "@testing-library/dom"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
import { axiosInstance } from "api/axios"; | ||
import { customWithin } from "test/queries/within"; | ||
import { mockIdentityProvider } from "test/mocks/providers"; | ||
import { mockPaginatedResponse } from "test/mocks/responses"; | ||
import { renderComponent } from "test/utils"; | ||
|
||
import { DeleteProviderBtnTestId } from "../DeleteProviderBtn"; | ||
import { EditProviderBtnTestId } from "../EditProviderBtn"; | ||
|
||
import { Label } from "./types"; | ||
import ProviderList from "./ProviderList"; | ||
import { Location } from "react-router-dom"; | ||
import { panels } from "util/usePanelParams"; | ||
|
||
const mock = new MockAdapter(axiosInstance); | ||
|
||
beforeEach(() => { | ||
mock.reset(); | ||
mock.onGet("/idps").reply(200, mockPaginatedResponse([], { _meta: {} })); | ||
}); | ||
|
||
test("displays provider rows", async () => { | ||
const provider = { | ||
id: faker.word.sample(), | ||
provider: faker.word.sample(), | ||
}; | ||
const providers = [mockIdentityProvider(provider)]; | ||
mock | ||
.onGet("/idps") | ||
.reply(200, mockPaginatedResponse(providers, { _meta: {} })); | ||
renderComponent(<ProviderList />); | ||
const row = await screen.findByRole("row", { | ||
name: new RegExp(provider.id), | ||
}); | ||
expect( | ||
customWithin(row).getCellByHeader(Label.HEADER_NAME, { role: "rowheader" }), | ||
).toHaveTextContent(provider.id); | ||
expect( | ||
customWithin(row).getCellByHeader(Label.HEADER_PROVIDER, { | ||
role: "gridcell", | ||
hasRowHeader: true, | ||
}), | ||
).toHaveTextContent(provider.provider); | ||
}); | ||
|
||
test("opens add provider panel", async () => { | ||
let location: Location | null = null; | ||
renderComponent(<ProviderList />, { | ||
setLocation: (newLocation) => { | ||
location = newLocation; | ||
}, | ||
}); | ||
await userEvent.click(screen.getByRole("button", { name: Label.ADD })); | ||
expect((location as Location | null)?.search).toBe( | ||
`?panel=${panels.providerCreate}`, | ||
); | ||
}); | ||
|
||
test("displays edit and delete buttons", async () => { | ||
const providers = [mockIdentityProvider()]; | ||
mock | ||
.onGet("/idps") | ||
.reply(200, mockPaginatedResponse(providers, { _meta: {} })); | ||
renderComponent(<ProviderList />); | ||
expect( | ||
await screen.findByTestId(EditProviderBtnTestId.COMPONENT), | ||
).toBeInTheDocument(); | ||
expect( | ||
await screen.findByTestId(DeleteProviderBtnTestId.COMPONENT), | ||
Check failure on line 74 in ui/src/pages/providers/ProviderList/ProviderList.test.tsx GitHub Actions / Test (20.x)src/pages/providers/ProviderList/ProviderList.test.tsx > displays edit and delete buttons
|
||
).toBeInTheDocument(); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum Label { | ||
ADD = "Add ID provider", | ||
HEADER_ACTIONS = "Actions", | ||
HEADER_NAME = "Name", | ||
HEADER_PROVIDER = "Provider", | ||
} |