-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] test: Adds tests for global concurrency view and task run view]
- Loading branch information
1 parent
6bfce9e
commit 9a3eb59
Showing
20 changed files
with
553 additions
and
31 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
81 changes: 81 additions & 0 deletions
81
ui-v2/src/components/concurrency/global-concurrency-view/data-table/data-table.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,81 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { createWrapper } from "@tests/utils"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { Table } from "./data-table"; | ||
|
||
const MOCK_DATA = [ | ||
{ | ||
id: "0", | ||
created: "2021-01-01T00:00:00Z", | ||
updated: "2021-01-01T00:00:00Z", | ||
active: true, | ||
name: "global concurrency limit 0", | ||
limit: 0, | ||
active_slots: 0, | ||
slot_decay_per_second: 0, | ||
}, | ||
]; | ||
|
||
describe("GlobalConcurrencyLimitTable -- table", () => { | ||
it("renders row data", () => { | ||
render( | ||
<Table | ||
data={MOCK_DATA} | ||
onDeleteRow={vi.fn()} | ||
onEditRow={vi.fn()} | ||
searchValue="" | ||
onSearchChange={vi.fn()} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
expect( | ||
screen.getByRole("cell", { name: /global concurrency limit 0/i }), | ||
).toBeVisible(); | ||
expect( | ||
screen.getByRole("switch", { name: /toggle active/i }), | ||
).toBeChecked(); | ||
}); | ||
|
||
it("calls onDelete upon clicking delete action menu item", async () => { | ||
const user = userEvent.setup(); | ||
|
||
const mockFn = vi.fn(); | ||
|
||
render( | ||
<Table | ||
data={MOCK_DATA} | ||
onDeleteRow={mockFn} | ||
onEditRow={vi.fn()} | ||
searchValue="" | ||
onSearchChange={vi.fn()} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
await user.click( | ||
screen.getByRole("button", { name: /open menu/i, hidden: true }), | ||
); | ||
await user.click(screen.getByRole("menuitem", { name: /delete/i })); | ||
expect(mockFn).toHaveBeenCalledOnce(); | ||
}); | ||
it("calls onEdit upon clicking rest action menu item", async () => { | ||
const user = userEvent.setup(); | ||
const mockFn = vi.fn(); | ||
|
||
render( | ||
<Table | ||
data={MOCK_DATA} | ||
onDeleteRow={vi.fn()} | ||
onEditRow={mockFn} | ||
searchValue="" | ||
onSearchChange={vi.fn()} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
await user.click( | ||
screen.getByRole("button", { name: /open menu/i, hidden: true }), | ||
); | ||
await user.click(screen.getByRole("menuitem", { name: /edit/i })); | ||
expect(mockFn).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
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
88 changes: 88 additions & 0 deletions
88
...-concurrency-view/dialog/create-or-edit-limit-dialog/create-or-edit-limit-dialog.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,88 @@ | ||
import { CreateOrEditLimitDialog } from "./create-or-edit-limit-dialog"; | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { createWrapper } from "@tests/utils"; | ||
import { beforeAll, describe, expect, it, vi } from "vitest"; | ||
|
||
const MOCK_DATA = { | ||
id: "0", | ||
created: "2021-01-01T00:00:00Z", | ||
updated: "2021-01-01T00:00:00Z", | ||
active: false, | ||
name: "global concurrency limit 0", | ||
limit: 0, | ||
active_slots: 0, | ||
slot_decay_per_second: 0, | ||
}; | ||
|
||
describe("CreateOrEditLimitDialog", () => { | ||
beforeAll(() => { | ||
class ResizeObserverMock { | ||
observe() {} | ||
unobserve() {} | ||
disconnect() {} | ||
} | ||
|
||
global.ResizeObserver = ResizeObserverMock; | ||
}); | ||
|
||
it("able to create a new limit", async () => { | ||
const user = userEvent.setup(); | ||
|
||
// ------------ Setup | ||
const mockOnSubmitFn = vi.fn(); | ||
render( | ||
<CreateOrEditLimitDialog | ||
onOpenChange={vi.fn()} | ||
onSubmit={mockOnSubmitFn} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
// ------------ Act | ||
|
||
await user.type(screen.getByLabelText(/name/i), MOCK_DATA.name); | ||
await user.type( | ||
screen.getByLabelText("Concurrency Limit"), | ||
MOCK_DATA.limit.toString(), | ||
); | ||
await user.type( | ||
screen.getByLabelText("Slot Decay Per Second"), | ||
MOCK_DATA.slot_decay_per_second.toString(), | ||
); | ||
await user.click(screen.getByRole("button", { name: /save/i })); | ||
|
||
// ------------ Assert | ||
expect(mockOnSubmitFn).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
it("able to edit a limit", async () => { | ||
const user = userEvent.setup(); | ||
|
||
// ------------ Setup | ||
const mockOnSubmitFn = vi.fn(); | ||
render( | ||
<CreateOrEditLimitDialog | ||
limitToUpdate={MOCK_DATA} | ||
onOpenChange={vi.fn()} | ||
onSubmit={mockOnSubmitFn} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
// ------------ Act | ||
|
||
await user.type(screen.getByLabelText(/name/i), MOCK_DATA.name); | ||
await user.type( | ||
screen.getByLabelText("Concurrency Limit"), | ||
MOCK_DATA.limit.toString(), | ||
); | ||
await user.type( | ||
screen.getByLabelText("Slot Decay Per Second"), | ||
MOCK_DATA.slot_decay_per_second.toString(), | ||
); | ||
await user.click(screen.getByRole("button", { name: /update/i })); | ||
|
||
// ------------ Assert | ||
expect(mockOnSubmitFn).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...omponents/concurrency/global-concurrency-view/dialog/create-or-edit-limit-dialog/index.ts
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 @@ | ||
export { CreateOrEditLimitDialog } from "./create-or-edit-limit-dialog"; |
43 changes: 43 additions & 0 deletions
43
ui-v2/src/components/concurrency/global-concurrency-view/dialog/delete-limit-dialog.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,43 @@ | ||
import { DeleteLimitDialog } from "./delete-limit-dialog"; | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { createWrapper } from "@tests/utils"; | ||
import { expect, test, vi } from "vitest"; | ||
|
||
const MOCK_DATA = { | ||
id: "0", | ||
created: "2021-01-01T00:00:00Z", | ||
updated: "2021-01-01T00:00:00Z", | ||
active: false, | ||
name: "global concurrency limit 0", | ||
limit: 0, | ||
active_slots: 0, | ||
slot_decay_per_second: 0, | ||
}; | ||
|
||
test("DeleteLimitDialog can successfully call delete", async () => { | ||
const user = userEvent.setup(); | ||
|
||
// ------------ Setup | ||
const mockOnDeleteFn = vi.fn(); | ||
render( | ||
<DeleteLimitDialog | ||
limit={MOCK_DATA} | ||
onDelete={mockOnDeleteFn} | ||
onOpenChange={vi.fn()} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
// ------------ Act | ||
expect(screen.getByRole("heading", { name: /delete concurrency limit/i })); | ||
await user.click( | ||
screen.getByRole("button", { | ||
name: /delete/i, | ||
}), | ||
); | ||
|
||
// ------------ Assert | ||
expect(mockOnDeleteFn).toHaveBeenCalledOnce(); | ||
}); |
20 changes: 9 additions & 11 deletions
20
...urrency/global-concurrency-view/empty-state/global-concurrency-limit-empty-state.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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { expect, test, vi } from "vitest"; | ||
import { GlobalConcurrencyLimitEmptyState } from "./global-concurrency-limit-empty-state"; | ||
|
||
describe("GlobalConcurrencyLimitEmptyState", () => { | ||
it("when adding limit, callback gets fired", async () => { | ||
const user = userEvent.setup(); | ||
test("GlobalConcurrencyLimitEmptyState", async () => { | ||
const user = userEvent.setup(); | ||
|
||
const mockFn = vi.fn(); | ||
const mockFn = vi.fn(); | ||
|
||
render(<GlobalConcurrencyLimitEmptyState onAdd={mockFn} />); | ||
await user.click( | ||
screen.getByRole("button", { name: /Add Concurrency Limit/i }), | ||
); | ||
expect(mockFn).toHaveBeenCalledOnce(); | ||
}); | ||
render(<GlobalConcurrencyLimitEmptyState onAdd={mockFn} />); | ||
await user.click( | ||
screen.getByRole("button", { name: /Add Concurrency Limit/i }), | ||
); | ||
expect(mockFn).toHaveBeenCalledOnce(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...ents/concurrency/global-concurrency-view/header/global-concurrency-limits-header.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,26 @@ | ||
import { GlobalConcurrencyLimitsHeader } from "./global-concurrency-limits-header"; | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { expect, test, vi } from "vitest"; | ||
|
||
test("GlobalConcurrencyLimitsHeader can successfully call onAdd", async () => { | ||
const user = userEvent.setup(); | ||
|
||
// ------------ Setup | ||
const mockOnAddFn = vi.fn(); | ||
render(<GlobalConcurrencyLimitsHeader onAdd={mockOnAddFn} />); | ||
|
||
// ------------ Act | ||
expect( | ||
screen.getByRole("heading", { name: /global concurrency limits/i }), | ||
).toBeVisible(); | ||
await user.click( | ||
screen.getByRole("button", { | ||
name: /add global concurrency limit/i, | ||
}), | ||
); | ||
|
||
// ------------ Assert | ||
expect(mockOnAddFn).toHaveBeenCalledOnce(); | ||
}); |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
ui-v2/src/components/concurrency/global-concurrency-view/header/index.ts
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 @@ | ||
export { GlobalConcurrencyLimitsHeader } from "./global-concurrency-limits-header"; |
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.