Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
NadicaUzunova authored Aug 9, 2024
1 parent 18ffccd commit 3870d79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/AddMeasurement.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import AddMeasurement from '../src/components/Measurements/AddMeasurement';
import AddMeasurement from './src/components/Measurements/AddMeasurement';

describe('AddMeasurement', () => {
it('renders the component', () => {
Expand Down
39 changes: 39 additions & 0 deletions frontend/AddProduct.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import AddProduct from './src/components/Products/AddProduct';

describe('AddProduct', () => {
it('renders the AddProduct component', () => {
render(<AddProduct open={true} handleClose={() => {}} />);
expect(screen.getByText('Add new product')).toBeInTheDocument();
});

it('updates the name input value', () => {
render(<AddProduct open={true} handleClose={() => {}} />);
const nameInput = screen.getByLabelText('product name');
fireEvent.change(nameInput, { target: { value: 'Test Product' } });
expect(nameInput.value).toBe('Test Product');
});

it('updates the max measure input value', () => {
render(<AddProduct open={true} handleClose={() => {}} />);
const maxMeasureInput = screen.getByLabelText('Max measure');
fireEvent.change(maxMeasureInput, { target: { value: '10' } });
expect(maxMeasureInput.value).toBe('10');
});

it('updates the min measure input value', () => {
render(<AddProduct open={true} handleClose={() => {}} />);
const minMeasureInput = screen.getByLabelText('Min measure');
fireEvent.change(minMeasureInput, { target: { value: '5' } });
expect(minMeasureInput.value).toBe('5');
});

it('calls the addProduct function when Add button is clicked', () => {
const addProductMock = jest.fn();
render(<AddProduct open={true} handleClose={() => {}} />);
const addButton = screen.getByText('Add');
fireEvent.click(addButton);
expect(addProductMock).toHaveBeenCalled();
});
});

0 comments on commit 3870d79

Please sign in to comment.