Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Use React Testing Library #290

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 60 additions & 54 deletions client/src/components/tests/CKANDropdownFilter-test.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import CKANDropdownFilter from '../CKANDropdownFilter';
import { render } from '@testing-library/react';

Enzyme.configure({ adapter: new Adapter() });

describe('CKANDropdownFilter', () => {
describe('render()', () => {
it('renders a select', () => {
const wrapper = mount(
<CKANDropdownFilter
id="123"
selections={['foo']}
/>
);

expect(wrapper.find('select').length).toBe(1);
});

it('renders the provided selections as options and a blank first option', () => {
const wrapper = mount(
<CKANDropdownFilter
id="123"
selections={['foo', 'bar', 'baz']}
/>
);

expect(wrapper.find('option').length).toBe(4);
expect(wrapper.find('option').first().text()).toBe('');
});

it('renders a label for the select field when provided', () => {
const wrapper = mount(
<CKANDropdownFilter
id="123"
label="Search things"
selections={['foo']}
/>
);

expect(wrapper.find('label').length).toBe(1);
expect(wrapper.find('label').text()).toContain('Search things');
});

it('adds the provided extraClass values', () => {
const wrapper = mount(
<CKANDropdownFilter
id="123"
extraClass="foo bar baz"
selections={['foo']}
/>
);

expect(wrapper.find('div.foo.bar.baz').length).toBe(1);
});
});
test('Something ', () => {
const { container } = render(
<CKANDropdownFilter {...{
id: '123',
selections: ['foo']
}}
/>
);
expect(container.querySelectorAll('select')).toHaveLength(1);
});

// describe('CKANDropdownFilter', () => {
// describe('render()', () => {
// it('renders a select', () => {
// const wrapper = mount(
// <CKANDropdownFilter
// />
// );

// expect(wrapper.find('select').length).toBe(1);
// });

// it('renders the provided selections as options and a blank first option', () => {
// const wrapper = mount(
// <CKANDropdownFilter
// id="123"
// selections={['foo', 'bar', 'baz']}
// />
// );

// expect(wrapper.find('option').length).toBe(4);
// expect(wrapper.find('option').first().text()).toBe('');
// });

// it('renders a label for the select field when provided', () => {
// const wrapper = mount(
// <CKANDropdownFilter
// id="123"
// label="Search things"
// selections={['foo']}
// />
// );

// expect(wrapper.find('label').length).toBe(1);
// expect(wrapper.find('label').text()).toContain('Search things');
// });

// it('adds the provided extraClass values', () => {
// const wrapper = mount(
// <CKANDropdownFilter
// id="123"
// extraClass="foo bar baz"
// selections={['foo']}
// />
// );

// expect(wrapper.find('div.foo.bar.baz').length).toBe(1);
// });
// });
// });
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lint-sass": "sass-lint client/src"
},
"dependencies": {
"@testing-library/react": "^14.0.0",
"bootstrap": "^4.6.2",
"classnames": "^2.3.2",
"griddle-react": "^1.13.1",
Expand All @@ -40,12 +41,8 @@
"@silverstripe/webpack-config": "^2.0.0",
"babel-jest": "^29.2.2",
"core-js": "^3.26.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"jest-cli": "^29.2.2",
"jest-environment-jsdom": "^29.3.1",
"react-16": "npm:react@^16.14.0",
"react-dom-16": "npm:react-dom@^16.14.0",
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0"
},
Expand Down
Loading