From 9111948959207832154e71575f11fdc9977a3069 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Sun, 18 Nov 2018 20:54:07 -0500 Subject: [PATCH] add basic component test for data list toolbar --- __tests__/components/DataListToolbar.test.jsx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 __tests__/components/DataListToolbar.test.jsx diff --git a/__tests__/components/DataListToolbar.test.jsx b/__tests__/components/DataListToolbar.test.jsx new file mode 100644 index 0000000000..22b91e6530 --- /dev/null +++ b/__tests__/components/DataListToolbar.test.jsx @@ -0,0 +1,57 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import DataListToolbar from '../../src/components/DataListToolbar'; + +describe('', () => { + const columns = [{ name: 'Name', key: 'name', isSortable: true }]; + const noop = () => {}; + + let toolbar; + + afterEach(() => { + if (toolbar) { + toolbar.unmount(); + toolbar = null; + } + }); + + test('it triggers the expected callbacks', () => { + const search = 'button[aria-label="Search"]'; + const searchTextInput = 'input[aria-label="search text input"]'; + const selectAll = 'input[aria-label="Select all"]'; + const sort = 'button[aria-label="Sort"]'; + + const onSearch = jest.fn(); + const onSort = jest.fn(); + const onSelectAll = jest.fn(); + + toolbar = mount( + + ); + + toolbar.find(sort).simulate('click'); + toolbar.find(selectAll).simulate('change', { target: { checked: false } }); + + expect(onSelectAll).toHaveBeenCalledTimes(1); + expect(onSort).toHaveBeenCalledTimes(1); + expect(onSort).toBeCalledWith('name', 'descending'); + + expect(onSelectAll).toHaveBeenCalledTimes(1); + expect(onSelectAll.mock.calls[0][0]).toBe(false); + + toolbar.find(searchTextInput).instance().value = 'test-321'; + toolbar.find(searchTextInput).simulate('change'); + toolbar.find(search).simulate('click'); + + expect(onSearch).toHaveBeenCalledTimes(1); + expect(onSearch).toBeCalledWith('test-321'); + }); +});