Skip to content

Commit

Permalink
feat: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieterjan Van Saet committed Jan 10, 2022
1 parent b717897 commit f55b89f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
90 changes: 90 additions & 0 deletions packages/table/src/Table.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Table from "./Table";
import { mount } from 'enzyme';
import React from 'react';
import { TABLE_MOCK_COLUMNS, TABLE_MOCK_ROWS, TABLE_MOCK_NESTED_ROWS, TABLE_MOCK_FILTER } from './mocks/Table.mock.js';
import * as sinon from 'sinon';

describe('Table Test', () => {
let component: Table;

describe('Setup and Teardown', () => {
test('Should create a valid component', () => {
const component = mount(
<Table />
);

expect(component).toBeDefined();
});

test('Should set an initial state', () => {
const component = mount(
<Table
tableId="1"
columns={TABLE_MOCK_COLUMNS()}
rows={TABLE_MOCK_ROWS.slice(0, 10)}
/>
);

expect(component).toBeDefined();
});
});

describe('Data', () => {
test('Should render data', () => {
const component = mount(
<Table
tableId="1"
columns={TABLE_MOCK_COLUMNS()}
rows={TABLE_MOCK_ROWS.slice(0, 10)}
/>
);

expect(component.find('tbody tr').length).toBe(10);
});
});

describe('Filters', () => {
test('Should render generic filter', () => {
const component = mount(
<Table
tableId="1"
columns={TABLE_MOCK_COLUMNS()}
rows={TABLE_MOCK_ROWS.slice(0, 10)}
filters={TABLE_MOCK_FILTER}
/>
);

expect(component.find(`input[name="${TABLE_MOCK_FILTER[0].id}"]`).props()).toHaveProperty('id', TABLE_MOCK_FILTER[0].id);
});

test('Should render optional filters', () => {
const component = mount(
<Table
tableId="1"
columns={TABLE_MOCK_COLUMNS()}
rows={TABLE_MOCK_ROWS.slice(0, 10)}
filters={TABLE_MOCK_FILTER}
/>
);

expect(component.find(`.m-table-filter__optional-filters > *`).length).toBe(4);
});
});

describe('Pagination', () => {
test('Should render pagination', () => {
const component = mount(
<Table
tableId="1"
columns={TABLE_MOCK_COLUMNS()}
rows={TABLE_MOCK_ROWS.slice(0, 10)}
itemsPerPage={10}
totalItems={1723}
currentPage={1}
/>
);

expect(component.find(`.m-pagination`)).toBeDefined()
});
});
});
4 changes: 4 additions & 0 deletions packages/table/src/components/Filter/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Filter = ({
case "select":
return (
<Select
key={filter.id}
label={filter.label}
id={filter.id}
name={filter.id}
Expand All @@ -36,6 +37,7 @@ const Filter = ({
case "datepicker":
return (
<Datepicker
key={filter.id}
label={filter.label}
id={filter.id}
name={filter.id}
Expand All @@ -47,6 +49,7 @@ const Filter = ({
case "telephone-number":
return (
<TelephoneNumber
key={filter.id}
label={filter.label}
id={filter.id}
name={filter.id}
Expand All @@ -58,6 +61,7 @@ const Filter = ({
default:
return (
<TextField
key={filter.id}
label={filter.label}
id={filter.id}
name={filter.id}
Expand Down

0 comments on commit f55b89f

Please sign in to comment.