Skip to content

Commit

Permalink
test: Restructure definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-s-snyder committed Apr 24, 2024
1 parent c59ad59 commit 54d75a5
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 67 deletions.
37 changes: 19 additions & 18 deletions test/browser/d3/bar-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ import { select } from '../../../node_modules/d3-selection/src/index.js';
import { createBarChart } from '../../../examples/annotated-visualizations/d3/annotated-bar-chart.js';
import { testChartMetadata } from '../../util/test-functions.js';

describe('D3 Bar Chart', function() {
const groundMetadatas = {
xAxis: {
domain: [null, null],
ordinal: ['United States', 'Russia', 'France', 'Germany (FRG)', 'Israel',
'United Kingdom', 'Netherlands', 'China', 'Spain', 'Italy'],
tickValues: ['United States', 'Russia', 'France', 'Germany (FRG)', 'Israel',
'United Kingdom', 'Netherlands', 'China', 'Spain', 'Italy']
},
yAxis: {
domain: [0, 13000],
ordinal: [],
tickValues: [0, 1000, 2000, 3000, 4000, 5000, 6000,
7000, 8000, 9000, 10000, 11000, 12000, 13000]
}
};

export function testBarChart() {
const divi = { };
let root;

Expand All @@ -12,28 +28,13 @@ describe('D3 Bar Chart', function() {
root = select('#root').append('div');
root.node().appendChild(chart);

divi.groundMetadatas = [{
chart,
xAxis: {
domain: [null, null],
ordinal: ['United States', 'Russia', 'France', 'Germany (FRG)', 'Israel',
'United Kingdom', 'Netherlands', 'China', 'Spain', 'Italy'],
tickValues: ['United States', 'Russia', 'France', 'Germany (FRG)', 'Israel',
'United Kingdom', 'Netherlands', 'China', 'Spain', 'Italy']
},
yAxis: {
domain: [0, 13000],
ordinal: [],
tickValues: [0, 1000, 2000, 3000, 4000, 5000, 6000,
7000, 8000, 9000, 10000, 11000, 12000, 13000]
}
}];
divi.metadatas = await hydrate(chart);
divi.groundMetadatas = [{ ...groundMetadatas, chart }];
});

describe('Chart Metadata', function() { testChartMetadata(divi); });

after(function() {
root.remove();
});
});
}
31 changes: 16 additions & 15 deletions test/browser/d3/scatter-plot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ import { select } from '../../../node_modules/d3-selection/src/index.js';
import { createScatterPlot } from '../../../examples/annotated-visualizations/d3/annotated-scatter-plot.js';
import { testChartMetadata } from '../../util/test-functions.js';

describe('D3 Scatter Plot', function() {
const groundMetadatas = {
xAxis: {
domain: [4, 8],
ordinal: [],
tickValues: [4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8]
},
yAxis: {
domain: [0, 10],
ordinal: [],
tickValues: [0, 2, 4, 6, 8, 10]
}
};

export function testScatterPlot() {
const divi = { };
let root;

Expand All @@ -12,25 +25,13 @@ describe('D3 Scatter Plot', function() {
root = select('#root').append('div');
root.node().appendChild(chart);

divi.groundMetadatas = [{
chart,
xAxis: {
domain: [4, 8],
ordinal: [],
tickValues: [4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8]
},
yAxis: {
domain: [0, 10],
ordinal: [],
tickValues: [0, 2, 4, 6, 8, 10]
}
}];
divi.metadatas = await hydrate(chart);
divi.groundMetadatas = [{ ...groundMetadatas, chart }];
});

describe('Chart Metadata', function() { testChartMetadata(divi); });

after(function() {
root.remove();
});
});
}
7 changes: 7 additions & 0 deletions test/browser/d3/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { testBarChart } from './bar-chart-test.js';
import { testScatterPlot } from './scatter-plot-test.js';

describe('D3', function() {
describe('Bar chart', testBarChart);
describe('Scatter plot', testScatterPlot);
});
31 changes: 16 additions & 15 deletions test/browser/ggplot2/line-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ import { select } from '../../../node_modules/d3-selection/src/index.js';
import { createLineChart } from '../../../examples/annotated-visualizations/ggplot2/annotated-line-chart.js';
import { testChartMetadata } from '../../util/test-functions.js';

describe('ggplot2 Line Chart', function() {
const groundMetadatas = {
xAxis: {
domain: [new Date(0, 0, 1), new Date(0, 3, 1)],
ordinal: [],
tickValues: [new Date(0, 0, 1), new Date(0, 3, 1)]
},
yAxis: {
domain: [-30, 20],
ordinal: [],
tickValues: [-30, -20, -10, 0, 10, 20]
}
};

export function testLineChart() {
const divi = { };
let root;

Expand All @@ -12,25 +25,13 @@ describe('ggplot2 Line Chart', function() {
root = select('#root').append('div');
root.node().appendChild(chart);

divi.groundMetadatas = [{
chart,
xAxis: {
domain: [new Date(0, 0, 1), new Date(0, 3, 1)],
ordinal: [],
tickValues: [new Date(0, 0, 1), new Date(0, 3, 1)]
},
yAxis: {
domain: [-30, 20],
ordinal: [],
tickValues: [-30, -20, -10, 0, 10, 20]
}
}];
divi.metadatas = await hydrate(chart);
divi.groundMetadatas = [{ ...groundMetadatas, chart }];
});

describe('Chart Metadata', function() { testChartMetadata(divi); });

after(function() {
root.remove();
});
});
}
5 changes: 5 additions & 0 deletions test/browser/ggplot2/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testLineChart } from './line-chart-test.js';

describe('ggplot2', function() {
describe('Line chart', testLineChart);
});
7 changes: 3 additions & 4 deletions test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
</script>

<!-- D3 chart tests -->
<script type="module" src="/test/browser/d3/bar-chart-test.js"></script>
<script type="module" src="/test/browser/d3/scatter-plot-test.js"></script>
<script type="module" src="/test/browser/d3/tests.js"></script>

<!-- Observable Plot chart tests -->
<script type="module" src="/test/browser/observable-plot/scatter-plot-test.js"></script>
<script type="module" src="/test/browser/observable-plot/tests.js"></script>

<!-- Vega-Lite chart tests -->

<!-- ggplot2 chart tests -->
<script type="module" src="/test/browser/ggplot2/line-chart-test.js"></script>
<script type="module" src="/test/browser/ggplot2/tests.js"></script>

<script type="module" class="mocha-exec">
mocha.run();
Expand Down
31 changes: 16 additions & 15 deletions test/browser/observable-plot/scatter-plot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ import { select } from '../../../node_modules/d3-selection/src/index.js';
import { createScatterPlot } from '../../../examples/annotated-visualizations/observable-plot/annotated-scatter-plot.js';
import { testChartMetadata } from '../../util/test-functions.js';

describe('Observable Plot Scatter Plot', function() {
const groundMetadatas = {
xAxis: {
domain: [180, 230],
ordinal: [],
tickValues: [180, 190, 200, 210, 220, 230]
},
yAxis: {
domain: [3000, 6000],
ordinal: [],
tickValues: [3000, 3500, 4000, 4500, 5000, 5500, 6000]
}
};

export function testScatterPlot() {
const divi = { };
let root;

Expand All @@ -12,25 +25,13 @@ describe('Observable Plot Scatter Plot', function() {
root = select('#root').append('div');
root.node().appendChild(chart);

divi.groundMetadatas = [{
chart,
xAxis: {
domain: [180, 230],
ordinal: [],
tickValues: [180, 190, 200, 210, 220, 230]
},
yAxis: {
domain: [3000, 6000],
ordinal: [],
tickValues: [3000, 3500, 4000, 4500, 5000, 5500, 6000]
}
}];
divi.metadatas = await hydrate(chart);
divi.groundMetadatas = [{ ...groundMetadatas, chart }];
});

describe('Chart Metadata', function() { testChartMetadata(divi); });

after(function() {
root.remove();
});
});
}
5 changes: 5 additions & 0 deletions test/browser/observable-plot/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { testScatterPlot } from './scatter-plot-test.js';

describe('Observable Plot', function() {
describe('Scatter plot', testScatterPlot);
});

0 comments on commit 54d75a5

Please sign in to comment.