From 459c44bd07194725913356d1c8e6aa21e0b540e3 Mon Sep 17 00:00:00 2001 From: CD Cabrera Date: Thu, 11 Aug 2022 17:10:15 -0400 Subject: [PATCH] DEV tableHelpers, tableRow tests --- .../__snapshots__/tableHelpers.test.js.snap | 303 ++++++++++++++++++ .../table/__tests__/tableHelpers.test.js | 51 ++- 2 files changed, 353 insertions(+), 1 deletion(-) diff --git a/src/components/table/__tests__/__snapshots__/tableHelpers.test.js.snap b/src/components/table/__tests__/__snapshots__/tableHelpers.test.js.snap index c5c55e6b..3734fe5b 100644 --- a/src/components/table/__tests__/__snapshots__/tableHelpers.test.js.snap +++ b/src/components/table/__tests__/__snapshots__/tableHelpers.test.js.snap @@ -45,6 +45,11 @@ Object { Object { "content": "hello world", }, + Object { + "content": + hello world + , + }, ], "headerSelectProps": Object {}, "isSortTable": false, @@ -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": + hello world + , + }, + ], + "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": + hello world + , + }, + ], + "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": + hello world + , + }, + ], + "expand": undefined, + "expandedContent": undefined, + "rowIndex": 3, + "select": Object { + "cells": Array [ + + hello world + , + ], + "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": + hello world + , + }, + ], + "expand": undefined, + "expandedContent": undefined, + "rowIndex": 3, + "select": undefined, + }, + ], + }, +} +`; diff --git a/src/components/table/__tests__/tableHelpers.test.js b/src/components/table/__tests__/tableHelpers.test.js index 31374377..8c8074d9 100644 --- a/src/components/table/__tests__/tableHelpers.test.js +++ b/src/components/table/__tests__/tableHelpers.test.js @@ -1,3 +1,4 @@ +import React from 'react'; import { tableHelpers, generateTableKey, tableHeader, tableRows } from '../tableHelpers'; describe('TableHelpers', () => { @@ -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', + hello world + ] + }), onSelect: tableHeader({ onSelect: () => {}, columnHeaders: ['lorem', { content: 'dolor' }, () => 'hello world'] @@ -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: [hello world] } + ] + }), + onExpandCells: tableRows({ + onExpand: () => {}, + rows: [ + { cells: ['lorem'] }, + { cells: [{ content: 'dolor', expandedContent: 'sit', isExpanded: true }] }, + { cells: [() => 'hello world'] }, + { cells: [hello world] } + ] + }), + onExpandRows: tableRows({ + onExpand: () => {}, + rows: [ + { cells: ['lorem'], expandedContent: 'ipsum', isExpanded: true }, + { cells: [{ content: 'dolor' }] }, + { cells: [() => 'hello world'] }, + { cells: [hello world] } + ] + }), + onSelect: tableRows({ + onSelect: () => {}, + rows: [ + { cells: ['lorem'], isSelected: true }, + { cells: [{ content: 'dolor' }], isDisabled: true }, + { cells: [() => 'hello world'] }, + { cells: [hello world] } + ] + }) + }).toMatchSnapshot('tableRows'); + }); });