1 | import 'dom4';
|
2 | import angular from 'angular';
|
3 | import 'angular-mocks';
|
4 |
|
5 | import Button from './button-ng';
|
6 |
|
7 | import overrides from './button-ng.css';
|
8 |
|
9 | const {ringIconDefaultColor} = overrides;
|
10 |
|
11 | describe('Button Ng', () => {
|
12 | let $compile;
|
13 | let $rootScope;
|
14 |
|
15 | beforeEach(window.module(Button));
|
16 |
|
17 |
|
18 | beforeEach(inject((_$rootScope_, _$compile_) => {
|
19 | $compile = _$compile_;
|
20 | $rootScope = _$rootScope_;
|
21 | }));
|
22 |
|
23 |
|
24 | it('should render button', () => {
|
25 | const element = renderButton();
|
26 | element.tagName.toLowerCase().should.be.equal('button');
|
27 | });
|
28 |
|
29 | it('should render button link', () => {
|
30 | const element = renderButtonLink();
|
31 | element.tagName.toLowerCase().should.be.equal('a');
|
32 | });
|
33 |
|
34 | it('should transclude content', () => {
|
35 | const buttonElement = renderButton();
|
36 | const linkElement = renderButtonLink();
|
37 |
|
38 | angular.element(buttonElement).text().trim().should.be.equal('A');
|
39 | angular.element(linkElement).text().trim().should.be.equal('A');
|
40 | });
|
41 |
|
42 | it('should render active button', () => {
|
43 | const scope = $rootScope.$new();
|
44 | scope.active = true;
|
45 | const element = renderButton(scope);
|
46 | element.should.have.attribute('data-test-active');
|
47 | });
|
48 |
|
49 |
|
50 | it('should remove active attribute', () => {
|
51 | const scope = $rootScope.$new();
|
52 |
|
53 | scope.active = true;
|
54 | const element = renderButton(scope);
|
55 | element.should.have.attribute('data-test-active');
|
56 |
|
57 | scope.active = false;
|
58 | scope.$digest();
|
59 | element.should.not.have.attribute('data-test-active');
|
60 | });
|
61 |
|
62 | it('should add default icon color class if button without mode', () => {
|
63 | const element = findTranscludeNode(renderButton());
|
64 | [...element.classList].should.contains(ringIconDefaultColor);
|
65 | });
|
66 |
|
67 |
|
68 | it('should not set default icon color for buttons with mode', () => {
|
69 |
|
70 |
|
71 |
|
72 | const scope = $rootScope.$new();
|
73 | const element = findTranscludeNode($compile('<rg-button mode="primary"/>')(scope)[0]);
|
74 | scope.$digest();
|
75 | [...element.classList].should.not.contains(ringIconDefaultColor);
|
76 | });
|
77 |
|
78 |
|
79 | function renderButton(scope = $rootScope.$new()) {
|
80 | return compileButton('rg-button', scope);
|
81 | }
|
82 |
|
83 | function renderButtonLink(scope = $rootScope.$new()) {
|
84 | return compileButton('rg-button-link', scope);
|
85 | }
|
86 |
|
87 | function compileButton(tagName, scope) {
|
88 | const iElement = $compile(`<${tagName} loader="loader" active="active">A</${tagName}>`)(scope);
|
89 | scope.$digest();
|
90 | return iElement[0];
|
91 | }
|
92 |
|
93 | function findTranscludeNode(element) {
|
94 | return element.query('ng-transclude');
|
95 | }
|
96 | });
|