Skip to content

Commit 7bf0005

Browse files
committed
Package code and tests
1 parent 92159aa commit 7bf0005

26 files changed

+315
-78
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969

7070
overrides: [
7171
{
72-
files: ["./.eslintrc.js", "./karma.conf.js", "./src/**/*.ts"],
72+
files: ["./.eslintrc.js", "./karma.conf.js", "./src/**/*.ts", "./scripts/**/*.mjs"],
7373

7474
env: {
7575
es6: true,
@@ -173,7 +173,7 @@ module.exports = {
173173
},
174174

175175
{
176-
files: ["./.eslintrc.js", "./karma.conf.js"],
176+
files: ["*.js", "./scripts/**/*.mjs"],
177177

178178
env: {
179179
es6: true,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![NPM latest version](https://img.shields.io/npm/v/@float-toolkit/angular?label=version&logo=npm)](https://www.npmjs.com/package/@float-toolkit/angular)
1010
[![NPM downloads](https://img.shields.io/npm/dt/@float-toolkit/angular?logo=npm)](https://www.npmjs.com/package/@float-toolkit/angular)
11-
[![Tests status](https://img.shields.io/github/workflow/status/float-toolkit/angular/Test%20with%20Karma?label=tests&logo=angular&logoColor=white)](https://github.com/float-toolkit/angular/actions/workflows/testWithKarma.yml)
11+
[![Tests status](https://img.shields.io/github/actions/workflow/status/float-toolkit/angular/testWithKarma.yml?branch=master&label=tests&logo=angular&logoColor=white)](https://github.com/float-toolkit/angular/actions/workflows/testWithKarma.yml)
1212
[![Code coverage with Codecov](https://img.shields.io/codecov/c/github/float-toolkit/angular/tests?logo=codecov&logoColor=white)](https://codecov.io/gh/float-toolkit/angular)
1313
[![Contributor Covenant Code of Conduct](https://img.shields.io/badge/Contributor%20Covenant-2.1-5e0d73)](https://github.com/float-toolkit/angular/blob/master/.github/CODE_OF_CONDUCT.md)
1414

jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"noEmit": false
1515
},
1616

17-
"include": ["./.eslintrc.js", "./karma.conf.js"],
17+
"include": ["./.eslintrc.js", "./karma.conf.js", "./scripts/**/*.mjs", "./package.json"],
1818
"exclude": [],
1919
"references": []
2020
}

ng-package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
"dest": "./dist/",
55
"lib": {
6-
"entryFile": "./src/public-api.ts"
7-
}
6+
"entryFile": "./src/index.ts"
7+
},
8+
9+
"allowedNonPeerDependencies": ["@float-toolkit/core"]
810
}

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test:ci": "npm run pretest && ng test --browsers=ChromeCI",
1010
"test:watch": "npm run pretest && ng test --watch",
1111
"pretest": "npm run format",
12-
"format": "prettier --write . && ng lint"
12+
"format": "node scripts/versionNumbers.mjs && prettier --write . && ng lint"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -66,6 +66,7 @@
6666
"typescript": "~4.8.4"
6767
},
6868
"dependencies": {
69+
"@float-toolkit/core": "^2.0.1",
6970
"tslib": "^2.4.1"
7071
}
7172
}

scripts/versionNumbers.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { writeFileSync } from "fs";
2+
import { join } from "path";
3+
import { cwd } from "process";
4+
5+
import PackageJSON from "../package.json" assert { type: "json" };
6+
7+
writeFileSync(
8+
join(cwd(), "src/versionNumbers.ts"),
9+
`// AUTOGENERATED. DO NOT MODIFY.
10+
11+
export const versionNumbers = ${JSON.stringify(PackageJSON.version.split("."))};`
12+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defaultOptions } from "../__mocks__/defaultOptions";
2+
import { ft } from "../setup.spec";
3+
4+
describe("inject FloatToolkit", () => {
5+
it("should inject with the default options", () => {
6+
expect(ft).toBeDefined();
7+
8+
expect(ft.defaultPrecision).toBe(10);
9+
expect(ft.options).toEqual(defaultOptions);
10+
});
11+
});
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ft } from "../setup.spec";
2+
3+
describe("FloatToolkit.output", () => {
4+
it("should have an initial value of 0", () => {
5+
expect(ft.output).toBe(0);
6+
});
7+
8+
it("should be changed by operation methods", () => {
9+
function run(callback: () => void, expectedOutput: number): void {
10+
callback();
11+
expect(ft.output).toBe(expectedOutput);
12+
}
13+
14+
run(() => ft.round(0.1 + 0.2), 0.3);
15+
run(() => ft.add([0.1, 0.2]), 0.3);
16+
run(() => ft.subtract([0.8, 0.1, 0.3]), 0.4);
17+
run(() => ft.multiply([0.1, 0.9]), 0.09);
18+
run(() => ft.divide([0.09, 0.9]), 0.1);
19+
});
20+
21+
it("should be reset to 0 when calling FloatToolkit.resetOutput()", () => {
22+
ft.resetOutput();
23+
expect(ft.output).toBe(0);
24+
});
25+
});

0 commit comments

Comments
 (0)