-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for utils and fix scss imports'
fix imports and add comments add unit tests for cell
- Loading branch information
Showing
8 changed files
with
132 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nts/virtualized-grid/VirtualizedGrid.scss → ...src/components/virtualized-grid/Grid.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
frontend/packages/console-shared/src/components/virtualized-grid/__tests__/Cell.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Cell from '../Cell'; | ||
import { RenderHeader, RenderCell } from '../types'; | ||
import { GridCellProps, CellMeasurer, CellMeasurerCache } from 'react-virtualized'; | ||
import { IDEAL_SPACE_BW_TILES } from '../const'; | ||
|
||
describe('Grid-cell', () => { | ||
let data: GridCellProps; | ||
let renderHeader: RenderHeader; | ||
let renderCell: RenderCell; | ||
let cache: CellMeasurerCache; | ||
|
||
beforeEach(() => { | ||
data = { | ||
key: 'unique-key', | ||
columnIndex: 0, | ||
rowIndex: 0, | ||
style: { | ||
height: 50, | ||
width: 50, | ||
top: 60, | ||
left: 60, | ||
position: 'absolute', | ||
}, | ||
isScrolling: false, | ||
isVisible: false, | ||
parent: null, | ||
}; | ||
renderHeader = jest.fn(); | ||
renderCell = jest.fn(); | ||
cache = {} as CellMeasurerCache; | ||
}); | ||
|
||
it('should return null when item is null', () => { | ||
const wrapper = shallow( | ||
<Cell data={data} renderCell={renderCell} cache={cache} columnCount={1} items={[null]} />, | ||
); | ||
expect(wrapper.isEmptyRender()).toBeTruthy(); | ||
}); | ||
|
||
it('should render cellMeasurer when item is not null', () => { | ||
const wrapper = shallow( | ||
<Cell data={data} renderCell={renderCell} cache={cache} columnCount={1} items={[{}]} />, | ||
); | ||
expect(wrapper.find(CellMeasurer)).toHaveLength(1); | ||
}); | ||
|
||
it('should render header and not the cell when item is string and height should not be changed', () => { | ||
const wrapper = shallow( | ||
<Cell | ||
data={data} | ||
renderCell={renderCell} | ||
cache={cache} | ||
columnCount={1} | ||
items={['string']} | ||
renderHeader={renderHeader} | ||
/>, | ||
); | ||
expect(wrapper.find('div').prop('style').height).toBe(50); | ||
expect(renderHeader).toHaveBeenCalledWith('string'); | ||
expect(renderCell).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render Cell and not the Header when item is neither string nor null and height should be changed', () => { | ||
const wrapper = shallow( | ||
<Cell | ||
data={data} | ||
renderCell={renderCell} | ||
cache={cache} | ||
columnCount={1} | ||
items={['string']} | ||
renderHeader={renderHeader} | ||
/>, | ||
); | ||
expect(wrapper.find('div').prop('style').height).toBe(50); | ||
expect(renderHeader).toHaveBeenCalledWith('string'); | ||
expect(renderCell).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render Cell and not the Header when item is neither string nor null and height should be changed', () => { | ||
const item = { id: 1 }; | ||
const wrapper = shallow( | ||
<Cell data={data} renderCell={renderCell} cache={cache} columnCount={1} items={[item]} />, | ||
); | ||
expect(wrapper.find('div').prop('style').height).toBe(50 - IDEAL_SPACE_BW_TILES); | ||
expect(renderCell).toHaveBeenCalledWith(item); | ||
expect(renderHeader).not.toHaveBeenCalled(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
frontend/packages/console-shared/src/components/virtualized-grid/__tests__/utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getItemsAndRowCount } from '../utils'; | ||
|
||
describe('virtualized-grid-utils', () => { | ||
it('should return row count, itemCount, headerRows based on itemcount and column count', () => { | ||
const data = { | ||
header1: [{}, {}, {}, {}, {}], | ||
}; | ||
const result1 = getItemsAndRowCount(data, 3); | ||
expect(result1.rowCount).toEqual(3); | ||
expect(result1.items).toEqual(['header1', null, null, {}, {}, {}, {}, {}, null]); | ||
expect(result1.headerRows).toEqual([0]); | ||
|
||
const data2 = { | ||
header1: [{}], | ||
header2: [{}, {}], | ||
}; | ||
const result2 = getItemsAndRowCount(data2, 2); | ||
expect(result2.rowCount).toEqual(4); | ||
expect(result2.items).toEqual(['header1', null, {}, null, 'header2', null, {}, {}]); | ||
expect(result2.headerRows).toEqual([0, 2]); | ||
|
||
const data3 = { | ||
header1: [], | ||
header2: [{}], | ||
}; | ||
|
||
const result3 = getItemsAndRowCount(data3, 1); | ||
expect(result3.rowCount).toEqual(3); | ||
expect(result3.items).toEqual(['header1', 'header2', {}]); | ||
expect(result3.headerRows).toEqual([0, 1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters