name:
src/test/js/formulas/info/ISNONTEXTTest.ts
-rw-r--r--
2925
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 { ISNONTEXT } from "../../../../main/js/formulas/info/ISNONTEXT";
10import { Grid } from "../../../../main/js/models/common/Grid";
11import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
12import { CommonModels } from "../../testutils/CommonModels";
13
14describe("ISNONTEXT", function () {
15 it("should work with numbers", function () {
16 assert.deepEqual(ISNONTEXT.SELF.run(null, 10), true);
17 });
18
19 it("should work with strings", function () {
20 assert.deepEqual(ISNONTEXT.SELF.run(null, "String"), false);
21 });
22
23 it("should work with booleans", function () {
24 assert.deepEqual(ISNONTEXT.SELF.run(null, true), true);
25 assert.deepEqual(ISNONTEXT.SELF.run(null, false), true);
26 });
27
28 it("should work with errors", function () {
29 assert.deepEqual(ISNONTEXT.SELF.run(null, new NAException()), true);
30 assert.deepEqual(ISNONTEXT.SELF.run(null, new DivException()), true);
31 assert.deepEqual(ISNONTEXT.SELF.run(null, new RefException()), true);
32 });
33
34 it("should work with blank/null/empty", function () {
35 assert.deepEqual(ISNONTEXT.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 ISNONTEXT(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
42 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(false);
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(ISNONTEXT.SELF.run(null, Grid.builder().add(0, 0, "Nope").build()), false);
51 assert.deepEqual(ISNONTEXT.SELF.run(null, Grid.builder().add(0, 0, 22000).build()), true);
52 assert.deepEqual(ISNONTEXT.SELF.run(null, Grid.builder().add(0, 0, true).build()), true);
53 assert.deepEqual(
54 ISNONTEXT.SELF.run(null, Grid.builder().add(0, 0, new DivException()).build()),
55 true
56 );
57 });
58
59 it("should return error when arguments are not of the correct length", function () {
60 assert.deepEqual((ISNONTEXT.SELF.run(null) as F7Exception).name, F7ExceptionName.NA);
61 assert.deepEqual((ISNONTEXT.SELF.run(null, "A", "B") as F7Exception).name, F7ExceptionName.NA);
62 });
63});