-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to show 0 value in price fied (#5180)
* Show 0 value in ProductVariantPrice * Add tests * Add changeset
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
You can now provide 0 variant price value during product creation |
87 changes: 87 additions & 0 deletions
87
src/products/components/ProductVariantPrice/ProductVariantPrice.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,87 @@ | ||
import { ChannelData } from "@dashboard/channels/utils"; | ||
import { ThemeWrapper } from "@test/themeWrapper"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import { ProductVariantPrice } from "./ProductVariantPrice"; | ||
|
||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<ThemeWrapper>{children}</ThemeWrapper> | ||
); | ||
|
||
jest.mock("react-intl", () => ({ | ||
useIntl: jest.fn(() => ({ | ||
formatMessage: jest.fn(x => x.defaultMessage), | ||
})), | ||
defineMessages: jest.fn(x => x), | ||
FormattedMessage: ({ defaultMessage }: { defaultMessage: string }) => <>{defaultMessage}</>, | ||
})); | ||
|
||
describe("ProductVariantPrice", () => { | ||
it("should render not assign info text when variant is not assigned to any channel", () => { | ||
// Arrange | ||
render(<ProductVariantPrice errors={[]} productVariantChannelListings={[]} />, { wrapper }); | ||
|
||
// Assert | ||
expect( | ||
screen.getByText( | ||
"Assign this variant to a channel in the product channel manager to define prices", | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should allow to display 0 value", async () => { | ||
// Arrange | ||
const listing = [ | ||
{ | ||
id: "1", | ||
currency: "USD", | ||
price: 0, | ||
preorderThreshold: 0, | ||
}, | ||
] as unknown as ChannelData[]; | ||
|
||
render(<ProductVariantPrice errors={[]} productVariantChannelListings={listing} />, { | ||
wrapper, | ||
}); | ||
|
||
// Assert | ||
expect(screen.getByTestId("price-field")).toHaveValue(0); | ||
}); | ||
|
||
it("should allow to set price value", () => { | ||
// Arrange | ||
const onChange = jest.fn(); | ||
const listing = [ | ||
{ | ||
id: "1", | ||
currency: "USD", | ||
price: "", | ||
preorderThreshold: 0, | ||
}, | ||
] as unknown as ChannelData[]; | ||
|
||
render( | ||
<ProductVariantPrice | ||
errors={[]} | ||
productVariantChannelListings={listing} | ||
onChange={onChange} | ||
/>, | ||
{ | ||
wrapper, | ||
}, | ||
); | ||
|
||
const input = screen.getByTestId("price-field"); | ||
|
||
// Act | ||
fireEvent.change(input, { target: { value: 0 } }); | ||
|
||
// Assert | ||
expect(onChange).toHaveBeenCalledWith("1", { | ||
price: 0, | ||
preorderThreshold: 0, | ||
costPrice: undefined, | ||
}); | ||
}); | ||
}); |
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