diff --git a/packages/block-library/src/table/test/state.js b/packages/block-library/src/table/test/state.js index 63904298be2bb..b076f75ada75a 100644 --- a/packages/block-library/src/table/test/state.js +++ b/packages/block-library/src/table/test/state.js @@ -8,6 +8,8 @@ import deepFreeze from 'deep-freeze'; */ import { createTable, + getCellAttribute, + updateCellAttribute, updateCellContent, insertRow, deleteRow, @@ -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 } ); @@ -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, {