-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMyCustomPlugin.spec.js
85 lines (61 loc) · 3.42 KB
/
MyCustomPlugin.spec.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { HyperFormula } from 'hyperformula';
import { MyCustomPlugin, MyCustomPluginTranslations } from './MyCustomPlugin';
describe('GREET function', () => {
it('works for a non-empty string', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([['Anthony', '=GREET(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 })).toEqual('👋 Hello, Anthony!');
});
it('propagates #DIV/0! error', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([['=1/0', '=GREET(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR');
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#DIV/0!');
});
it('propagates #CYCLE! error', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([['=B1', '=GREET(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR');
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#CYCLE!');
});
});
describe('DOUBLE_RANGE function', () => {
it('works for a single number', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([[42, '=DOUBLE_RANGE(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 })).toEqual(84);
});
it('works for a range of numbers', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([
[1, '=DOUBLE_RANGE(A1:A3)'],
[2],
[3],
], { licenseKey: 'gpl-v3' });
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 })).toEqual(2);
expect(engine.getCellValue({ sheet: 0, row: 1, col: 1 })).toEqual(4);
expect(engine.getCellValue({ sheet: 0, row: 2, col: 1 })).toEqual(6);
});
it('returns a VALUE error if the range argument contains a string', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([
[1, '=DOUBLE_RANGE(A1:A3)'],
['I should not be here'],
[3],
], { licenseKey: 'gpl-v3' });
expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR');
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#VALUE!');
});
it('propagates #DIV/0! error', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([['=1/0', '=DOUBLE_RANGE(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR');
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#DIV/0!');
});
it('propagates #CYCLE! error', () => {
HyperFormula.registerFunctionPlugin(MyCustomPlugin, MyCustomPluginTranslations);
const engine = HyperFormula.buildFromArray([['=B1', '=DOUBLE_RANGE(A1)']], { licenseKey: 'gpl-v3' });
expect(engine.getCellValueType({ sheet: 0, row: 0, col: 1 })).toEqual('ERROR');
expect(engine.getCellValue({ sheet: 0, row: 0, col: 1 }).value).toEqual('#CYCLE!');
});
});