-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AnnouncementBanner tests; Fix defaultState redundancy (#3311)
- Loading branch information
1 parent
f90b698
commit 0812f13
Showing
25 changed files
with
131 additions
and
110 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
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,73 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { act } from "react"; | ||
import { Provider } from "react-redux"; | ||
import createMockStore from "redux-mock-store"; | ||
|
||
import AnnouncementBanner, { | ||
AnnouncementBannerTextId, | ||
} from "components/AnnouncementBanner"; | ||
import { defaultState } from "rootRedux/types"; | ||
|
||
jest.mock("backend", () => ({ | ||
getBannerText: () => mockGetBannerText(), | ||
})); | ||
|
||
const mockBannerText = "I'm a banner!"; | ||
const mockGetBannerText = jest.fn(); | ||
const mockStore = createMockStore()(defaultState); | ||
|
||
const renderAnnouncementBanner = async (bannerText?: string): Promise<void> => { | ||
mockGetBannerText.mockResolvedValue(bannerText ?? ""); | ||
await act(async () => { | ||
render( | ||
<Provider store={mockStore}> | ||
<AnnouncementBanner /> | ||
</Provider> | ||
); | ||
}); | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("AnnouncementBanner", () => { | ||
it("doesn't load if no banner text", async () => { | ||
await renderAnnouncementBanner(); | ||
|
||
// Confirm no banner by the absence of its close button | ||
expect( | ||
screen.queryByLabelText(AnnouncementBannerTextId.ButtonClose) | ||
).toBeNull(); | ||
}); | ||
|
||
it("loads banner with text", async () => { | ||
await renderAnnouncementBanner(mockBannerText); | ||
|
||
// Confirm open banner by the presence of its close button and text | ||
expect( | ||
screen.queryByLabelText(AnnouncementBannerTextId.ButtonClose) | ||
).not.toBeNull(); | ||
expect(screen.queryByText(mockBannerText)).not.toBeNull(); | ||
}); | ||
|
||
it("closes when button is clicked", async () => { | ||
// Setup | ||
const agent = userEvent.setup(); | ||
await renderAnnouncementBanner(mockBannerText); | ||
expect(screen.queryByText(mockBannerText)).not.toBeNull(); | ||
|
||
// Click close button | ||
const closeButton = screen.getByLabelText( | ||
AnnouncementBannerTextId.ButtonClose | ||
); | ||
await agent.click(closeButton); | ||
|
||
// Confirm closed | ||
expect( | ||
screen.queryByLabelText(AnnouncementBannerTextId.ButtonClose) | ||
).toBeNull(); | ||
expect(screen.queryByText(mockBannerText)).toBeNull(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/components/App/component.tsx → src/components/App/index.tsx
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
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
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
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
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
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
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
Oops, something went wrong.