2024-07-31 19:01:45 +02:00
|
|
|
import { LumberProduct, Product } from "@/lib/product"
|
2024-06-28 04:00:29 +02:00
|
|
|
import {ProductAttributeEditor} from "../ProductAttributeEditor"
|
|
|
|
import { fireEvent, render, screen } from '@testing-library/react-native';
|
2024-06-27 23:31:59 +02:00
|
|
|
|
|
|
|
describe("Product editor tests", () => {
|
2024-06-30 18:37:27 +02:00
|
|
|
const productName = "Fun Product";
|
2024-06-28 04:00:29 +02:00
|
|
|
it("Product attributes can be deleted", async () => {
|
2024-06-27 23:31:59 +02:00
|
|
|
const onChange = jest.fn();
|
|
|
|
const onDelete = jest.fn();
|
2024-06-28 04:00:29 +02:00
|
|
|
render(
|
|
|
|
<ProductAttributeEditor
|
|
|
|
attributeKey="name"
|
|
|
|
attributeValue="product"
|
2024-06-30 18:37:27 +02:00
|
|
|
onChangeAttribute={onChange}
|
2024-06-28 04:00:29 +02:00
|
|
|
onDelete={onDelete}
|
|
|
|
/>);
|
|
|
|
expect(screen.getByLabelText("Delete Attribute")).not.toBeNull();
|
|
|
|
fireEvent.press(await screen.getByLabelText("Delete Attribute"));
|
|
|
|
expect(onDelete).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
it("Product attributes can be modified", async () => {
|
2024-07-31 19:01:45 +02:00
|
|
|
const product : Product = {
|
|
|
|
pricePerUnit: 10,
|
|
|
|
dimensions: {
|
|
|
|
l: 40,
|
|
|
|
u: "ft",
|
|
|
|
},
|
|
|
|
type: "lumber",
|
|
|
|
}
|
2024-06-28 04:00:29 +02:00
|
|
|
const onChange = jest.fn();
|
|
|
|
const onDelete = jest.fn();
|
2024-06-30 18:37:27 +02:00
|
|
|
const onKeyChange = jest.fn();
|
2024-06-28 04:00:29 +02:00
|
|
|
render(
|
|
|
|
<ProductAttributeEditor
|
2024-06-30 18:37:27 +02:00
|
|
|
attributeKey="old test key"
|
|
|
|
attributeValue="old test value"
|
|
|
|
onChangeAttribute={onChange}
|
2024-06-28 04:00:29 +02:00
|
|
|
onDelete={onDelete}
|
2024-06-30 18:37:27 +02:00
|
|
|
onChangeAttributeKey={onKeyChange}
|
2024-06-28 04:00:29 +02:00
|
|
|
/>);
|
2024-06-30 18:37:27 +02:00
|
|
|
fireEvent.changeText(screen.getByLabelText("Edit Key"), "new test key");
|
|
|
|
expect(onKeyChange).toHaveBeenCalled();
|
2024-06-28 04:00:29 +02:00
|
|
|
fireEvent.changeText(screen.getByLabelText("Edit Value"), "new name");
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
2024-06-30 18:37:27 +02:00
|
|
|
fireEvent.press(screen.getByLabelText("Delete Attribute"));
|
|
|
|
expect(onDelete).toHaveBeenCalled();
|
2024-06-27 23:31:59 +02:00
|
|
|
})
|
2024-06-28 04:00:29 +02:00
|
|
|
|
2024-06-27 23:31:59 +02:00
|
|
|
})
|