Skip to content

Commit

Permalink
DEV tableHelpers, tableRow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Aug 11, 2022
1 parent 85d039b commit 459c44b
Show file tree
Hide file tree
Showing 2 changed files with 353 additions and 1 deletion.
303 changes: 303 additions & 0 deletions src/components/table/__tests__/__snapshots__/tableHelpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Object {
Object {
"content": "hello world",
},
Object {
"content": <React.Fragment>
hello world
</React.Fragment>,
},
],
"headerSelectProps": Object {},
"isSortTable": false,
Expand Down Expand Up @@ -120,3 +125,301 @@ Object {
},
}
`;

exports[`TableHelpers tableRows should return parsed table body settings, props: tableRows 1`] = `
Object {
"basic": Object {
"allRowsSelected": true,
"isExpandableCell": false,
"isExpandableRow": false,
"isSelectTable": false,
"rows": Array [],
},
"onExpandCells": Object {
"allRowsSelected": false,
"isExpandableCell": true,
"isExpandableRow": false,
"isSelectTable": false,
"rows": Array [
Object {
"cells": Array [
Object {
"content": "lorem",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 0,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "dolor",
"expandedContent": "sit",
"isExpanded": true,
"props": Object {
"compoundExpand": Object {
"isExpanded": true,
"onToggle": [Function],
},
"dataLabel": undefined,
"isActionCell": undefined,
"noPadding": undefined,
"width": undefined,
},
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 1,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "hello world",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 2,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": <React.Fragment>
hello world
</React.Fragment>,
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 3,
"select": undefined,
},
],
},
"onExpandRows": Object {
"allRowsSelected": false,
"isExpandableCell": false,
"isExpandableRow": true,
"isSelectTable": false,
"rows": Array [
Object {
"cells": Array [
Object {
"content": "lorem",
},
],
"expand": Object {
"isExpanded": true,
"onToggle": [Function],
"rowIndex": 0,
},
"expandedContent": "ipsum",
"rowIndex": 0,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "dolor",
"props": Object {
"dataLabel": undefined,
"isActionCell": undefined,
"noPadding": undefined,
"width": undefined,
},
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 1,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "hello world",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 2,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": <React.Fragment>
hello world
</React.Fragment>,
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 3,
"select": undefined,
},
],
},
"onSelect": Object {
"allRowsSelected": false,
"isExpandableCell": false,
"isExpandableRow": false,
"isSelectTable": true,
"rows": Array [
Object {
"cells": Array [
Object {
"content": "lorem",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 0,
"select": Object {
"cells": Array [
"lorem",
],
"disable": false,
"isSelected": true,
"onSelect": [Function],
"rowIndex": 0,
},
},
Object {
"cells": Array [
Object {
"content": "dolor",
"props": Object {
"dataLabel": undefined,
"isActionCell": undefined,
"noPadding": undefined,
"width": undefined,
},
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 1,
"select": Object {
"cells": Array [
Object {
"content": "dolor",
},
],
"disable": true,
"isSelected": false,
"onSelect": [Function],
"rowIndex": 1,
},
},
Object {
"cells": Array [
Object {
"content": "hello world",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 2,
"select": Object {
"cells": Array [
[Function],
],
"disable": false,
"isSelected": false,
"onSelect": [Function],
"rowIndex": 2,
},
},
Object {
"cells": Array [
Object {
"content": <React.Fragment>
hello world
</React.Fragment>,
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 3,
"select": Object {
"cells": Array [
<React.Fragment>
hello world
</React.Fragment>,
],
"disable": false,
"isSelected": false,
"onSelect": [Function],
"rowIndex": 3,
},
},
],
},
"rows": Object {
"allRowsSelected": false,
"isExpandableCell": false,
"isExpandableRow": false,
"isSelectTable": false,
"rows": Array [
Object {
"cells": Array [
Object {
"content": "lorem",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 0,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "dolor",
"props": Object {
"dataLabel": undefined,
"isActionCell": undefined,
"noPadding": undefined,
"width": undefined,
},
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 1,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": "hello world",
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 2,
"select": undefined,
},
Object {
"cells": Array [
Object {
"content": <React.Fragment>
hello world
</React.Fragment>,
},
],
"expand": undefined,
"expandedContent": undefined,
"rowIndex": 3,
"select": undefined,
},
],
},
}
`;
51 changes: 50 additions & 1 deletion src/components/table/__tests__/tableHelpers.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { tableHelpers, generateTableKey, tableHeader, tableRows } from '../tableHelpers';

describe('TableHelpers', () => {
Expand All @@ -22,7 +23,14 @@ describe('TableHelpers', () => {
expect({
basic: tableHeader(),
allRowsSelected: tableHeader({ allRowsSelected: true }),
columnHeaders: tableHeader({ columnHeaders: ['lorem', { content: 'dolor' }, () => 'hello world'] }),
columnHeaders: tableHeader({
columnHeaders: [
'lorem',
{ content: 'dolor' },
() => 'hello world',
<React.Fragment>hello world</React.Fragment>
]
}),
onSelect: tableHeader({
onSelect: () => {},
columnHeaders: ['lorem', { content: 'dolor' }, () => 'hello world']
Expand All @@ -38,4 +46,45 @@ describe('TableHelpers', () => {
})
}).toMatchSnapshot('tableHeader');
});

it('tableRows should return parsed table body settings, props', () => {
expect({
basic: tableRows(),
rows: tableRows({
rows: [
{ cells: ['lorem'] },
{ cells: [{ content: 'dolor' }] },
{ cells: [() => 'hello world'] },
{ cells: [<React.Fragment>hello world</React.Fragment>] }
]
}),
onExpandCells: tableRows({
onExpand: () => {},
rows: [
{ cells: ['lorem'] },
{ cells: [{ content: 'dolor', expandedContent: 'sit', isExpanded: true }] },
{ cells: [() => 'hello world'] },
{ cells: [<React.Fragment>hello world</React.Fragment>] }
]
}),
onExpandRows: tableRows({
onExpand: () => {},
rows: [
{ cells: ['lorem'], expandedContent: 'ipsum', isExpanded: true },
{ cells: [{ content: 'dolor' }] },
{ cells: [() => 'hello world'] },
{ cells: [<React.Fragment>hello world</React.Fragment>] }
]
}),
onSelect: tableRows({
onSelect: () => {},
rows: [
{ cells: ['lorem'], isSelected: true },
{ cells: [{ content: 'dolor' }], isDisabled: true },
{ cells: [() => 'hello world'] },
{ cells: [<React.Fragment>hello world</React.Fragment>] }
]
})
}).toMatchSnapshot('tableRows');
});
});

0 comments on commit 459c44b

Please sign in to comment.