-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove
onDelete
for Placeholder tag for non Platform admiins (#…
- Loading branch information
Showing
4 changed files
with
182 additions
and
41 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
5 changes: 3 additions & 2 deletions
5
editor.planx.uk/src/pages/FlowEditor/components/Flow/components/Tag.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
119 changes: 119 additions & 0 deletions
119
editor.planx.uk/src/ui/editor/ComponentTagSelect.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,119 @@ | ||
import ChecklistComponent from "@planx/components/Checklist/Editor"; | ||
import { within } from "@testing-library/react"; | ||
import { TAG_DISPLAY_VALUES } from "pages/FlowEditor/components/Flow/components/Tag"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
import { DndProvider } from "react-dnd"; | ||
import { HTML5Backend } from "react-dnd-html5-backend"; | ||
import { act } from "react-dom/test-utils"; | ||
import { setup } from "testUtils"; | ||
import { it } from "vitest"; | ||
|
||
const { setState } = useStore; | ||
|
||
const mockUser = { | ||
id: 200, | ||
firstName: "Testy", | ||
lastName: "McTester", | ||
email: "[email protected]", | ||
teams: [], | ||
}; | ||
|
||
describe("Checklist Component for a Platform Admin", () => { | ||
beforeEach(() => | ||
act(() => | ||
setState({ | ||
user: { | ||
...mockUser, | ||
isPlatformAdmin: true, | ||
}, | ||
teamSlug: "team", | ||
}), | ||
), | ||
); | ||
|
||
it("renders all tags with none selected", async () => { | ||
const { getByRole, user } = setup( | ||
<DndProvider backend={HTML5Backend}> | ||
<ChecklistComponent text="" /> | ||
</DndProvider>, | ||
); | ||
const tagSelect = getByRole("combobox", { name: /tag this component/i }); | ||
|
||
await user.click(tagSelect); | ||
|
||
const optionsList = getByRole("listbox", { name: /tag this component/i }); | ||
const options = within(optionsList).getAllByRole("option"); | ||
|
||
const tagDisplayNames = Object.values(TAG_DISPLAY_VALUES).map( | ||
(tag) => tag.displayName, | ||
); | ||
const optionTexts = options.map((option) => option.textContent); | ||
|
||
expect(optionTexts).toEqual(expect.arrayContaining(tagDisplayNames)); | ||
}); | ||
|
||
it("renders all tags with Placeholder selected as a button", async () => { | ||
const { queryByTestId, queryByRole } = setup( | ||
<DndProvider backend={HTML5Backend}> | ||
<ChecklistComponent | ||
text="" | ||
node={{ data: { text: "", tags: ["placeholder"] } }} | ||
/> | ||
</DndProvider>, | ||
); | ||
|
||
const placeholderChip = queryByTestId("placeholder-chip"); | ||
const placeholderButton = queryByRole("button", { name: /placeholder/i }); | ||
|
||
expect(placeholderChip).toBeInTheDocument(); | ||
expect(placeholderButton).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("Checklist Component for a non Platform Admin", () => { | ||
beforeEach(() => | ||
act(() => | ||
setState({ | ||
user: { | ||
...mockUser, | ||
isPlatformAdmin: false, | ||
}, | ||
}), | ||
), | ||
); | ||
|
||
it("renders all tags except Placeholder with none selected", async () => { | ||
const { getByRole, user } = setup( | ||
<DndProvider backend={HTML5Backend}> | ||
<ChecklistComponent text="" /> | ||
</DndProvider>, | ||
); | ||
const tagSelect = getByRole("combobox", { name: /tag this component/i }); | ||
|
||
await user.click(tagSelect); | ||
|
||
const optionsList = getByRole("listbox", { name: /tag this component/i }); | ||
const options = within(optionsList).getAllByRole("option"); | ||
const optionTexts = options.map((option) => option.textContent); | ||
|
||
expect(optionTexts).not.toContain(/placeholder/i); | ||
}); | ||
|
||
it("renders all tags with static Placeholder selected", async () => { | ||
const { getByTestId, queryByRole } = setup( | ||
<DndProvider backend={HTML5Backend}> | ||
<ChecklistComponent | ||
text="" | ||
node={{ data: { text: "", tags: ["placeholder"] } }} | ||
/> | ||
</DndProvider>, | ||
); | ||
|
||
const placeholderChip = getByTestId("placeholder-chip"); | ||
const placeholderButton = queryByRole("button", { name: /placeholder/i }); | ||
|
||
expect(placeholderChip).toBeInTheDocument(); | ||
expect(placeholderButton).not.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