name:
src/test/js/formulas/info/ISBLANKTest.ts
-rw-r--r--
2663
1import { assert } from "chai";
2import { it, describe } from "../../testutils/TestUtils";
3import { stub } from "sinon";
4import { F7Exception } from "../../../../main/js/errors/F7Exception";
5import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
6import { NAException } from "../../../../main/js/errors/NAException";
7import { ISBLANK } from "../../../../main/js/formulas/info/ISBLANK";
8import { Grid } from "../../../../main/js/models/common/Grid";
9import {
10 CollateralLookupFunction,
11 Computed,
12 LookupFunction,
13} from "../../../../main/js/models/common/Types";
14import { CommonModels } from "../../testutils/CommonModels";
15
16describe("ISBLANK", function () {
17 it("should work with numbers", function () {
18 assert.deepEqual(ISBLANK.SELF.run(null, 10), false);
19 });
20
21 it("should work with strings", function () {
22 assert.deepEqual(ISBLANK.SELF.run(null, "String"), false);
23 });
24
25 it("should work with booleans", function () {
26 assert.deepEqual(ISBLANK.SELF.run(null, true), false);
27 assert.deepEqual(ISBLANK.SELF.run(null, false), false);
28 });
29
30 it("should work with errors", function () {
31 assert.deepEqual(ISBLANK.SELF.run(null, new NAException()), false);
32 });
33
34 it("should work with blank/null/empty", function () {
35 assert.deepEqual(ISBLANK.SELF.run(null, null), true);
36 });
37
38 it("should work with lookup", function () {
39 const lookup = stub();
40 const collateralLookup = stub();
41 const F = new ISBLANK(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
42 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(null);
43 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), true);
44 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
45 assert.equal(collateralLookup.callCount, 1);
46 assert.isTrue(lookup.notCalled);
47 });
48
49 it("should work with grid", function () {
50 assert.deepEqual(ISBLANK.SELF.run(null, Grid.from<Computed>([["Yes"]])), false);
51 assert.deepEqual(ISBLANK.SELF.run(null, Grid.from<Computed>([[22000]])), false);
52 assert.deepEqual(ISBLANK.SELF.run(null, Grid.from<Computed>([[true]])), false);
53 assert.deepEqual(ISBLANK.SELF.run(null, Grid.from<Computed>([["Nope"], [false]])), false);
54 assert.deepEqual(ISBLANK.SELF.run(null, Grid.from<Computed>([[new NAException()]])), false);
55 });
56
57 it("should return error when arguments are not of the correct length", function () {
58 assert.deepEqual((ISBLANK.SELF.run(null) as F7Exception).name, F7ExceptionName.NA);
59 assert.deepEqual((ISBLANK.SELF.run(null, "A", "B") as F7Exception).name, F7ExceptionName.NA);
60 });
61});