generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SILVA-581): Change the action columns from the home screen and op…
…ening search (#523)
- Loading branch information
1 parent
0ea2145
commit 0978fce
Showing
18 changed files
with
219 additions
and
264 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 +1,41 @@ | ||
// ActionButtons.test.tsx | ||
import React from "react"; | ||
import { vi } from "vitest"; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import ActionButtons from "../../components/ActionButtons"; | ||
|
||
// Mock console.log | ||
const consoleLogMock = vi.spyOn(console, "log").mockImplementationOnce(() =>vi.fn()) ; | ||
|
||
afterEach(() => { | ||
consoleLogMock.mockClear(); | ||
}); | ||
|
||
afterAll(() => { | ||
consoleLogMock.mockRestore(); | ||
}); | ||
import { NotificationProvider } from "../../contexts/NotificationProvider" | ||
|
||
describe("ActionButtons", () => { | ||
const rowId = "test-row-id"; | ||
|
||
it("renders the 'View' and 'Document Download' buttons", () => { | ||
render(<ActionButtons rowId={rowId} />); | ||
const rowId = "123456"; | ||
const favorited = false; | ||
|
||
it("renders the 'Favorite Opening' and 'Document Download' buttons", () => { | ||
render( | ||
<MemoryRouter> | ||
<NotificationProvider> | ||
<ActionButtons favorited={favorited} rowId={rowId} /> | ||
</NotificationProvider> | ||
</MemoryRouter> | ||
); | ||
|
||
// Check that both buttons are in the document | ||
expect(screen.getByRole("button", { name: /View/i })).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /Favorite Opening/i })).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /Document Download/i })).toBeInTheDocument(); | ||
}); | ||
|
||
it("calls console.log with rowId when the 'View' button is clicked", () => { | ||
render(<ActionButtons rowId={rowId} />); | ||
it("set the 'Favorite Opening' as favorited when button is clicked", () => { | ||
render( | ||
<MemoryRouter> | ||
<NotificationProvider> | ||
<ActionButtons favorited={favorited} rowId={rowId} /> | ||
</NotificationProvider> | ||
</MemoryRouter> | ||
); | ||
|
||
// Find the "View" button and click it | ||
const viewButton = screen.getByRole("button", { name: /View/i }); | ||
const viewButton = screen.getByRole("button", { name: /Favorite Opening/i }); | ||
expect(viewButton.classList).toContain('favorite-button'); | ||
fireEvent.click(viewButton); | ||
|
||
// Check if console.log was called with the correct rowId | ||
expect(consoleLogMock).toHaveBeenCalledWith(rowId); | ||
expect(screen.getByRole("button", { name: /Favorite Opening/i }).classList).toContain('favorite'); | ||
}); | ||
}); |
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.