Skip to content

Commit 6c6f83d

Browse files
committed
cva-test-suite added
1 parent adfd0c2 commit 6c6f83d

File tree

3 files changed

+106
-8
lines changed

3 files changed

+106
-8
lines changed

bun.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"lockfileVersion": 1,
3+
"configVersion": 0,
34
"workspaces": {
45
"": {
56
"name": "ngx-mask",
@@ -56,6 +57,7 @@
5657
"lint-staged": "16.1.2",
5758
"markdownlint-cli": "0.45.0",
5859
"ng-packagr": "20.1.0",
60+
"ngx-cva-test-suite": "^2.0.1",
5961
"npm-check-updates": "18.0.1",
6062
"postcss": "8.5.6",
6163
"postcss-nesting": "13.0.2",
@@ -2432,6 +2434,8 @@
24322434

24332435
"ng-packagr": ["[email protected]", "", { "dependencies": { "@ampproject/remapping": "^2.3.0", "@rollup/plugin-json": "^6.1.0", "@rollup/wasm-node": "^4.24.0", "ajv": "^8.17.1", "ansi-colors": "^4.1.3", "browserslist": "^4.22.1", "chokidar": "^4.0.1", "commander": "^14.0.0", "dependency-graph": "^1.0.0", "esbuild": "^0.25.0", "find-cache-directory": "^6.0.0", "injection-js": "^2.4.0", "jsonc-parser": "^3.3.1", "less": "^4.2.0", "ora": "^8.2.0", "piscina": "^5.0.0", "postcss": "^8.4.47", "rollup-plugin-dts": "^6.2.0", "rxjs": "^7.8.1", "sass": "^1.81.0", "tinyglobby": "^0.2.12" }, "optionalDependencies": { "rollup": "^4.24.0" }, "peerDependencies": { "@angular/compiler-cli": "^20.0.0 || ^20.1.0-next.0 || ^20.2.0-next.0", "tailwindcss": "^2.0.0 || ^3.0.0 || ^4.0.0", "tslib": "^2.3.0", "typescript": ">=5.8 <5.9" }, "optionalPeers": ["tailwindcss"], "bin": { "ng-packagr": "src/cli/main.js" } }, "sha512-objHk39HWnSSv54KD0Ct4A02rug6HiqbmXo1KJW39npzuVc37QWfiZy94afltH1zIx+mQqollmGaCmwibmagvQ=="],
24342436

2437+
"ngx-cva-test-suite": ["[email protected]", "", { "dependencies": { "tslib": "^2.3.0" }, "peerDependencies": { "@angular/core": ">=12.0.0", "@angular/forms": ">=12.0.0", "@angular/platform-browser": ">=12.0.0" } }, "sha512-Q6JrUVFXq1J4AdxOoD6KMO4vTZei+l8GYQdlWbT2vExUNu7KW6bulqXsl+OBNHiQ6tj3BKS/+K42HEOuaSfNWg=="],
2438+
24352439
"ngx-highlightjs": ["[email protected]", "", { "dependencies": { "highlight.js": "^11.11.1", "tslib": "^2.3.0" }, "peerDependencies": { "@angular/cdk": ">=19.0.0", "@angular/common": ">=19.0.0", "@angular/core": ">=19.0.0", "rxjs": ">=7.0.0" } }, "sha512-pa4YPChIho+Qs6P036oMvTt8pmTlMwberz/kGBojKVMEHSj9t4PT1YzBplM+RMK0VWgLK4zRbJbxivQrLPr1fQ=="],
24362440

24372441
"ngxtension": ["[email protected]", "", { "dependencies": { "tslib": "^2.3.0" }, "peerDependencies": { "@angular/common": ">=16.0.0", "@angular/core": ">=16.0.0", "@use-gesture/vanilla": "^10.0.0", "rxjs": "^6.0.0 || ^7.0.0" }, "optionalPeers": ["@use-gesture/vanilla"] }, "sha512-ZYs5Fkgrcu+aa/GBqIf/2N7SUZoYam+Fjmu7WxP9rIm4Mx0SECzq+glpWDwBYyPtyfCBwuo6Z8dSPyyzR7PTFQ=="],

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
"@typescript-eslint/parser": "8.38.0",
100100
"@web/test-runner": "0.20.2",
101101
"angular-cli-ghpages": "2.0.3",
102+
"angular-eslint": "20.1.1",
102103
"angular-http-server": "1.12.0",
104+
"bun-types": "1.2.19",
105+
"cssnano": "7.1.0",
103106
"eslint": "9.31.0",
104107
"eslint-config-prettier": "10.1.8",
105108
"eslint-plugin-json": "4.0.1",
@@ -109,23 +112,21 @@
109112
"lint-staged": "16.1.2",
110113
"markdownlint-cli": "0.45.0",
111114
"ng-packagr": "20.1.0",
115+
"ngx-cva-test-suite": "^2.0.1",
112116
"npm-check-updates": "18.0.1",
117+
"postcss": "8.5.6",
118+
"postcss-nesting": "13.0.2",
119+
"postcss-scss": "4.0.9",
113120
"prettier": "3.6.2",
114121
"puppeteer": "24.14.0",
115122
"stylelint": "16.22.0",
116123
"stylelint-config-prettier": "9.0.5",
117124
"stylelint-config-recommended-scss": "15.0.1",
118125
"stylelint-prettier": "5.0.3",
126+
"tailwindcss": "3.4.16",
119127
"type-coverage": "2.29.7",
120128
"typescript": "5.8.3",
121-
"angular-eslint": "20.1.1",
122-
"typescript-eslint": "8.38.0",
123-
"tailwindcss": "3.4.16",
124-
"bun-types": "1.2.19",
125-
"postcss": "8.5.6",
126-
"postcss-nesting": "13.0.2",
127-
"cssnano": "7.1.0",
128-
"postcss-scss": "4.0.9"
129+
"typescript-eslint": "8.38.0"
129130
},
130131
"typeCoverage": {
131132
"atLeast": 91,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Component } from '@angular/core';
2+
import {
3+
ControlValueAccessor,
4+
FormControl,
5+
FormsModule,
6+
ReactiveFormsModule,
7+
} from '@angular/forms';
8+
import { runValueAccessorTests } from 'ngx-cva-test-suite';
9+
import { NgxMaskDirective, provideEnvironmentNgxMask } from 'ngx-mask';
10+
11+
@Component({
12+
imports: [NgxMaskDirective, FormsModule, ReactiveFormsModule],
13+
template: `
14+
<input
15+
class="text-align-right"
16+
mask="Hh:m0"
17+
[dropSpecialCharacters]="false"
18+
[showMaskTyped]="true"
19+
[leadZeroDateTime]="true"
20+
[formControl]="innerFormControl"
21+
(blur)="onTouched()" />
22+
`,
23+
})
24+
class TestComponent implements ControlValueAccessor {
25+
innerFormControl = new FormControl('');
26+
private _onChange: null | ((value: string) => void) = null;
27+
private _onTouched: null | (() => void) = null;
28+
29+
registerOnChange(onChange: (value: string) => void): void {
30+
this._onChange = onChange;
31+
}
32+
33+
registerOnTouched(onTouched: () => void): void {
34+
this._onTouched = onTouched;
35+
}
36+
37+
onChange(value: string): void {
38+
if (this._onChange) {
39+
this._onChange(value);
40+
}
41+
}
42+
43+
onTouched(): void {
44+
if (this._onTouched) {
45+
this._onTouched();
46+
}
47+
}
48+
49+
setDisabledState(isDisabled: boolean): void {
50+
if (isDisabled) this.innerFormControl.disable({ emitEvent: false });
51+
else this.innerFormControl.enable({ emitEvent: false });
52+
}
53+
54+
get disabled() {
55+
return this.innerFormControl.disabled;
56+
}
57+
58+
writeValue(value: string): void {
59+
this.innerFormControl.setValue(value, { emitEvent: false });
60+
}
61+
}
62+
63+
describe('CVA', () => {
64+
runValueAccessorTests({
65+
/** Component, that is being tested */
66+
component: TestComponent,
67+
68+
/**
69+
* All the metadata required for this test to run.
70+
* Under the hood calls TestBed.configureTestingModule with provided config.
71+
*/
72+
testModuleMetadata: {
73+
imports: [ReactiveFormsModule, FormsModule],
74+
providers: [provideEnvironmentNgxMask()],
75+
},
76+
/** Whether component is able to track "onBlur" events separately */
77+
supportsOnBlur: true,
78+
/**
79+
* CSS selector for the element, that should dispatch `blur` event.
80+
* Required and used only if `supportsOnBlur` is set to true.
81+
*/
82+
nativeControlSelector: 'input',
83+
/**
84+
* Tests the correctness of an approach that is used to set value in the component,
85+
* when the change is internal. It's optional and can be omitted by passing "null"
86+
*/
87+
internalValueChangeSetter: null,
88+
/** Function to get the value of a component in a runtime. */
89+
getComponentValue: (fixture) => fixture.componentInstance.innerFormControl.value,
90+
resetCustomValue: { value: null },
91+
getValues: () => ['20:00', '10:00', null],
92+
});
93+
});

0 commit comments

Comments
 (0)