Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jun 12, 2019
1 parent f0fb443 commit 61f19ed
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/block-library/src/table/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import deepFreeze from 'deep-freeze';
*/
import {
createTable,
getCellAttribute,
updateCellAttribute,
updateCellContent,
insertRow,
deleteRow,
Expand Down Expand Up @@ -74,6 +76,36 @@ const tableWithContent = deepFreeze( {
],
} );

const tableWithAttribute = deepFreeze( {
body: [
{
cells: [
{
content: '',
tag: 'td',
},
{
content: '',
tag: 'td',
},
],
},
{
cells: [
{
content: '',
tag: 'td',
},
{
testAttr: 'testVal',
content: '',
tag: 'td',
},
],
},
],
} );

describe( 'createTable', () => {
it( 'should create a table', () => {
const state = createTable( { rowCount: 2, columnCount: 2 } );
Expand All @@ -82,6 +114,33 @@ describe( 'createTable', () => {
} );
} );

describe( 'getCellAttribute', () => {
it( 'should get the cell attribute', () => {
const state = getCellAttribute( tableWithAttribute, {
section: 'body',
rowIndex: 1,
columnIndex: 1,
attributeName: 'testAttr',
} );

expect( state ).toBe( 'testVal' );
} );
} );

describe( 'updateCellAttribute', () => {
it( 'should update cell attribute', () => {
const state = updateCellAttribute( table, {
section: 'body',
rowIndex: 1,
columnIndex: 1,
attributeName: 'testAttr',
value: 'testVal',
} );

expect( state ).toEqual( tableWithAttribute );
} );
} );

describe( 'updateCellContent', () => {
it( 'should update cell content', () => {
const state = updateCellContent( table, {
Expand Down

0 comments on commit 61f19ed

Please sign in to comment.