Skip to content

Commit

Permalink
Minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjbauer committed Dec 5, 2018
1 parent 64bc6da commit 7aaeb7f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 166 deletions.
30 changes: 13 additions & 17 deletions frontend/src/pages/Compare.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Compare', () => {
* After calling this function, the global 'tree' will be a Compare instance with a table viewer
* and a tensorboard viewer.
*/
async function setUpViewers(): Promise<void> {
async function setUpViewersAndShallowMount(): Promise<void> {

// Simulate returning a tensorboard and table viewer
outputArtifactLoaderSpy.mockImplementation(() => [
Expand All @@ -106,12 +106,14 @@ describe('Compare', () => {
}
}
};
const run = newMockRun('run-with-workflow');
run.pipeline_runtime!.workflow_manifest = JSON.stringify(workflow);
runs.push(run);
const run1 = newMockRun('run-with-workflow-1');
run1.pipeline_runtime!.workflow_manifest = JSON.stringify(workflow);
const run2 = newMockRun('run-with-workflow-2');
run2.pipeline_runtime!.workflow_manifest = JSON.stringify(workflow);
runs.push(run1, run2);

const props = generateProps();
props.location.search = `?${QUERY_PARAMS.runlist}=run-with-workflow`;
props.location.search = `?${QUERY_PARAMS.runlist}=run-with-workflow-1,run-with-workflow-2`;

tree = shallow(<TestCompare {...props} />);
await TestUtils.flushPromises();
Expand Down Expand Up @@ -151,15 +153,8 @@ describe('Compare', () => {
tree = shallow(<Compare {...props} />);
await TestUtils.flushPromises();

expect(tree).toMatchSnapshot();
});

it('renders a page with no runs', async () => {
const props = generateProps();
// Ensure there are no run IDs in the query
props.location.search = '';
tree = shallow(<Compare {...props} />);
await TestUtils.flushPromises();
expect(updateBannerSpy).toHaveBeenCalledTimes(1);
expect(updateBannerSpy).toHaveBeenLastCalledWith({});

expect(tree).toMatchSnapshot();
});
Expand All @@ -181,6 +176,7 @@ describe('Compare', () => {
props.location.search = `?${QUERY_PARAMS.runlist}=run-1,run-2,run-3`;

tree = shallow(<Compare {...props} />);
await TestUtils.flushPromises();

expect(getRunSpy).toHaveBeenCalledTimes(3);
expect(getRunSpy).toHaveBeenCalledWith('run-1');
Expand Down Expand Up @@ -355,7 +351,7 @@ describe('Compare', () => {
});

it('collapses all sections', async () => {
await setUpViewers();
await setUpViewersAndShallowMount();
const instance = tree.instance() as Compare;
const collapseBtn =
instance.getInitialToolbarState().actions.find(b => b.title === 'Collapse all');
Expand All @@ -375,7 +371,7 @@ describe('Compare', () => {
});

it('expands all sections if they were collapsed', async () => {
await setUpViewers();
await setUpViewersAndShallowMount();
const instance = tree.instance() as Compare;
const collapseBtn =
instance.getInitialToolbarState().actions.find(b => b.title === 'Collapse all');
Expand Down Expand Up @@ -447,7 +443,7 @@ describe('Compare', () => {
});

it('does not show viewers for deselected runs', async () => {
await setUpViewers();
await setUpViewersAndShallowMount();

// We call _selectionChanged() rather than using setState because _selectionChanged has a
// callback which is needed to properly update the run parameters section
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/pages/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ class Compare extends Page<{}, CompareState> {
return;
}

this.setStateSafe({
runs,
selectedIds: runs.map(r => r.run!.id!),
workflowObjects,
}, () => this._loadParameters());

const outputPathsList = workflowObjects.map(
workflow => WorkflowParser.loadAllOutputPaths(workflow));

Expand All @@ -234,13 +240,8 @@ class Compare extends Page<{}, CompareState> {
}
}));


this.setStateSafe({
runs,
selectedIds: runs.map(r => r.run!.id!),
viewersMap,
workflowObjects,
}, () => this._loadParameters());
// For each output artifact type, list all artifact instances in all runs
this.setStateSafe({ viewersMap });
}

protected _selectionChanged(selectedIds: string[]): void {
Expand Down
201 changes: 59 additions & 142 deletions frontend/src/pages/__snapshots__/Compare.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ exports[`Compare does not show viewers for deselected runs 1`] = `
location={
Object {
"pathname": "/compare",
"search": "?runlist=run-with-workflow",
"search": "?runlist=run-with-workflow-1,run-with-workflow-2",
}
}
match={
Expand All @@ -923,7 +923,8 @@ exports[`Compare does not show viewers for deselected runs 1`] = `
onSelectionChange={[Function]}
runIdListMask={
Array [
"run-with-workflow",
"run-with-workflow-1",
"run-with-workflow-2",
]
}
selectedIds={Array []}
Expand Down Expand Up @@ -1085,7 +1086,7 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
location={
Object {
"pathname": "/compare",
"search": "?runlist=run-with-workflow",
"search": "?runlist=run-with-workflow-1,run-with-workflow-2",
}
}
match={
Expand All @@ -1097,12 +1098,14 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
onSelectionChange={[Function]}
runIdListMask={
Array [
"run-with-workflow",
"run-with-workflow-1",
"run-with-workflow-2",
]
}
selectedIds={
Array [
"run-with-workflow",
"run-with-workflow-1",
"run-with-workflow-2",
]
}
toolbarProps={
Expand Down Expand Up @@ -1196,7 +1199,8 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
rows={Array []}
xLabels={
Array [
"test run run-with-workflow",
"test run run-with-workflow-1",
"test run run-with-workflow-2",
]
}
yLabels={Array []}
Expand All @@ -1217,6 +1221,22 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
<div
className="flex outputsRow"
>
<PlotCard
configs={
Array [
Object {
"type": "tensorboard",
"url": "gs://path",
},
Object {
"type": "tensorboard",
"url": "gs://path",
},
]
}
maxDimension={400}
title="Aggregated view"
/>
<PlotCard
configs={
Array [
Expand All @@ -1228,7 +1248,20 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
}
key="0"
maxDimension={400}
title="test run run-with-workflow"
title="test run run-with-workflow-1"
/>
<PlotCard
configs={
Array [
Object {
"type": "tensorboard",
"url": "gs://path",
},
]
}
key="1"
maxDimension={400}
title="test run run-with-workflow-2"
/>
<Component />
</div>
Expand Down Expand Up @@ -1264,7 +1297,25 @@ exports[`Compare expands all sections if they were collapsed 1`] = `
}
key="0"
maxDimension={400}
title="test run run-with-workflow"
title="test run run-with-workflow-1"
/>
<PlotCard
configs={
Array [
Object {
"data": Array [
Array [],
],
"labels": Array [
"col1, col2",
],
"type": "table",
},
]
}
key="1"
maxDimension={400}
title="test run run-with-workflow-2"
/>
<Component />
</div>
Expand Down Expand Up @@ -1561,137 +1612,3 @@ exports[`Compare renders a page with no runs 1`] = `
/>
</div>
`;

exports[`Compare renders a page with no runs 2`] = `
<div
className="page"
>
<CollapseButton
collapseSections={Object {}}
compareSetState={[Function]}
sectionName="Run overview"
/>
<div
className="noShrink"
>
<RunList
disablePaging={true}
history={
Object {
"push": [MockFunction],
}
}
location={
Object {
"pathname": "/compare",
"search": "",
}
}
match={
Object {
"params": Object {},
}
}
onError={[Function]}
onSelectionChange={[Function]}
runIdListMask={Array []}
selectedIds={Array []}
toolbarProps={
Object {
"actions": Array [
Object {
"action": [Function],
"icon": [Function],
"id": "expandBtn",
"title": "Expand all",
"tooltip": "Expand all sections",
},
Object {
"action": [Function],
"icon": [Function],
"id": "collapseBtn",
"title": "Collapse all",
"tooltip": "Collapse all sections",
},
],
"breadcrumbs": Array [
Object {
"displayName": "Experiments",
"href": "/experiments",
},
],
"pageTitle": "Compare runs",
}
}
updateBanner={
[MockFunction] {
"calls": Array [
Array [
Object {},
],
],
}
}
updateDialog={[MockFunction]}
updateSnackbar={[MockFunction]}
updateToolbar={
[MockFunction] {
"calls": Array [
Array [
Object {
"actions": Array [
Object {
"action": [Function],
"icon": [Function],
"id": "expandBtn",
"title": "Expand all",
"tooltip": "Expand all sections",
},
Object {
"action": [Function],
"icon": [Function],
"id": "collapseBtn",
"title": "Collapse all",
"tooltip": "Collapse all sections",
},
],
"breadcrumbs": Array [
Object {
"displayName": "Experiments",
"href": "/experiments",
},
],
"pageTitle": "Compare runs",
},
],
],
}
}
/>
</div>
<Component
orientation="vertical"
/>
<CollapseButton
collapseSections={Object {}}
compareSetState={[Function]}
sectionName="Parameters"
/>
<div
className="noShrink outputsRow"
>
<Component
orientation="vertical"
/>
<CompareTable
rows={Array []}
xLabels={Array []}
yLabels={Array []}
/>
<Component />
</div>
<Component
orientation="vertical"
/>
</div>
`;

0 comments on commit 7aaeb7f

Please sign in to comment.