|
| 1 | +import { defaultOptions } from "../__mocks__/defaultOptions"; |
| 2 | +import { ft } from "../setup.spec"; |
| 3 | +import { FloatToolkit } from "../../float-toolkit.service"; |
| 4 | + |
| 5 | +describe("FloatToolkit.defaultPrecision", () => { |
| 6 | + it("should return a valid FloatToolkit.Precision value", () => { |
| 7 | + expect(ft.defaultPrecision).toBe(10); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should be assignable to a FloatToolkit.Precision value", () => { |
| 11 | + expect(() => { |
| 12 | + ft.defaultPrecision = 5; |
| 13 | + }).not.toThrowError(); |
| 14 | + |
| 15 | + expect(ft.defaultPrecision).toBe(5); |
| 16 | + }); |
| 17 | +}); |
| 18 | + |
| 19 | +describe("FloatToolkit.options", () => { |
| 20 | + it("should return a valid frozen FloatToolkit.Options object", () => { |
| 21 | + expect(ft.options).toEqual(defaultOptions); |
| 22 | + expect(Object.isFrozen(ft.options)).toBeTrue(); |
| 23 | + }); |
| 24 | +}); |
| 25 | + |
| 26 | +describe("FloatToolkit.setOptions()", () => { |
| 27 | + let prevOptions: Readonly<FloatToolkit.Options>; |
| 28 | + let returnedOptions: Readonly<FloatToolkit.Options>; |
| 29 | + |
| 30 | + beforeEach(() => { |
| 31 | + prevOptions = ft.options; |
| 32 | + |
| 33 | + returnedOptions = ft.setOptions({ |
| 34 | + forceUseDefaultPrecision: true, |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should modify the service's options", () => { |
| 39 | + expect(returnedOptions).toEqual({ ...prevOptions, forceUseDefaultPrecision: true }); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should return a valid frozen FloatToolkit.Options object", () => { |
| 43 | + expect(Object.isFrozen(returnedOptions)).toBeTrue(); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should reset the output if instructed", () => { |
| 47 | + const newOptions: FloatToolkit.Options = { |
| 48 | + forceUseDefaultPrecision: true, |
| 49 | + }; |
| 50 | + |
| 51 | + ft.add([1]); |
| 52 | + expect(ft.output).toBe(1); |
| 53 | + |
| 54 | + ft.setOptions(newOptions, true); |
| 55 | + expect(ft.output).toBe(0); |
| 56 | + expect(ft.options).toEqual({ ...returnedOptions, ...newOptions }); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
| 60 | +describe("FloatToolkit.resetOptions()", () => { |
| 61 | + let returnedOptions: Readonly<FloatToolkit.Options>; |
| 62 | + |
| 63 | + beforeEach(() => { |
| 64 | + returnedOptions = ft.resetOptions({ |
| 65 | + forceUseDefaultPrecision: true, |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should reset and modify the FloatToolkit's options", () => { |
| 70 | + expect(returnedOptions).toEqual({ ...defaultOptions, forceUseDefaultPrecision: true }); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should return a valid frozen FloatToolkit.Options object", () => { |
| 74 | + expect(Object.isFrozen(returnedOptions)).toBeTrue(); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should reset the output if instructed", () => { |
| 78 | + const newOptions: FloatToolkit.Options = { |
| 79 | + forceUseDefaultPrecision: true, |
| 80 | + }; |
| 81 | + |
| 82 | + ft.add([1]); |
| 83 | + expect(ft.output).toBe(1); |
| 84 | + |
| 85 | + ft.resetOptions(newOptions, true); |
| 86 | + expect(ft.output).toBe(0); |
| 87 | + expect(ft.options).toEqual({ ...defaultOptions, ...newOptions }); |
| 88 | + }); |
| 89 | +}); |
0 commit comments