-
-
Notifications
You must be signed in to change notification settings - Fork 10
[MergeDups] Add "Revert set" button to discard changes and reset to initial state #3959
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
53033a5
Initial plan
Copilot f3e54b1
Add revert/reset button to MergeDups with confirmation dialog
Copilot 262380e
Address PR review feedback: use CancelConfirmDialog, optimize state s…
Copilot 2b05190
Address additional PR feedback: use Button, simplify state, refactor …
Copilot db0e9ea
Address final PR feedback: optimize state storage and simplify tests
Copilot 7089f39
Refine reset action scope and improve test structure
Copilot 2190c0d
Alphabetize Button props and add variant="contained"
Copilot 5478264
Refactor test to use mockDispatch pattern instead of store.getActions()
Copilot f0a660a
Condense and sort tests
imnasnainaec bfe7318
Merge remote-tracking branch 'origin/master' into copilot/add-reset-b…
Copilot eb65ac6
Merge branch 'master' into copilot/add-reset-button-to-merge-tool
imnasnainaec 445889a
Reorder
imnasnainaec e13d6d4
Tidy tests
imnasnainaec f2902c0
Use TSDoc comment for function
imnasnainaec b6641ce
Merge branch 'master' into copilot/add-reset-button-to-merge-tool
imnasnainaec 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 hidden or 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 hidden or 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
135 changes: 135 additions & 0 deletions
135
src/goals/MergeDuplicates/MergeDupsStep/tests/SaveDeferButtons.test.tsx
This file contains hidden or 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,135 @@ | ||
| import "@testing-library/jest-dom"; | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { Provider } from "react-redux"; | ||
| import configureMockStore from "redux-mock-store"; | ||
|
|
||
| import SaveDeferButtons from "goals/MergeDuplicates/MergeDupsStep/SaveDeferButtons"; | ||
| import { defaultState as defaultMergeDupState } from "goals/MergeDuplicates/Redux/MergeDupsReduxTypes"; | ||
| import { defaultState } from "rootRedux/types"; | ||
| import { testWordList } from "types/word"; | ||
|
|
||
| jest.mock("goals/Redux/GoalActions"); | ||
| jest.mock("backend"); | ||
|
|
||
| const mockStore = configureMockStore(); | ||
|
|
||
| let store: any; | ||
|
|
||
| function setMockStore(hasChanges = false): any { | ||
| const words = testWordList(); | ||
| const data = { words: { [words[0].id]: words[0] }, senses: {} }; | ||
| const tree = hasChanges | ||
| ? { | ||
| words: { | ||
| [words[0].id]: { sensesGuids: {}, vern: "test", flag: {} }, | ||
| }, | ||
| sidebar: {}, | ||
| deletedSenseGuids: [], | ||
| } | ||
| : { words: {}, sidebar: {}, deletedSenseGuids: [] }; | ||
| const initialTree = JSON.stringify({ | ||
| words: {}, | ||
| sidebar: {}, | ||
| deletedSenseGuids: [], | ||
| }); | ||
| const audio = { | ||
| counts: {}, | ||
| moves: hasChanges ? { [words[0].id]: [] } : {}, | ||
| }; | ||
|
|
||
| const mergeDuplicateGoal = { | ||
| ...defaultMergeDupState, | ||
| data, | ||
| tree, | ||
| audio, | ||
| initialTree, | ||
| }; | ||
|
|
||
| store = mockStore({ | ||
| ...defaultState, | ||
| mergeDuplicateGoal, | ||
| }); | ||
| return store; | ||
| } | ||
imnasnainaec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const renderSaveDeferButtons = async (hasChanges: boolean): Promise<void> => { | ||
| render( | ||
| <Provider store={setMockStore(hasChanges)}> | ||
| <SaveDeferButtons /> | ||
| </Provider> | ||
| ); | ||
| }; | ||
|
|
||
| describe("SaveDeferButtons", () => { | ||
| it("renders all buttons", async () => { | ||
| await renderSaveDeferButtons(false); | ||
|
|
||
| expect(screen.getByText("buttons.saveAndContinue")).toBeInTheDocument(); | ||
| expect(screen.getByText("buttons.defer")).toBeInTheDocument(); | ||
| expect(screen.getByText("buttons.revertSet")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("disables revert button when no changes", async () => { | ||
| await renderSaveDeferButtons(false); | ||
|
|
||
| const revertButton = screen.getByTitle("mergeDups.helpText.revertSet"); | ||
| expect(revertButton).toBeDisabled(); | ||
| }); | ||
|
|
||
| it("enables revert button when changes exist", async () => { | ||
| await renderSaveDeferButtons(true); | ||
|
|
||
| const revertButton = screen.getByTitle("mergeDups.helpText.revertSet"); | ||
| expect(revertButton).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| it("shows confirmation dialog when revert is clicked", async () => { | ||
| await renderSaveDeferButtons(true); | ||
|
|
||
| const revertButton = screen.getByTitle("mergeDups.helpText.revertSet"); | ||
| await userEvent.click(revertButton); | ||
|
|
||
| expect( | ||
| screen.getByText("mergeDups.helpText.revertSetDialog") | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("cancels revert when cancel button is clicked", async () => { | ||
| await renderSaveDeferButtons(true); | ||
|
|
||
| const revertButton = screen.getByTitle("mergeDups.helpText.revertSet"); | ||
| await userEvent.click(revertButton); | ||
|
|
||
| // Dialog should be visible | ||
| expect(screen.getByRole("dialog")).toBeVisible(); | ||
|
|
||
| const cancelButton = screen.getByTestId("revert-cancel"); | ||
| await userEvent.click(cancelButton); | ||
|
|
||
| // After clicking cancel, wait for the dialog to close and be removed from DOM | ||
| await waitFor(() => { | ||
| expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it("dispatches reset action when confirm is clicked", async () => { | ||
| await renderSaveDeferButtons(true); | ||
|
|
||
| const revertButton = screen.getByTitle("mergeDups.helpText.revertSet"); | ||
| await userEvent.click(revertButton); | ||
|
|
||
| const confirmButton = screen.getByTestId("revert-confirm"); | ||
| await userEvent.click(confirmButton); | ||
|
|
||
| // Wait for the action to be dispatched | ||
| await waitFor(() => { | ||
| const actions = store.getActions(); | ||
| expect(actions).toContainEqual( | ||
| expect.objectContaining({ | ||
| type: "mergeDupStepReducer/resetTreeToInitialAction", | ||
| }) | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.