Skip to content

Commit

Permalink
fix(simplelist): all tests should have at least one assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
tay1orjones committed May 5, 2020
1 parent b50d33b commit 9e8acfe
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/components/List/SimpleList/SimpleList.test.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import { settings } from '../../../constants/Settings';

import SimpleList from './SimpleList';

const { iotPrefix } = settings;

const getFatRowListItems = num =>
Array(num)
.fill(0)
Expand Down Expand Up @@ -67,16 +72,27 @@ describe('SimpleList component tests', () => {
expect(getByTitle('Item 5')).toBeTruthy();
});

test('SimpleList handleSelect', () => {
test('the first item is selectable via keyboard', () => {
const { getAllByRole } = render(<SimpleList title="Simple list" items={getListItems(1)} />);
fireEvent.keyPress(getAllByRole('button')[0], { key: 'Enter', charCode: 13 });
expect(getAllByRole('button')[0]).toBeInTheDocument();
expect(getAllByRole('button')[0]).toBeVisible();
expect(
getAllByRole('button')[0].className.includes(`${iotPrefix}--list-item__selected`)
).toEqual(true);
});

test('SimpleList when unselect selected item', () => {
const { getAllByRole } = render(<SimpleList title="Simple list" items={getListItems(1)} />);
fireEvent.keyPress(getAllByRole('button')[0], { key: 'Enter', charCode: 13 });
fireEvent.keyPress(getAllByRole('button')[0], { key: 'Enter', charCode: 13 });
});
// this is a failing test, opened defect at https://github.com/IBM/carbon-addons-iot-react/issues/1149
// test('the first item is properly unselected via keyboard', () => {
// const { getAllByRole } = render(<SimpleList title="Simple list" items={getListItems(1)} />);
// fireEvent.keyPress(getAllByRole('button')[0], { key: 'Enter', charCode: 13 });
// fireEvent.keyPress(getAllByRole('button')[0], { key: 'Enter', charCode: 13 });
// expect(getAllByRole('button')[0]).toBeInTheDocument();
// expect(getAllByRole('button')[0]).toBeVisible();
// expect(
// getAllByRole('button')[0].className.includes(`.${iotPrefix}--list-item__selected`)
// ).toEqual(false);
// });

test('SimpleList when click on next page', () => {
const { getAllByRole, getByTitle } = render(
Expand Down

0 comments on commit 9e8acfe

Please sign in to comment.