-
Notifications
You must be signed in to change notification settings - Fork 23
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 #1584 from flanksource/mainawycliffe/issue1580
Mainawycliffe/issue1580
- Loading branch information
Showing
9 changed files
with
187 additions
and
21 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
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
79 changes: 79 additions & 0 deletions
79
src/components/Playbooks/Runs/Actions/__tests__/PlaybookRunsAction.unit.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { rest } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
import { | ||
PlaybookRunAction, | ||
PlaybookRunWithActions | ||
} from "../../../../../api/types/playbooks"; | ||
import PlaybookRunsActions from "./../PlaybookRunsActions"; | ||
|
||
const mockAction: PlaybookRunAction = { | ||
playbook_run_id: "1", | ||
id: "1", | ||
name: "Test Action", | ||
status: "completed", | ||
start_time: "2022-01-01T00:00:00Z", | ||
end_time: "2022-01-01T01:00:00Z" | ||
}; | ||
|
||
const server = setupServer( | ||
rest.get("/api/db/playbook_run_actions", (req, res, ctx) => { | ||
return res(ctx.json([mockAction])); | ||
}) | ||
); | ||
|
||
describe.skip("PlaybookRunsActions", () => { | ||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
it("renders correctly", async () => { | ||
const mockData: PlaybookRunWithActions = { | ||
id: "1", | ||
playbook_id: "1", | ||
playbooks: { | ||
name: "Test Playbook", | ||
id: "1", | ||
source: "UI", | ||
created_at: "2022-01-01T00:00:00Z", | ||
spec: {}, | ||
updated_at: "2022-01-01T00:00:00Z" | ||
}, | ||
status: "completed", | ||
start_time: "2022-01-01T00:00:00Z", | ||
end_time: "2022-01-01T01:00:00Z", | ||
created_at: "2022-01-01T00:00:00Z", | ||
actions: [ | ||
{ | ||
playbook_run_id: "1", | ||
id: "1", | ||
name: "Test Action 1", | ||
status: "completed", | ||
start_time: "2022-01-01T00:00:00Z", | ||
end_time: "2022-01-01T01:00:00Z" | ||
}, | ||
{ | ||
playbook_run_id: "1", | ||
id: "2", | ||
name: "Test Action 2", | ||
status: "completed", | ||
start_time: "2022-01-01T00:00:00Z", | ||
end_time: "2022-01-01T01:00:00Z" | ||
} | ||
] | ||
// other fields as needed | ||
}; | ||
|
||
render(<PlaybookRunsActions data={mockData} />); | ||
|
||
expect(screen.getByText("Test Playbook")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Action 1")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Action 2")).toBeInTheDocument(); | ||
|
||
// Click on an action to trigger the network request | ||
fireEvent.click(screen.getByText("Test Action 1")); | ||
|
||
// Wait for the request to complete | ||
await screen.findByText(/some text from the response/i); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
src/components/Playbooks/Runs/Actions/__tests__/PlaybookRunsActionItem.unit.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from "react"; | ||
import { render, fireEvent, screen } from "@testing-library/react"; | ||
import PlaybookRunsActionItem from "./../PlaybookRunsActionItem"; | ||
import { PlaybookRunAction } from "../../../../../api/types/playbooks"; | ||
|
||
describe("PlaybookRunsActionItem", () => { | ||
const mockAction: PlaybookRunAction = { | ||
playbook_run_id: "1", | ||
id: "1", | ||
name: "Test Action", | ||
status: "completed", | ||
start_time: "2022-01-01T00:00:00Z", | ||
end_time: "2022-01-01T01:00:00Z" | ||
}; | ||
|
||
const mockOnClick = jest.fn(); | ||
|
||
it("renders correctly", () => { | ||
render( | ||
<PlaybookRunsActionItem | ||
action={mockAction} | ||
onClick={mockOnClick} | ||
isSelected={false} | ||
/> | ||
); | ||
|
||
expect(screen.getByRole("button")).toBeInTheDocument(); | ||
expect(screen.getByText("Test Action")).toBeInTheDocument(); | ||
}); | ||
|
||
it("calls onClick when clicked", () => { | ||
render( | ||
<PlaybookRunsActionItem | ||
action={mockAction} | ||
onClick={mockOnClick} | ||
isSelected={false} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByRole("button")); | ||
|
||
expect(mockOnClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it("has correct style when selected", () => { | ||
render( | ||
<PlaybookRunsActionItem | ||
action={mockAction} | ||
onClick={mockOnClick} | ||
isSelected={true} | ||
/> | ||
); | ||
|
||
expect(screen.getByRole("button")).toHaveClass("bg-gray-200"); | ||
}); | ||
}); |
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