Repository navigation
fix: migrate edit view type page into mui/uicore components #1113
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
Open
tomrndom
wants to merge
9
commits into
master
Choose a base branch
from
fix/edit-view-type-mui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7fc8a3f
fix: add 'new button' using mui components
tomrndom 2a372ac
fix: migrate edit view type page into mui/uicore components
tomrndom 73e1d28
fix: use formik into form, restore add new button, adjust actions
tomrndom ad0085c
fix: update new button with mui components
tomrndom 08abd85
fix: update uicore version and use mui add new button
tomrndom 3a3486c
fix: adjust return in actions, update validations based on API rules,…
tomrndom a04126e
fix: pass entity on buildValidationSchema
tomrndom e57b251
fix: adjust action order for getViewType
tomrndom 9318394
fix: add character validation for description, update unit test
tomrndom 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import React from "react"; | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import "@testing-library/jest-dom"; | ||
| import ViewTypeForm from "../view-type-form"; | ||
|
|
||
| jest.mock("i18n-react/dist/i18n-react", () => ({ | ||
| __esModule: true, | ||
| default: { translate: (key) => key } | ||
| })); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/mui/formik-inputs/texteditor", | ||
| () => ({ | ||
| __esModule: true, | ||
| default: ({ name }) => { | ||
| // eslint-disable-next-line global-require | ||
| const { useFormikContext } = require("formik"); | ||
| return useFormikContext().errors[name] ?? null; | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| jest.mock("../../../hooks/useScrollToError", () => ({ | ||
| __esModule: true, | ||
| default: jest.fn() | ||
| })); | ||
|
|
||
| const ENTITY = { id: 3, name: "Card", description: "", is_default: null }; | ||
|
|
||
| describe("ViewTypeForm", () => { | ||
| it("shows server errors and submits the edited entity once while saving", async () => { | ||
| const onSubmit = jest.fn(() => new Promise(() => {})); | ||
| render( | ||
| <ViewTypeForm | ||
| entity={ENTITY} | ||
| errors={{ name: "name taken" }} | ||
| onSubmit={onSubmit} | ||
| /> | ||
| ); | ||
|
|
||
| expect(await screen.findByText("name taken")).toBeInTheDocument(); | ||
|
|
||
| await userEvent.type( | ||
| screen.getByRole("textbox", { name: /edit_view_type.name/ }), | ||
| "Print" | ||
| ); | ||
| await userEvent.click(screen.getByRole("checkbox")); | ||
| await userEvent.click(screen.getByRole("button", { name: "general.save" })); | ||
|
|
||
| await waitFor(() => | ||
| expect(onSubmit).toHaveBeenCalledWith({ | ||
| ...ENTITY, | ||
| name: "CardPrint", | ||
| is_default: true | ||
| }) | ||
| ); | ||
| expect(screen.getByRole("button", { name: "general.save" })).toBeDisabled(); | ||
| expect(onSubmit).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("blocks submit on values the API rejects", async () => { | ||
| const onSubmit = jest.fn(); | ||
| const { rerender } = render( | ||
| <ViewTypeForm | ||
| entity={{ ...ENTITY, name: "Card Print" }} | ||
| onSubmit={onSubmit} | ||
| /> | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole("button", { name: "general.save" })); | ||
| expect( | ||
| await screen.findByText("validation.single_word") | ||
| ).toBeInTheDocument(); | ||
|
|
||
| rerender(<ViewTypeForm entity={{ name: "Card" }} onSubmit={onSubmit} />); | ||
| await userEvent.click(screen.getByRole("button", { name: "general.save" })); | ||
| expect(await screen.findByText("validation.required")).toBeInTheDocument(); | ||
|
|
||
| rerender( | ||
| <ViewTypeForm | ||
| entity={{ ...ENTITY, description: `<p>${"a".repeat(250)}</p>` }} | ||
| onSubmit={onSubmit} | ||
| /> | ||
| ); | ||
| await userEvent.click(screen.getByRole("button", { name: "general.save" })); | ||
| expect( | ||
| await screen.findByText("validation.max_length") | ||
| ).toBeInTheDocument(); | ||
|
|
||
| expect(onSubmit).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
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.