This repository was archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathstyle-utils.spec.ts
91 lines (75 loc) · 2.76 KB
/
style-utils.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, PLATFORM_ID} from '@angular/core';
import {CommonModule, isPlatformServer} from '@angular/common';
import {ComponentFixture, inject, TestBed} from '@angular/core/testing';
import {customMatchers} from '../../utils/testing/custom-matchers';
import {makeCreateTestComponent, expectNativeEl} from '../../utils/testing/helpers';
import {StyleUtils} from './style-utils';
describe('styler', () => {
let styler: StyleUtils;
let fixture: ComponentFixture<any>;
let platformId: Object;
let componentWithTemplate = (template: string, styles?: any) => {
fixture = makeCreateTestComponent(() => TestLayoutComponent)(template, styles);
inject([StyleUtils, PLATFORM_ID], (_styler: StyleUtils, _platformId: Object) => {
styler = _styler;
platformId = _platformId;
})();
};
beforeEach(() => {
jasmine.addMatchers(customMatchers);
// Configure testbed to prepare services
TestBed.configureTestingModule({
imports: [CommonModule],
declarations: [TestLayoutComponent],
});
});
describe('testing display styles', () => {
it('should not have a default for <div></div>', () => {
componentWithTemplate(`
<div></div>
`);
expectNativeEl(fixture).not.toHaveStyle({'display': 'block'}, styler);
});
it('should find to "display" for inline style <div></div>', () => {
componentWithTemplate(`
<div style="display: flex;"></div>
`);
expectNativeEl(fixture).toHaveCSS({'display': 'flex'}, styler);
});
it('should find `display` from html style element', () => {
componentWithTemplate(`
<style>
div.special { display: inline-block; }
</style>
<div class="special"></div>
`);
// TODO(CaerusKaru): Domino is unable to detect this style
if (!isPlatformServer(platformId)) {
expectNativeEl(fixture).toHaveCSS({'display': 'inline-block'}, styler);
}
});
it('should find `display` from component styles', () => {
componentWithTemplate(`<div class="extra"></div>`, ['div.extra { display:table; }']);
// TODO(CaerusKaru): Domino is unable to detect this style
if (!isPlatformServer(platformId)) {
expectNativeEl(fixture).toHaveCSS({'display': 'table'}, styler);
}
});
});
});
// *****************************************************************
// Template Component
// *****************************************************************
@Component({
selector: 'test-style-utils',
template: `<span>PlaceHolder Template HTML</span>`
})
class TestLayoutComponent {
}