-
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.
feat: improve config details sections by adding subsections
Closes #1386
- Loading branch information
1 parent
6b15e11
commit b7977fd
Showing
5 changed files
with
259 additions
and
47 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
61 changes: 61 additions & 0 deletions
61
src/components/Configs/Sidebar/__tests__/ConfigDetails.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,61 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { rest } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
import { ConfigDetails } from "./../ConfigDetails"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
const server = setupServer( | ||
rest.get("/api/db/config_items", (req, res, ctx) => { | ||
return res( | ||
ctx.json([ | ||
{ | ||
name: "Test Config", | ||
type: "Test Type", | ||
created_at: "2022-01-01T00:00:00.000Z", | ||
updated_at: "2022-01-02T00:00:00.000Z", | ||
tags: { | ||
"Tag 1": "Value 1", | ||
"Tag 2/Subtag 1": "Value 2", | ||
"Tag 2/Subtag 2": "Value 3" | ||
} | ||
} | ||
]) | ||
); | ||
}) | ||
); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
const queryClient = new QueryClient({}); | ||
|
||
describe("ConfigDetails", () => { | ||
const configId = "123"; | ||
|
||
it("renders the config name", async () => { | ||
render( | ||
<MemoryRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<ConfigDetails configId={configId} isCollapsed={false} /> | ||
</QueryClientProvider> | ||
</MemoryRouter> | ||
); | ||
expect(await screen.findByText("Test Config")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the tags", async () => { | ||
render( | ||
<MemoryRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<ConfigDetails configId={configId} isCollapsed={false} /> | ||
</QueryClientProvider> | ||
</MemoryRouter> | ||
); | ||
expect(await screen.findByText("Tag 1")).toBeInTheDocument(); | ||
expect(await screen.findByText("Subtag 1")).toBeInTheDocument(); | ||
expect(await screen.findByText("Subtag 2")).toBeInTheDocument(); | ||
}); | ||
}); |
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,27 @@ | ||
import { ReactNode } from "react"; | ||
|
||
type DisplayDetailsRowProps = { | ||
items: { | ||
label: string; | ||
value: ReactNode; | ||
}[]; | ||
className?: string; | ||
}; | ||
|
||
export default function DisplayDetailsRow({ | ||
items, | ||
className = "flex flex-col flex-1" | ||
}: DisplayDetailsRowProps) { | ||
return ( | ||
<div className="flex flex-row gap-2 w-full"> | ||
{items.map(({ label, value }) => ( | ||
<div className={className} key={label} data-testid="display-item-row"> | ||
<label className="text-sm overflow-hidden truncate text-gray-900 font-medium"> | ||
{label} | ||
</label> | ||
<p className="text-sm text-gray-500 break-all">{value}</p> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/components/Utils/__tests__/DisplayDetailsRow.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,33 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import DisplayDetailsRow from "./../DisplayDetailsRow"; | ||
|
||
describe("DisplayDetailsRow", () => { | ||
const items = [ | ||
{ label: "Label 1", value: "Value 1" }, | ||
{ label: "Label 2", value: "Value 2" }, | ||
{ label: "Label 3", value: "Value 3" } | ||
]; | ||
|
||
it("renders the correct number of items", () => { | ||
render(<DisplayDetailsRow items={items} />); | ||
expect(screen.getAllByTestId("display-item-row")).toHaveLength( | ||
items.length | ||
); | ||
}); | ||
|
||
it("renders the correct labels and values", () => { | ||
render(<DisplayDetailsRow items={items} />); | ||
|
||
items.forEach(({ label, value }) => { | ||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
expect(screen.getByText(value)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("renders with the correct className", () => { | ||
const className = "test-class-name"; | ||
render(<DisplayDetailsRow items={items} className={className} />); | ||
expect(screen.getAllByTestId("display-item-row")[0]).toHaveClass(className); | ||
}); | ||
}); |