forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique_v0.test.ts
71 lines (64 loc) · 1.83 KB
/
unique_v0.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { describe, it, expect, beforeEach } from 'vitest';
import UniqueNode, { unique_node_data } from '$lib/compute/unique_v0';
import deepCopy from 'deep-copy';
describe('UniqueNode class', () => {
let node;
let inputData;
beforeEach(() => {
node = new UniqueNode(deepCopy(unique_node_data));
inputData = {
input: [
{ key: 'value1' },
{ key: 'value1' },
{ key: 'value2' },
{ key: 'value3' },
{ key: 'value3' }
]
};
node.data.text = 'key';
});
it('should return unique values based on the specified property', async () => {
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual(['value1', 'value2', 'value3']);
});
it('should return an empty array if input is empty', async () => {
inputData.input = [];
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toEqual([]);
});
it('should return undefined if no property is specified', async () => {
node.data.text = '';
const output = await node.compute(
inputData,
'run',
console.log,
console.error,
console.log,
'test_slug'
);
expect(output).toBeUndefined();
});
it('should set dirty to false after compute', async () => {
await node.compute(inputData, 'run', console.log, console.error, console.log, 'test_slug');
expect(node.data.dirty).toBe(false);
});
it('should not mutate the input data', async () => {
const originalInputData = deepCopy(inputData);
await node.compute(inputData, 'run', console.log, console.error, console.log, 'test_slug');
expect(inputData).toEqual(originalInputData);
});
});