1 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
2 | import * as i0 from '@angular/core';
|
3 | import { Injectable, NgModule } from '@angular/core';
|
4 | import { MatIconRegistry } from '@angular/material/icon';
|
5 | import { of } from 'rxjs';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class MatIconHarness extends ComponentHarness {
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | static with(options = {}) {
|
23 | return new HarnessPredicate(MatIconHarness, options)
|
24 | .addOption('type', options.type, async (harness, type) => (await harness.getType()) === type)
|
25 | .addOption('name', options.name, (harness, text) => HarnessPredicate.stringMatches(harness.getName(), text))
|
26 | .addOption('namespace', options.namespace, (harness, text) => HarnessPredicate.stringMatches(harness.getNamespace(), text));
|
27 | }
|
28 |
|
29 | async getType() {
|
30 | const type = await (await this.host()).getAttribute('data-mat-icon-type');
|
31 | return type === 'svg' ? 0 : 1 ;
|
32 | }
|
33 |
|
34 | async getName() {
|
35 | const host = await this.host();
|
36 | const nameFromDom = await host.getAttribute('data-mat-icon-name');
|
37 |
|
38 | if (nameFromDom) {
|
39 | return nameFromDom;
|
40 | }
|
41 |
|
42 |
|
43 | if ((await this.getType()) === 1 ) {
|
44 | return host.text();
|
45 | }
|
46 | return null;
|
47 | }
|
48 |
|
49 | async getNamespace() {
|
50 | return (await this.host()).getAttribute('data-mat-icon-namespace');
|
51 | }
|
52 |
|
53 | async isInline() {
|
54 | return (await this.host()).hasClass('mat-icon-inline');
|
55 | }
|
56 | }
|
57 |
|
58 | MatIconHarness.hostSelector = '.mat-icon';
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | class FakeMatIconRegistry {
|
80 | addSvgIcon() {
|
81 | return this;
|
82 | }
|
83 | addSvgIconLiteral() {
|
84 | return this;
|
85 | }
|
86 | addSvgIconInNamespace() {
|
87 | return this;
|
88 | }
|
89 | addSvgIconLiteralInNamespace() {
|
90 | return this;
|
91 | }
|
92 | addSvgIconSet() {
|
93 | return this;
|
94 | }
|
95 | addSvgIconSetLiteral() {
|
96 | return this;
|
97 | }
|
98 | addSvgIconSetInNamespace() {
|
99 | return this;
|
100 | }
|
101 | addSvgIconSetLiteralInNamespace() {
|
102 | return this;
|
103 | }
|
104 | registerFontClassAlias() {
|
105 | return this;
|
106 | }
|
107 | classNameForFontAlias(alias) {
|
108 | return alias;
|
109 | }
|
110 | getDefaultFontSetClass() {
|
111 | return ['material-icons'];
|
112 | }
|
113 | getSvgIconFromUrl() {
|
114 | return of(this._generateEmptySvg());
|
115 | }
|
116 | getNamedSvgIcon() {
|
117 | return of(this._generateEmptySvg());
|
118 | }
|
119 | setDefaultFontSetClass() {
|
120 | return this;
|
121 | }
|
122 | addSvgIconResolver() {
|
123 | return this;
|
124 | }
|
125 | ngOnDestroy() { }
|
126 | _generateEmptySvg() {
|
127 | const emptySvg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
128 | emptySvg.classList.add('fake-testing-svg');
|
129 |
|
130 | emptySvg.setAttribute('fit', '');
|
131 | emptySvg.setAttribute('height', '100%');
|
132 | emptySvg.setAttribute('width', '100%');
|
133 | emptySvg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
|
134 | emptySvg.setAttribute('focusable', 'false');
|
135 | return emptySvg;
|
136 | }
|
137 | }
|
138 | FakeMatIconRegistry.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FakeMatIconRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
139 | FakeMatIconRegistry.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FakeMatIconRegistry });
|
140 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FakeMatIconRegistry, decorators: [{
|
141 | type: Injectable
|
142 | }] });
|
143 |
|
144 | class MatIconTestingModule {
|
145 | }
|
146 | MatIconTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatIconTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
147 | MatIconTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: MatIconTestingModule });
|
148 | MatIconTestingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatIconTestingModule, providers: [{ provide: MatIconRegistry, useClass: FakeMatIconRegistry }] });
|
149 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatIconTestingModule, decorators: [{
|
150 | type: NgModule,
|
151 | args: [{
|
152 | providers: [{ provide: MatIconRegistry, useClass: FakeMatIconRegistry }],
|
153 | }]
|
154 | }] });
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | export { FakeMatIconRegistry, MatIconHarness, MatIconTestingModule };
|
177 |
|