forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: replace item popup with shared item popup, adjust props and actions #1034
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
1
commit into
master
Choose a base branch
from
fix/sponsor-global-manage-item-popup
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
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
187 changes: 187 additions & 0 deletions
187
src/pages/sponsors-global/form-templates/__tests__/sponsor-inventory-popup.test.js
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,187 @@ | ||
| 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 SponsorItemDialog from "../sponsor-inventory-popup"; | ||
|
|
||
| jest.mock("i18n-react/dist/i18n-react", () => ({ | ||
| translate: jest.fn((key) => key) | ||
| })); | ||
|
|
||
| jest.mock("../../../../hooks/useScrollToError", () => jest.fn()); | ||
|
|
||
| jest.mock("openstack-uicore-foundation/lib/components", () => ({ | ||
| MuiFormikUpload: function MockMuiFormikUpload({ name }) { | ||
| return <div data-testid={`upload-${name}`} />; | ||
| } | ||
| })); | ||
|
|
||
| jest.mock( | ||
| "openstack-uicore-foundation/lib/components/mui/formik-inputs/additional-input-list", | ||
| () => | ||
| function MockAdditionalInputList({ name }) { | ||
| return <div data-testid={`meta-fields-${name}`} />; | ||
| } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| "../../../../components/mui/formik-inputs/item-price-tiers", | ||
| () => | ||
| function MockItemPriceTiers() { | ||
| return <div data-testid="price-tiers" />; | ||
| } | ||
| ); | ||
|
|
||
| jest.mock( | ||
| "../../../../components/inputs/formik-text-editor", | ||
| () => | ||
| function MockFormikTextEditor({ name }) { | ||
| return <textarea data-testid={`editor-${name}`} name={name} readOnly />; | ||
| } | ||
| ); | ||
|
|
||
| const BASE_ENTITY = { | ||
| id: 0, | ||
| code: "", | ||
| name: "", | ||
| description: "", | ||
| early_bird_rate: "", | ||
| standard_rate: "", | ||
| onsite_rate: "", | ||
| quantity_limit_per_show: "", | ||
| quantity_limit_per_sponsor: "", | ||
| meta_fields: [], | ||
| images: [] | ||
| }; | ||
|
|
||
| const fillRequiredTextFields = async (user) => { | ||
| await user.type(document.querySelector("input[name=\"code\"]"), "CODE-1"); | ||
| await user.type(document.querySelector("input[name=\"name\"]"), "Item 1"); | ||
| }; | ||
|
|
||
| const submit = async (user) => { | ||
| await user.click( | ||
| screen.getByRole("button", { name: "edit_inventory_item.save_changes" }) | ||
| ); | ||
| }; | ||
|
|
||
| describe("SponsorItemDialog", () => { | ||
| let onSave; | ||
| let onClose; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| onSave = jest.fn(() => Promise.resolve()); | ||
| onClose = jest.fn(); | ||
| }); | ||
|
|
||
| it("titles itself by whether the entity has an id", () => { | ||
| const { rerender } = render( | ||
| <SponsorItemDialog | ||
| entity={BASE_ENTITY} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| /> | ||
| ); | ||
| expect( | ||
| screen.getByText("edit_inventory_item.new_item") | ||
| ).toBeInTheDocument(); | ||
|
|
||
| rerender( | ||
| <SponsorItemDialog | ||
| entity={{ ...BASE_ENTITY, id: 42 }} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| /> | ||
| ); | ||
| expect( | ||
| screen.getByText("edit_inventory_item.edit_item") | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("blocks save when code/name are empty", async () => { | ||
| const user = userEvent.setup(); | ||
| render( | ||
| <SponsorItemDialog | ||
| entity={BASE_ENTITY} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| /> | ||
| ); | ||
|
|
||
| await submit(user); | ||
|
|
||
| expect(onSave).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| describe("default_quantity requirement", () => { | ||
| it("is optional by default: saves with no value and shows no required marker", async () => { | ||
| const user = userEvent.setup(); | ||
| render( | ||
| <SponsorItemDialog | ||
| entity={BASE_ENTITY} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.queryByText("edit_inventory_item.default_quantity *") | ||
| ).not.toBeInTheDocument(); | ||
|
|
||
| await fillRequiredTextFields(user); | ||
| await submit(user); | ||
|
|
||
| await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)); | ||
| expect(onClose).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("blocks save, shows the error and the required marker when required and empty", async () => { | ||
| const user = userEvent.setup(); | ||
| render( | ||
| <SponsorItemDialog | ||
| entity={{ ...BASE_ENTITY, default_quantity: undefined }} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| requireDefaultQuantity | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText("edit_inventory_item.default_quantity *") | ||
| ).toBeInTheDocument(); | ||
|
|
||
| await fillRequiredTextFields(user); | ||
| await submit(user); | ||
|
|
||
| expect(onSave).not.toHaveBeenCalled(); | ||
| expect( | ||
| await screen.findByText("validation.required") | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("allows save once a value is provided when required", async () => { | ||
| const user = userEvent.setup(); | ||
| render( | ||
| <SponsorItemDialog | ||
| entity={{ ...BASE_ENTITY, default_quantity: "" }} | ||
| onSave={onSave} | ||
| onClose={onClose} | ||
| requireDefaultQuantity | ||
| /> | ||
| ); | ||
|
|
||
| await fillRequiredTextFields(user); | ||
| await user.type( | ||
| document.querySelector("input[name=\"default_quantity\"]"), | ||
| "5" | ||
| ); | ||
| await submit(user); | ||
|
|
||
| await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)); | ||
| expect(onSave.mock.calls[0][0]).toEqual( | ||
| expect.objectContaining({ default_quantity: 5 }) | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
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.
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.
@tomrndom This branch was cut from
78ef677c(Aug 3) and does not contain #1002 (merged Aug 21), so this rewrite ofsaveSponsorFormItemsits on top of the pre-#1002 version of the file and reverts it. GitHub already reports the PR asCONFLICTING; master is 31 commits ahead.#1002 deliberately stopped sending images in the item request body, because the nested-images path replaces the whole collection on update.
origin/master:src/actions/sponsor-forms-actions.js:1424-1429:With this branch's
normalizeItem, stored images are filtered out —file_pathiswrite_onlyin purchases-api'sShowFormItemImageSerializer, so a fetched item only carriesid+file_url— and the PUT sendsimages: [].ShowFormItemService.updatethen runsform_item.images.all().delete()(show_form_item_service.py:95-97). Concretely: upload an image, save, reopen the item, edit the name, save — every image on that item is gone.What merging as-is would undo:
delete normalizedEntity.imagesimages.filter(img => img.file_path)→ PUT sendsimages: []→ collection wipedsaveNewItemImagesposts new uploads to/items/{id}/imagesonImageDeletedonSponsorItemDialog, wired toMuiFormikUpload'sonDeleteremoveItemFilewired throughhandleRemoveItemImagein the list pageexpand: "images"on the save request paramssaveSponsorFormItem/updateSponsorFormItemtests, including "omits persisted images from the update request body so they are never round-tripped"Could you rebase onto master and rebuild the change on top of #1002? The intent here — one shared dialog, a single save action,
requireDefaultQuantity— still holds. On the new base it needs to keepdelete normalizedEntity.images+saveNewItemImages, theexpand: "images"param,onImageDeletedpassed fromsponsor-form-item-list-page/index.js, and master's existing tests, extended to cover the new POST/PUT branch.