-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Shubh942/master4
Added context Api in webapp for state managment
- Loading branch information
Showing
7 changed files
with
190 additions
and
46 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
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
46 changes: 38 additions & 8 deletions
46
webapp/src/components/DebugHeader/__tests__/DebugHeader.test.jsx
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,26 +1,56 @@ | ||
// DebugHeader.test.jsx | ||
|
||
import React from "react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import DebugHeader from "../DebugHeader.jsx"; | ||
import { DataContext } from "../../../context/DataContext.jsx"; | ||
|
||
describe("DebugHeader Component", () => { | ||
test("renders DebugHeader component with icons and filename", async () => { | ||
render(<DebugHeader />); | ||
test("renders DebugHeader component with icons and filename", () => { | ||
render( | ||
<DataContext.Provider value={{ refresh: false, setRefresh: vi.fn() }}> | ||
<DebugHeader /> | ||
</DataContext.Provider> | ||
); | ||
|
||
const filenameContent = screen.getByText(/filename/i); | ||
expect(filenameContent).toBeInTheDocument(); | ||
|
||
const saveContent = screen.getByRole("button"); | ||
const saveContent = screen.getByRole("button", { name: /save/i }); | ||
expect(saveContent).toBeInTheDocument(); | ||
}); | ||
|
||
test("clicking Save button triggers save action", () => { | ||
render(<DebugHeader />); | ||
const mockSetRefresh = vi.fn(); | ||
|
||
render( | ||
<DataContext.Provider | ||
value={{ refresh: false, setRefresh: mockSetRefresh }} | ||
> | ||
<DebugHeader /> | ||
</DataContext.Provider> | ||
); | ||
|
||
const saveButton = screen.getByRole("button", { name: /save/i }); | ||
expect(saveButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(saveButton); | ||
expect(mockSetRefresh).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
test("clicking Save button when refresh is true shows 'Saving..'", () => { | ||
const mockSetRefresh = vi.fn(); | ||
|
||
render( | ||
<DataContext.Provider | ||
value={{ refresh: true, setRefresh: mockSetRefresh }} | ||
> | ||
<DebugHeader /> | ||
</DataContext.Provider> | ||
); | ||
|
||
const saveButton = screen.getByText(/Save/i); | ||
const saveButton = screen.getByRole("button", { name: /saving\.\./i }); | ||
expect(saveButton).toBeInTheDocument(); | ||
|
||
// fireEvent.click(saveButton); | ||
fireEvent.click(saveButton); | ||
expect(mockSetRefresh).toHaveBeenCalledWith(false); | ||
}); | ||
}); |
Oops, something went wrong.