diff --git a/test/specs/collections/Table/Table-test.js b/test/specs/collections/Table/Table-test.js index 674e9f0a49..131859a7e7 100644 --- a/test/specs/collections/Table/Table-test.js +++ b/test/specs/collections/Table/Table-test.js @@ -38,8 +38,70 @@ describe('Table', () => { common.propValueOnlyToClassName(Table, 'color') common.propValueOnlyToClassName(Table, 'size') - it('renders as a thead by default', () => { + it('renders as a table by default', () => { shallow() .should.have.tagName('table') }) + + describe('shorthand', () => { + let wrapper + let thead + let tbody + let tfoot + + beforeEach(() => { + wrapper = undefined + thead = undefined + tbody = undefined + tfoot = undefined + }) + + const headerRow = ['Name', 'Status', 'Notes'] + + const bodyRow = ({ name, status, notes }) => [name || '', status || '', notes || ''] + + const footerRow = [{ colSpan: 3, content: 'Total' }] + + const tableData = [ + { name: undefined, status: undefined, notes: undefined }, + { name: 'Jimmy', status: 'Requires Action', notes: undefined }, + { name: 'Jamie', status: undefined, notes: 'Hostile' }, + { name: 'Jill', status: undefined, notes: undefined }, + ] + + const wrapperMount = (props) => { + wrapper = mount(
) + + thead = wrapper.find('thead') + tbody = wrapper.find('tbody') + tfoot = wrapper.find('tfoot') + } + + it('renders empty tbody with no shorthand', () => { + wrapperMount() + + thead.should.have.lengthOf(0) + + tbody.should.have.lengthOf(1) + tbody.find('tr').should.have.lengthOf(0) + + tfoot.should.have.lengthOf(0) + }) + + it('renders the table', () => { + wrapperMount({ headerRow, bodyRow, footerRow, tableData }) + + thead.should.have.lengthOf(1) + thead.find('tr').should.have.lengthOf(1) + thead.find('tr').find('th').should.have.lengthOf(headerRow.length) + + tbody.should.have.lengthOf(1) + tbody.find('tr').should.have.lengthOf(tableData.length) + tbody.find('tr').first().find('td').should.have.lengthOf(3) + + tfoot.should.have.lengthOf(1) + tfoot.find('tr').should.have.lengthOf(1) + tfoot.find('tr').find('td').should.have.lengthOf(footerRow.length) + }) + }) }) diff --git a/test/specs/collections/Table/TableCell-test.js b/test/specs/collections/Table/TableCell-test.js index 88324b57be..6ca17b4968 100644 --- a/test/specs/collections/Table/TableCell-test.js +++ b/test/specs/collections/Table/TableCell-test.js @@ -22,8 +22,23 @@ describe('TableCell', () => { }) common.propKeyOnlyToClassName(TableCell, 'warning') - it('renders as a thead by default', () => { + it('renders as a td by default', () => { shallow() .should.have.tagName('td') }) + + describe('shorthand', () => { + it('renders empty cell with no shorthand', () => { + const wrapper = shallow() + + wrapper.text().should.equal('') + }) + + it('renders the cell', () => { + const content = 'Hey there' + const wrapper = shallow() + + wrapper.text().should.equal(content) + }) + }) }) diff --git a/test/specs/collections/Table/TableHeaderCell-test.js b/test/specs/collections/Table/TableHeaderCell-test.js index 1181985d54..8ce4fdaa0f 100644 --- a/test/specs/collections/Table/TableHeaderCell-test.js +++ b/test/specs/collections/Table/TableHeaderCell-test.js @@ -6,7 +6,7 @@ import TableHeaderCell from 'src/collections/Table/TableHeaderCell' describe('TableHeaderCell', () => { common.isConformant(TableHeaderCell) - it('renders as a tfoot by default', () => { + it('renders as a th by default', () => { shallow() .should.have.tagName('th') }) diff --git a/test/specs/collections/Table/TableRow-test.js b/test/specs/collections/Table/TableRow-test.js index 3d12525515..b3b41a48d7 100644 --- a/test/specs/collections/Table/TableRow-test.js +++ b/test/specs/collections/Table/TableRow-test.js @@ -17,8 +17,31 @@ describe('TableRow', () => { common.propKeyOnlyToClassName(TableRow, 'positive') common.propKeyOnlyToClassName(TableRow, 'warning') - it('renders as a thead by default', () => { + it('renders as a tr by default', () => { shallow() .should.have.tagName('tr') }) + + describe('shorthand', () => { + const items = ['Name', 'Status', 'Notes'] + + it('renders empty tr with no shorthand', () => { + const wrapper = mount() + + wrapper.find('td').should.have.lengthOf(0) + }) + + it('renders the cells', () => { + const wrapper = mount() + + wrapper.find('td').should.have.lengthOf(items.length) + }) + + it('renders the cells using itemAs', () => { + const itemAs = 'th' + const wrapper = mount() + + wrapper.find(itemAs).should.have.lengthOf(items.length) + }) + }) })