Skip to content

Commit

Permalink
Merge pull request #23 from Shubh942/master4
Browse files Browse the repository at this point in the history
Added context Api in webapp for state managment
  • Loading branch information
Ammoniya authored Aug 5, 2024
2 parents 66715dd + 02d0263 commit a6367f2
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 46 deletions.
69 changes: 58 additions & 11 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"axios": "^1.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
Expand Down
44 changes: 25 additions & 19 deletions webapp/src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// App.test.jsx
import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import App from "./App.jsx";

// App.jsx
import { DataProvider } from "./context/DataContext"; // Import the DataProvider

test("renders Footer component", () => {
render(
<MemoryRouter>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
expect(
Expand All @@ -20,58 +20,64 @@ test("renders Footer component", () => {
test("renders Threads component within Debug route", () => {
render(
<MemoryRouter initialEntries={["/debug/threads"]}>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
expect(screen.getByText(/Threads/i)).toBeInTheDocument();
const threadsComponent = screen.getByText(/Threads/i);
expect(threadsComponent).toBeInTheDocument();
expect(threadsComponent).toHaveClass("gdb-header-content active");
// Add any other checks specific to the Threads component
});

test("renders LocalVariable component within Debug route", () => {
render(
<MemoryRouter initialEntries={["/debug/localVariable"]}>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
expect(screen.getByText(/Local Variable/i)).toBeInTheDocument();
const localVariableComponent = screen.getByText(/Local Variable/i);
expect(localVariableComponent).toBeInTheDocument();
expect(localVariableComponent).toHaveClass("gdb-header-content active");
// Add any other checks specific to the LocalVariable component
});

test("renders Context component within Debug route", () => {
render(
<MemoryRouter initialEntries={["/debug/context"]}>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
expect(screen.getByText(/Context/i)).toBeInTheDocument();
const contextComponent = screen.getByText(/Context/i);
expect(contextComponent).toBeInTheDocument();
expect(contextComponent).toHaveClass("gdb-header-content active");
// Add any other checks specific to the Context component
});

test("renders MemoryMap component within Debug route", () => {
render(
<MemoryRouter initialEntries={["/debug/memoryMap"]}>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
expect(screen.getByText(/Memory Map/i)).toBeInTheDocument();
const memoryMapComponent = screen.getByText(/Memory Map/i);
expect(memoryMapComponent).toBeInTheDocument();
expect(memoryMapComponent).toHaveClass("gdb-header-content active");
// Add any other checks specific to the MemoryMap component
});

test("renders BreakPoints component within Debug route", () => {
render(
<MemoryRouter initialEntries={["/debug/breakPoints"]}>
<App />
<DataProvider>
<App />
</DataProvider>
</MemoryRouter>
);
const breakpointsComponent = screen.getByText(/Break Points/i);
expect(breakpointsComponent).toBeInTheDocument();
expect(breakpointsComponent).toHaveClass("gdb-header-content active");
// Add any other checks specific to the BreakPoints component
});
9 changes: 7 additions & 2 deletions webapp/src/components/DebugHeader/DebugHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useContext } from "react";
import {
FaArrowLeft,
FaArrowRight,
Expand All @@ -8,10 +8,13 @@ import {
import { IoReload } from "react-icons/io5";
import { MdSkipNext, MdSkipPrevious } from "react-icons/md";
import { BsArrowRightSquareFill } from "react-icons/bs";
import { DataState } from "../../context/DataContext";

import "./DebugHeader.css";

const DebugHeader = () => {
const { refresh, setRefresh } = DataState();

return (
<div className="parent-debug-header">
<div className="debug-header">
Expand All @@ -33,7 +36,9 @@ const DebugHeader = () => {
<div className="filename-content">filename</div>
</div>
<div className="save">
<button className="save-button">Save</button>
<button className="save-button" onClick={() => setRefresh(!refresh)}>
{refresh ? "Saving.." : "Save"}
</button>
</div>
</div>
</div>
Expand Down
46 changes: 38 additions & 8 deletions webapp/src/components/DebugHeader/__tests__/DebugHeader.test.jsx
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);
});
});
Loading

0 comments on commit a6367f2

Please sign in to comment.