2024-06-27 23:31:59 +02:00
|
|
|
import { Product } from "@/lib/product"
|
2024-06-28 04:00:29 +02:00
|
|
|
import {ProductAttributeEditor} from "../ProductAttributeEditor"
|
2024-06-27 23:31:59 +02:00
|
|
|
import { area } from "enheter"
|
2024-06-28 04:00:29 +02:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react-native';
|
2024-06-27 23:31:59 +02:00
|
|
|
import React from "react";
|
2024-06-28 04:00:29 +02:00
|
|
|
import { emitTypingEvents } from "@testing-library/react-native/build/user-event/type/type";
|
2024-06-27 23:31:59 +02:00
|
|
|
|
|
|
|
describe("Product editor tests", () => {
|
2024-06-28 04:00:29 +02:00
|
|
|
it("Product attributes can be deleted", async () => {
|
2024-06-27 23:31:59 +02:00
|
|
|
const product = new Product(
|
|
|
|
100,
|
|
|
|
area("squareFoot", 4 * 7)
|
|
|
|
);
|
|
|
|
const onChange = jest.fn();
|
|
|
|
const onDelete = jest.fn();
|
2024-06-28 04:00:29 +02:00
|
|
|
render(
|
|
|
|
<ProductAttributeEditor
|
|
|
|
attributeKey="name"
|
|
|
|
attributeValue="product"
|
|
|
|
product={product}
|
|
|
|
onChange={onChange}
|
|
|
|
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 () => {
|
|
|
|
const productName = "Fun Product";
|
|
|
|
const product = new Product(
|
|
|
|
100,
|
|
|
|
area("squareFoot", 4 * 7),
|
|
|
|
{ name: productName },
|
|
|
|
);
|
|
|
|
const onChange = jest.fn();
|
|
|
|
const onDelete = jest.fn();
|
|
|
|
render(
|
|
|
|
<ProductAttributeEditor
|
|
|
|
attributeKey="Name"
|
|
|
|
attributeValue="product"
|
|
|
|
product={product}
|
|
|
|
onChange={onChange}
|
|
|
|
onDelete={onDelete}
|
|
|
|
/>);
|
|
|
|
fireEvent.press(screen.getByText("product")); // Use getByText instead of findByText
|
|
|
|
fireEvent.changeText(screen.getByLabelText("Edit Value"), "new name");
|
|
|
|
expect(onChange).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
|
|
|
})
|