-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add new editor - error handling and enhancements #3543
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a4d60bf
fix: refactor Team component folder structure
jamdelion f7e87fb
Basic "add new editor" button on team editors table
jamdelion 5f38c8a
Merge main
jamdelion d2f9c59
Hide button behind feature flag
jamdelion 0a566a1
Rename test
jamdelion edc221b
Test button appears within team editors table only
jamdelion fe7ce77
Style button correctly
jamdelion 12df25c
Basic open modal functionality
jamdelion 2975369
Move modal to new component and add static input fields
jamdelion 3240488
Extract setup helper from test
jamdelion 50c0a9c
Extract props type
jamdelion f6d7f25
Use formik for form validation and submission
jamdelion b419666
Implement changes requested
jamdelion 5d189eb
Merge branch 'jh/add-team-editor-button' into jh/validate-add-team-ed…
jamdelion c5f31a8
Get basic createUser working
jamdelion 0f368f5
Merge branch 'main' into jh/validate-add-team-editor
jamdelion 4a27c5c
Basic addUserToTeam mutation
jamdelion 3f81d7b
Split out queries into own folder
jamdelion fc91022
Tidy up - move type defs and schemas
jamdelion 4ec6cb6
Fix import
jamdelion e616c02
Start writing a test for form submission - close modal
jamdelion 237a0ee
Optimistically update the table when fetching complete, plus refactors
jamdelion 29624c1
Test that new row added to team editors table
jamdelion 522e2d7
Update editor.planx.uk/src/pages/FlowEditor/components/Team/component…
jamdelion 37c8a3f
Use teamId from store instead of fetchCurrentTeam
jamdelion b6a12d2
Combine createUser and addToTeam mutations into one
jamdelion 2e1fedc
Use store to optimistically update, plus refactor member filtering
jamdelion 8a3459d
Fix tests
jamdelion 126d6d4
Merge branch 'main' into jh/validate-add-team-editor
jamdelion a5dfb84
Show toast message on success
jamdelion a78a86d
Handle user already exists er
jamdelion a4904bb
Refactor tests
jamdelion 0a1aee5
Extract error logic out
jamdelion 034d4d4
Add in correct close-modal test
jamdelion 45ef05c
Improve platformAdmins filter
jamdelion 752fb93
Use returned userId as key in table update
jamdelion 99b38c6
Fix teamMember store setting
jamdelion 55c558b
Refetch query when user created and added to team
jamdelion 1c5651f
Merge branch 'main' into jh/validate-add-team-editor
jamdelion 096f824
Merge branch 'jh/validate-add-team-editor' into jh/add-editor-error-h…
jamdelion c54b7c7
Merge branch 'main' into jh/add-editor-error-handling
jamdelion 0cfbd19
Delete duplicate files from merge
jamdelion 0cb25f9
Use user.type instead of fireEvent
jamdelion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions
8
editor.planx.uk/src/pages/FlowEditor/components/Team/errors/addNewEditorErrors.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,8 @@ | ||
export const AddNewEditorErrors = { | ||
USER_ALREADY_EXISTS: { | ||
regex: /violates unique constraint "users_email_key"/i, | ||
errorMessage: "User already exists", | ||
}, | ||
}; | ||
export const isUserAlreadyExistsError = (error: string) => | ||
AddNewEditorErrors.USER_ALREADY_EXISTS.regex.test(error); |
44 changes: 44 additions & 0 deletions
44
...nx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.errors.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,44 @@ | ||
import { screen, within } from "@testing-library/react"; | ||
import { FullStore, useStore } from "pages/FlowEditor/lib/store"; | ||
import { vi } from "vitest"; | ||
|
||
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; | ||
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; | ||
import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; | ||
import { alreadyExistingUser } from "./mocks/mockUsers"; | ||
|
||
vi.mock("lib/featureFlags.ts", () => ({ | ||
hasFeatureFlag: vi.fn().mockReturnValue(true), | ||
})); | ||
|
||
vi.mock( | ||
"pages/FlowEditor/components/Team/queries/createAndAddUserToTeam.tsx", | ||
() => ({ | ||
createAndAddUserToTeam: vi.fn().mockRejectedValue({ | ||
message: | ||
'Uniqueness violation. duplicate key value violates unique constraint "users_email_key"', | ||
}), | ||
}), | ||
); | ||
|
||
let initialState: FullStore; | ||
|
||
describe("when a user fills in the 'add a new editor' form correctly but the user already exists", () => { | ||
afterAll(() => useStore.setState(initialState)); | ||
beforeEach(async () => { | ||
useStore.setState({ | ||
teamMembers: [...mockTeamMembersData, alreadyExistingUser], | ||
}); | ||
|
||
const user = await setupTeamMembersScreen(); | ||
await userTriesToAddNewEditor(user); | ||
}); | ||
|
||
it("shows an appropriate error message", async () => { | ||
const addNewEditorModal = await screen.findByTestId("dialog-create-user"); | ||
|
||
expect( | ||
await within(addNewEditorModal).findByText(/User already exists/), | ||
).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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
|
||
import { screen, waitFor, within } from "@testing-library/react"; | ||
import { FullStore, useStore } from "pages/FlowEditor/lib/store"; | ||
import { vi } from "vitest"; | ||
|
||
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; | ||
import { userEntersInput } from "./helpers/userEntersInput"; | ||
import { userTriesToAddNewEditor } from "./helpers/userTriesToAddNewEditor"; | ||
import { mockTeamMembersData } from "./mocks/mockTeamMembersData"; | ||
|
||
vi.mock("lib/featureFlags.ts", () => ({ | ||
hasFeatureFlag: vi.fn().mockReturnValue(true), | ||
|
@@ -24,6 +24,7 @@ let initialState: FullStore; | |
|
||
describe("when a user with the ADD_NEW_EDITOR feature flag enabled presses 'add a new editor'", () => { | ||
beforeEach(async () => { | ||
useStore.setState({ teamMembers: mockTeamMembersData }); | ||
const user = await setupTeamMembersScreen(); | ||
|
||
const teamEditorsTable = screen.getByTestId("team-editors"); | ||
|
@@ -42,26 +43,9 @@ describe("when a user with the ADD_NEW_EDITOR feature flag enabled presses 'add | |
describe("when a user fills in the 'add a new editor' form correctly", () => { | ||
afterAll(() => useStore.setState(initialState)); | ||
beforeEach(async () => { | ||
useStore.setState({ teamMembers: mockTeamMembersData }); | ||
const user = await setupTeamMembersScreen(); | ||
const teamEditorsTable = screen.getByTestId("team-editors"); | ||
const addEditorButton = await within(teamEditorsTable).findByText( | ||
"Add a new editor", | ||
); | ||
user.click(addEditorButton); | ||
const addNewEditorModal = await screen.findByTestId("modal-create-user"); | ||
await userEntersInput("First name", "Mickey", addNewEditorModal); | ||
await userEntersInput("Last name", "Mouse", addNewEditorModal); | ||
await userEntersInput( | ||
"Email address", | ||
"[email protected]", | ||
addNewEditorModal, | ||
); | ||
|
||
const createUserButton = await screen.findByTestId( | ||
"modal-create-user-button", | ||
); | ||
|
||
user.click(createUserButton); | ||
await userTriesToAddNewEditor(user); | ||
}); | ||
|
||
it("adds the new user row to the Team Editors table", async () => { | ||
|
@@ -73,4 +57,16 @@ describe("when a user fills in the 'add a new editor' form correctly", () => { | |
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("closes the modal", async () => { | ||
await waitFor(() => { | ||
expect(screen.queryByTestId("modal-create-user")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("shows a success message", async () => { | ||
expect( | ||
await screen.findByText(/Successfully added a user/), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
4 changes: 0 additions & 4 deletions
4
...or.planx.uk/src/pages/FlowEditor/components/Team/tests/helpers/setupTeamMembersScreen.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
8 changes: 4 additions & 4 deletions
8
editor.planx.uk/src/pages/FlowEditor/components/Team/tests/helpers/userEntersInput.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,13 +1,13 @@ | ||
import { fireEvent, within } from "@testing-library/react"; | ||
import { within } from "@testing-library/react"; | ||
import { UserEvent } from "@testing-library/user-event/dist/types/setup/setup"; | ||
|
||
export const userEntersInput = async ( | ||
labelText: string, | ||
inputString: string, | ||
container: HTMLElement, | ||
user: UserEvent, | ||
) => { | ||
const inputField = await within(container).findByLabelText(labelText); | ||
|
||
fireEvent.change(inputField, { | ||
target: { value: inputString }, | ||
}); | ||
await user.type(inputField, inputString); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice solution!