Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from tannakartikey/table-perf
Browse files Browse the repository at this point in the history
Refactored Row component spec in accordance with #1429
  • Loading branch information
abhishekakade committed Apr 23, 2020
2 parents 5362202 + a0a8877 commit a001012
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/__tests__/components/Row.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Row from '../../components/row';

import {shallow} from 'enzyme';
import {mount} from 'enzyme';
import React from 'react';
import {MemoryRouter} from 'react-router-dom';

const state = {
active: '1',
Expand All @@ -27,8 +28,25 @@ const districts = {
};

describe('Row component', () => {
let wrapper;
const RealDate = Date;
const handleReveal = jest.fn();

const wrapper = mount(
<MemoryRouter>
<table>
<tbody>
<Row
state={state}
districts={districts}
index={1}
total={false}
reveal={true}
handleReveal={handleReveal}
/>
</tbody>
</table>
</MemoryRouter>
);

beforeAll(() => {
const mockedDate = new Date('2020-04-13T17:11:38.158Z');
Expand All @@ -38,10 +56,6 @@ describe('Row component', () => {
return mockedDate;
}
};

wrapper = shallow(
<Row state={state} districts={districts} index={1} total={false} />
);
});

afterAll(() => {
Expand All @@ -67,15 +81,19 @@ describe('Row component', () => {
expect(deaths).toEqual('-');
});

test('State last update data', () => {
const stateLastUpdate = wrapper.find('tr.state-last-update');
test('Districts and the confirmed cases', () => {
const stateRow = wrapper.find('tr.state');
expect(stateRow).toHaveLength(1);

expect(stateLastUpdate.text()).toMatch(/14 days ago/i);
});
stateRow.simulate('click');
expect(handleReveal).toHaveBeenCalledWith('Andaman and Nicobar Islands');

test('Districts and the confirmed cases', () => {
const districtsSelector = wrapper.find('tr.district');
const stateLastUpdate = wrapper.find('tr.state-last-update');

expect(districtsSelector).toHaveLength(3);
expect(stateLastUpdate.text()).toMatch(/14 days ago/i);

districtsSelector.forEach((e, index) => {
const cells = e.find('td');
const district = cells.at(0).childAt(0).text();
Expand Down

0 comments on commit a001012

Please sign in to comment.