Skip to content

Commit 3ad5f88

Browse files
committed
Wrote some tests, fixed imports for node
1 parent 768fef5 commit 3ad5f88

File tree

8 files changed

+127
-11
lines changed

8 files changed

+127
-11
lines changed

Diff for: src/core/lib/Charts.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @author tlwr [[email protected]] - Original
3-
* @author Matt C [[email protected]] - Conversion to new format
2+
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
44
* @copyright Crown Copyright 2019
55
* @license Apache-2.0
66
*/

Diff for: src/core/operations/HTMLToText.mjs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
4+
* @copyright Crown Copyright 2019
5+
* @license Apache-2.0
6+
*/
7+
8+
import Operation from "../Operation";
9+
10+
/**
11+
* HTML To Text operation
12+
*/
13+
class HTMLToText extends Operation {
14+
15+
/**
16+
* HTMLToText constructor
17+
*/
18+
constructor() {
19+
super();
20+
21+
this.name = "HTML To Text";
22+
this.module = "Default";
23+
this.description = "Converts a HTML ouput from an operation to a readable string instead of being rendered in the DOM.";
24+
this.infoURL = "";
25+
this.inputType = "html";
26+
this.outputType = "string";
27+
this.args = [];
28+
}
29+
30+
/**
31+
* @param {html} input
32+
* @param {Object[]} args
33+
* @returns {string}
34+
*/
35+
run(input, args) {
36+
return input;
37+
}
38+
39+
}
40+
41+
export default HTMLToText;

Diff for: src/core/operations/HeatmapChart.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
/**
22
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
34
* @copyright Crown Copyright 2019
45
* @license Apache-2.0
56
*/
67

7-
import * as d3 from "d3";
8-
import * as nodom from "nodom";
8+
import * as d3temp from "d3";
9+
import * as nodomtemp from "nodom";
910
import { getScatterValues, RECORD_DELIMITER_OPTIONS, COLOURS, FIELD_DELIMITER_OPTIONS } from "../lib/Charts";
1011

1112

1213
import Operation from "../Operation";
1314
import OperationError from "../errors/OperationError";
1415
import Utils from "../Utils";
1516

17+
const d3 = d3temp.default ? d3temp.default : d3temp;
18+
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
19+
1620
/**
1721
* Heatmap chart operation
1822
*/

Diff for: src/core/operations/HexDensityChart.mjs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
/**
22
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
34
* @copyright Crown Copyright 2019
45
* @license Apache-2.0
56
*/
67

7-
import * as d3 from "d3";
8-
import * as d3hexbin from "d3-hexbin";
9-
import * as nodom from "nodom";
8+
import * as d3temp from "d3";
9+
import * as d3hexbintemp from "d3-hexbin";
10+
import * as nodomtemp from "nodom";
1011
import { getScatterValues, RECORD_DELIMITER_OPTIONS, COLOURS, FIELD_DELIMITER_OPTIONS } from "../lib/Charts";
1112

1213
import Operation from "../Operation";
1314
import Utils from "../Utils";
1415

16+
const d3 = d3temp.default ? d3temp.default : d3temp;
17+
const d3hexbin = d3hexbintemp.default ? d3hexbintemp.default : d3hexbintemp;
18+
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
19+
20+
1521
/**
1622
* Hex Density chart operation
1723
*/

Diff for: src/core/operations/ScatterChart.mjs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
/**
22
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
34
* @copyright Crown Copyright 2019
45
* @license Apache-2.0
56
*/
67

7-
import * as d3 from "d3";
8-
import * as nodom from "nodom";
8+
import * as d3temp from "d3";
9+
import * as nodomtemp from "nodom";
10+
911
import { getScatterValues, getScatterValuesWithColour, RECORD_DELIMITER_OPTIONS, COLOURS, FIELD_DELIMITER_OPTIONS } from "../lib/Charts";
1012

1113
import Operation from "../Operation";
1214
import Utils from "../Utils";
1315

16+
const d3 = d3temp.default ? d3temp.default : d3temp;
17+
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
18+
1419
/**
1520
* Scatter chart operation
1621
*/

Diff for: src/core/operations/SeriesChart.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/**
22
* @author tlwr [[email protected]]
3+
* @author Matt C [[email protected]]
34
* @copyright Crown Copyright 2019
45
* @license Apache-2.0
56
*/
67

7-
import * as d3 from "d3";
8-
import * as nodom from "nodom";
8+
import * as d3temp from "d3";
9+
import * as nodomtemp from "nodom";
910
import { getSeriesValues, RECORD_DELIMITER_OPTIONS, FIELD_DELIMITER_OPTIONS } from "../lib/Charts";
1011

1112
import Operation from "../Operation";
1213
import Utils from "../Utils";
1314

15+
const d3 = d3temp.default ? d3temp.default : d3temp;
16+
const nodom = nodomtemp.default ? nodomtemp.default: nodomtemp;
17+
1418
/**
1519
* Series chart operation
1620
*/

Diff for: tests/operations/index.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import "./tests/BitwiseOp";
3333
import "./tests/ByteRepr";
3434
import "./tests/CartesianProduct";
3535
import "./tests/CharEnc";
36+
import "./tests/Charts";
3637
import "./tests/Checksum";
3738
import "./tests/Ciphers";
3839
import "./tests/Code";

Diff for: tests/operations/tests/Charts.mjs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Chart tests.
3+
*
4+
* @author Matt C [[email protected]]
5+
* @copyright Crown Copyright 2019
6+
* @license Apache-2.0
7+
*/
8+
import TestRegister from "../TestRegister";
9+
10+
TestRegister.addTests([
11+
{
12+
name: "Scatter chart",
13+
input: "100 100\n200 200\n300 300\n400 400\n500 500",
14+
expectedMatch: /^<svg width/,
15+
recipeConfig: [
16+
{
17+
"op": "Scatter chart",
18+
"args": ["Line feed", "Space", false, "time", "stress", "black", 5, false]
19+
}
20+
],
21+
},
22+
{
23+
name: "Hex density chart",
24+
input: "100 100\n200 200\n300 300\n400 400\n500 500",
25+
expectedMatch: /^<svg width/,
26+
recipeConfig: [
27+
{
28+
"op": "Hex Density chart",
29+
"args": ["Line feed", "Space", 25, 15, true, "", "", true, "white", "black", true]
30+
}
31+
],
32+
},
33+
{
34+
name: "Series chart",
35+
input: "100 100 100\n200 200 200\n300 300 300\n400 400 400\n500 500 500",
36+
expectedMatch: /^<svg width/,
37+
recipeConfig: [
38+
{
39+
"op": "Series chart",
40+
"args": ["Line feed", "Space", "", 1, "mediumseagreen, dodgerblue, tomato"]
41+
}
42+
],
43+
},
44+
{
45+
name: "Heatmap chart",
46+
input: "100 100\n200 200\n300 300\n400 400\n500 500",
47+
expectedMatch: /^<svg width/,
48+
recipeConfig: [
49+
{
50+
"op": "Heatmap chart",
51+
"args": ["Line feed", "Space", 25, 25, true, "", "", false, "white", "black"]
52+
}
53+
],
54+
},
55+
]);

0 commit comments

Comments
 (0)