Skip to content

Commit

Permalink
fix(table): allow dynamic values to be visible
Browse files Browse the repository at this point in the history
Closes DCOS-39066
  • Loading branch information
Daniel Schmidt committed Jul 10, 2018
1 parent 6c9b2c6 commit 2260bb2
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/table/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class Table<T> extends React.PureComponent<ITableProps, {}> {
public render() {
return (
<AutoSizer
__dataThatTriggersARerenderWhenChanged={this.props.data} // passed to notify react-virtualized about updates
defaultWidth={DEFAULT_WIDTH}
defaultHeight={DEFAULT_HEIGHT}
onResize={this.updateGridSize}
Expand Down
17 changes: 16 additions & 1 deletion packages/table/tests/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { Table, Column } from "../";
import * as emotion from "emotion";
import { createSerializer } from "jest-emotion";
import { render, shallow } from "enzyme";
import { render, shallow, mount } from "enzyme";
import toJson from "enzyme-to-json";

expect.addSnapshotSerializer(createSerializer(emotion));
Expand Down Expand Up @@ -59,6 +59,21 @@ describe("Table", () => {
expect(toJson(component)).toMatchSnapshot();
});

it("renders again with new data", () => {
const itemRenderer = item => <span>{item}</span>;
const component = mount(
<Table data={[1, 2, 3]}>
<Column header="item" cellRenderer={itemRenderer} width={width} />
</Table>
);
expect(toJson(component)).toMatchSnapshot();

component.setProps({
data: [4, 5, 6]
});
expect(toJson(component)).toMatchSnapshot();
});

describe("getData", () => {
it("will return the right array", () => {
const width = () => 10;
Expand Down
130 changes: 130 additions & 0 deletions packages/table/tests/__snapshots__/Table.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,135 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Table renders again with new data 1`] = `
<Table
data={
Array [
1,
2,
3,
]
}
>
<AutoSizer
__dataThatTriggersARerenderWhenChanged={
Array [
1,
2,
3,
]
}
defaultHeight={768}
defaultWidth={1024}
disableHeight={false}
disableWidth={false}
onResize={[Function]}
style={Object {}}
>
<div
style={
Object {
"height": 0,
"overflow": "visible",
"width": 0,
}
}
>
<MultiGrid
cellRenderer={[Function]}
classNameBottomLeftGrid=""
classNameBottomRightGrid=""
classNameTopLeftGrid=""
classNameTopRightGrid=""
columnCount={1}
columnWidth={[Function]}
enableFixedColumnScroll={true}
enableFixedRowScroll={true}
fixedColumnCount={1}
fixedRowCount={1}
height={0}
hideBottomLeftGridScrollbar={true}
hideTopRightGridScrollbar={true}
rowCount={4}
rowHeight={35}
scrollToColumn={-1}
scrollToRow={-1}
style={Object {}}
styleBottomLeftGrid={Object {}}
styleBottomRightGrid={Object {}}
styleTopLeftGrid={Object {}}
styleTopRightGrid={Object {}}
width={0}
/>
</div>
</AutoSizer>
</Table>
`;

exports[`Table renders again with new data 2`] = `
<Table
data={
Array [
4,
5,
6,
]
}
>
<AutoSizer
__dataThatTriggersARerenderWhenChanged={
Array [
4,
5,
6,
]
}
defaultHeight={768}
defaultWidth={1024}
disableHeight={false}
disableWidth={false}
onResize={[Function]}
style={Object {}}
>
<div
style={
Object {
"height": 0,
"overflow": "visible",
"width": 0,
}
}
>
<MultiGrid
cellRenderer={[Function]}
classNameBottomLeftGrid=""
classNameBottomRightGrid=""
classNameTopLeftGrid=""
classNameTopRightGrid=""
columnCount={1}
columnWidth={[Function]}
enableFixedColumnScroll={true}
enableFixedRowScroll={true}
fixedColumnCount={1}
fixedRowCount={1}
height={0}
hideBottomLeftGridScrollbar={true}
hideTopRightGridScrollbar={true}
rowCount={4}
rowHeight={35}
scrollToColumn={-1}
scrollToRow={-1}
style={Object {}}
styleBottomLeftGrid={Object {}}
styleBottomRightGrid={Object {}}
styleTopLeftGrid={Object {}}
styleTopRightGrid={Object {}}
width={0}
/>
</div>
</AutoSizer>
</Table>
`;

exports[`Table renders default 1`] = `
.emotion-0 {
box-sizing: border-box;
Expand Down

0 comments on commit 2260bb2

Please sign in to comment.