f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/js/formulas/info/ISNATest.ts
-rw-r--r--
2856
 1import { assert } from "chai";
 2import { it, describe } from "../../testutils/TestUtils";
 3import { stub } from "sinon";
 4import { DivException } from "../../../../main/js/errors/DivException";
 5import { F7Exception } from "../../../../main/js/errors/F7Exception";
 6import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
 7import { NAException } from "../../../../main/js/errors/NAException";
 8import { RefException } from "../../../../main/js/errors/RefException";
 9import { ISNA } from "../../../../main/js/formulas/info/ISNA";
10import { Grid } from "../../../../main/js/models/common/Grid";
11import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
12import { CommonModels } from "../../testutils/CommonModels";
13
14describe("ISNA", function () {
15  it("should work with numbers", function () {
16    assert.deepEqual(ISNA.SELF.run(null, 10), false);
17  });
18
19  it("should work with strings", function () {
20    assert.deepEqual(ISNA.SELF.run(null, "String"), false);
21  });
22
23  it("should work with booleans", function () {
24    assert.deepEqual(ISNA.SELF.run(null, true), false);
25    assert.deepEqual(ISNA.SELF.run(null, false), false);
26  });
27
28  it("should work with errors", function () {
29    assert.deepEqual(ISNA.SELF.run(null, new NAException()), true);
30    assert.deepEqual(ISNA.SELF.run(null, new DivException()), false);
31    assert.deepEqual(ISNA.SELF.run(null, new RefException()), false);
32  });
33
34  it("should work with blank/null/empty", function () {
35    assert.deepEqual(ISNA.SELF.run(null, null), false);
36  });
37
38  it("should work with lookup", function () {
39    const lookup = stub();
40    const collateralLookup = stub();
41    const F = new ISNA(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
42    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(new NAException());
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(ISNA.SELF.run(null, Grid.builder().add(0, 0, "Nope").build()), false);
51    assert.deepEqual(ISNA.SELF.run(null, Grid.builder().add(0, 0, 22000.0).build()), false);
52    assert.deepEqual(ISNA.SELF.run(null, Grid.builder().add(0, 0, true).build()), false);
53    assert.deepEqual(
54      ISNA.SELF.run(null, Grid.builder().add(0, 0, new NAException()).build()),
55      true
56    );
57  });
58
59  it("should return error when arguments are not of the correct length", function () {
60    assert.deepEqual((ISNA.SELF.run(null) as F7Exception).name, F7ExceptionName.NA);
61    assert.deepEqual((ISNA.SELF.run(null, "A", "B") as F7Exception).name, F7ExceptionName.NA);
62  });
63});