Skip to content

Commit

Permalink
add test for DocumentFilterArray
Browse files Browse the repository at this point in the history
  • Loading branch information
MonireRasouli committed Dec 20, 2024
1 parent dbe440c commit 95f91f4
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions lib/DocumentFilter/DocumentFilterArray.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { MemoryRouter } from 'react-router-dom';
import { screen } from'@testing-library/react';

Check warning on line 2 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

'screen' is defined but never used. Allowed unused vars must match /React/u

Check failure on line 2 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Expected space(s) after "from"
import { waitFor } from '@folio/jest-config-stripes/testing-library/react';
import { renderWithIntl, Button, TestForm, Dropdown} from '@folio/stripes-erm-testing';

Check failure on line 4 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

A space is required before '}'

import { translationsProperties } from '../../test/jest/helpers';

import DocumentFilterArray from './DocumentFilterArray';

Check failure on line 8 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Expected 1 empty line after import statement not followed by another import
const handleSubmit = jest.fn();
const translatedContentOptions = [
{
"value": "alternateNames",

Check failure on line 12 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote

Check failure on line 12 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote
"label": "Alternative names"

Check failure on line 13 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote

Check failure on line 13 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote
},
{
"value": "agreementContentTypes",

Check failure on line 16 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote

Check failure on line 16 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote
"label": "Content types"

Check failure on line 17 in lib/DocumentFilter/DocumentFilterArray.test.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

Strings must use singlequote
},
{
"value": "contacts",
"label": "Internal contacts"
},
{
"value": "orgs",
"label": "Organizations"
},
{
"value": "items",
"label": "Agreement lines"
},
{
"value": "linkedLicenses",
"label": "Linked licenses"
},
{
"value": "externalLicenseDocs",
"label": "External licenses"
},
{
"value": "supplementaryDocs",
"label": "Supplementary documents"
},
{
"value": "usageDataProviders",
"label": "Usage data"
},
{
"value": "relatedAgreements",
"label": "Related agreements"
},
{
"value": "tags",
"label": "Tags"
}
];
const onSubmit = jest.fn();
jest.mock('./DocumentFilterField', () => () => <div>DocumentFilterField</div>);

let renderComponent;
describe('DocumentFilterArray', () => {
beforeEach(() => {
renderComponent = renderWithIntl(
<MemoryRouter>
<TestForm onSubmit={onSubmit}>
<DocumentFilterArray
translatedContentOptions={translatedContentOptions}
name={"agreementContent"}
handleSubmit={handleSubmit}
/>
</TestForm>,
</MemoryRouter>,
translationsProperties
);
});

test('renders the And/Or dropdown button', async () => {
await Dropdown('Add filter').exists();
});

describe('clicking \'Add filter\' button', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('Add filter').click();
});
});

it('should render the \'AND\' and \'OR\' dropdown buttons', async () => {
await Button('AND').exists();
await Button('OR').exists();
});
});

describe('clicking \'OR\' button', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('Add filter').click();
await Button('OR').click();
});
});

it('should display the OR label', async () => {
const { getAllByText } = renderComponent;
await waitFor(async () => {
expect(getAllByText('OR').length).toEqual(2);
});
});
});

describe('clicking \'AND\' button', () => {
beforeEach(async () => {
await waitFor(async () => {
await Button('Add filter').click();
await Button('AND').click();
});
});

it('should display the AND label', async () => {
const { getAllByText } = renderComponent;
await waitFor(async () => {
expect(getAllByText('AND').length).toEqual(2);
});
});
});
});

0 comments on commit 95f91f4

Please sign in to comment.