Skip to content

Commit

Permalink
tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MonireRasouli committed Jan 28, 2025
1 parent 06b6e64 commit ff9f117
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/components/views/Basket/Basket.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemoryRouter } from 'react-router-dom';
import { useMutation } from 'react-query';
import { waitFor, fireEvent, screen } from '@folio/jest-config-stripes/testing-library/react';
import { waitFor, fireEvent } from '@folio/jest-config-stripes/testing-library/react';

import {
Button,
Expand All @@ -13,7 +13,13 @@ import Basket from './Basket';
import translationsProperties from '../../../../test/helpers';
import { data, handlers } from './testResources';

jest.mock('../../BasketList', () => () => <div>BasketList</div>);
jest.mock('../../BasketList', () => (props) => (
<div>
<input type="checkbox" />
<button icon="trash" onClick={() => props.handlers.onRemoveBasketItem()} type="button">Remove</button>
BasketList
</div>
));
jest.mock('../../AgreementSearchButton', () => () => <div>AgreementSearchButton</div>);
jest.mock('../../AgreementModal', () => () => <div>AgreementModal</div>);

Expand Down Expand Up @@ -70,6 +76,12 @@ describe('Basket', () => {
expect(getByText('BasketList')).toBeInTheDocument();
});

if (isButtonDisabled) {
test('the Create New Agreement button is disabled', async () => {
await Button('Create new agreement').is({ disabled: true });
});
}

describe(' clicking on the create agreement button', () => {
if (!isButtonDisabled) {
it('triggers create agreement logic on button click', async () => {
Expand All @@ -89,6 +101,20 @@ describe('Basket', () => {
}
});

it('toggles item selection', async () => {
const { getByText } = renderComponent;
const basketList = getByText('BasketList');

const checkbox = basketList.querySelector('input[type="checkbox"]');
expect(checkbox).toBeInTheDocument();

fireEvent.click(checkbox);
expect(checkbox.checked).toBe(true);

fireEvent.click(checkbox);
expect(checkbox.checked).toBe(false);
});

it('renders the close basket button', async () => {
const { getByRole } = renderComponent;
expect(getByRole('button', { name: 'Close basket' })).toBeInTheDocument();
Expand Down

0 comments on commit ff9f117

Please sign in to comment.