Skip to content

Commit a2443a2

Browse files
committed
test(action strip): refactoring tests
1 parent 9bcd1df commit a2443a2

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

projects/igniteui-angular/src/lib/action-strip/action-strip.component.spec.ts

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { IgxActionStripComponent } from './action-strip.component';
22
import { Component, ViewChild, ElementRef, ViewContainerRef } from '@angular/core';
33
import { configureTestSuite } from '../test-utils/configure-suite';
44
import { IgxIconModule } from '../icon/public_api';
5-
import { TestBed, fakeAsync, waitForAsync } from '@angular/core/testing';
5+
import { TestBed } from '@angular/core/testing';
66
import { By } from '@angular/platform-browser';
77
import { wait } from '../test-utils/ui-interactions.spec';
88
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
99
import { IgxToggleModule } from '../directives/toggle/toggle.directive';
1010
import { IgxActionStripModule } from './action-strip.module';
11+
import { IgxDropDownModule } from '../drop-down/public_api';
1112

1213
const ACTION_STRIP_CONTAINER_CSS = 'igx-action-strip__actions';
1314
const DROP_DOWN_LIST = 'igx-drop-down__list';
@@ -20,33 +21,48 @@ describe('igxActionStrip', () => {
2021
let innerContainer: ViewContainerRef;
2122

2223
describe('Unit tests: ', () => {
23-
const mockViewContainerRef = jasmine.createSpyObj('ViewContainerRef', ['element']);
24-
const mockRenderer2 = jasmine.createSpyObj('Renderer2', ['appendChild', 'removeChild']);
25-
const mockContext = jasmine.createSpyObj('context', ['element']);
26-
const mockDisplayDensity = jasmine.createSpyObj('IDisplayDensityOptions', ['displayDensity']);
27-
const cdr = jasmine.createSpyObj('ChangeDetectorRef', ['detectChanges']);
28-
29-
it('should properly get/set hidden', () => {
30-
actionStrip = new IgxActionStripComponent(mockViewContainerRef, mockRenderer2, mockDisplayDensity, cdr);
31-
expect(actionStrip.hidden).toBeFalsy();
32-
actionStrip.hidden = true;
33-
expect(actionStrip.hidden).toBeTruthy();
24+
25+
configureTestSuite(() => {
26+
return TestBed.configureTestingModule({
27+
declarations: [
28+
IgxActionStripComponent
29+
],
30+
imports: [
31+
NoopAnimationsModule,
32+
IgxDropDownModule
33+
]
34+
});
3435
});
3536

37+
// This test is only testing whether a setter ran. Removing it
38+
// it('should properly get/set hidden', () => {
39+
// fixture = TestBed.createComponent(IgxActionStripComponent);
40+
// actionStrip = fixture.componentInstance as IgxActionStripComponent;
41+
// fixture.detectChanges();
42+
// expect(actionStrip.hidden).toBeFalsy();
43+
// actionStrip.hidden = true;
44+
// expect(actionStrip.hidden).toBeTruthy();
45+
// });
46+
3647
it('should properly show and hide using API', () => {
37-
actionStrip = new IgxActionStripComponent(mockViewContainerRef, mockRenderer2, mockDisplayDensity, cdr);
38-
actionStrip.show(mockContext);
48+
fixture = TestBed.createComponent(IgxActionStripComponent);
49+
actionStrip = fixture.componentInstance as IgxActionStripComponent;
50+
fixture.detectChanges();
51+
52+
const el = document.createElement('div');
53+
fixture.debugElement.nativeElement.appendChild(el);
54+
actionStrip.show(el);
3955
expect(actionStrip.hidden).toBeFalsy();
40-
expect(actionStrip.context).toBe(mockContext);
56+
expect(actionStrip.context).toBe(el);
4157
actionStrip.hide();
4258
expect(actionStrip.hidden).toBeTruthy();
59+
fixture.debugElement.nativeElement.removeChild(el);
4360
});
4461
});
4562

4663
describe('Initialization and rendering tests: ', () => {
47-
configureTestSuite();
48-
beforeAll(waitForAsync(() => {
49-
TestBed.configureTestingModule({
64+
configureTestSuite(() => {
65+
return TestBed.configureTestingModule({
5066
declarations: [
5167
IgxActionStripTestingComponent
5268
],
@@ -56,16 +72,18 @@ describe('igxActionStrip', () => {
5672
NoopAnimationsModule,
5773
IgxToggleModule
5874
]
59-
}).compileComponents();
60-
}));
61-
beforeEach(fakeAsync(() => {
75+
})
76+
});
77+
78+
beforeEach(() => {
6279
fixture = TestBed.createComponent(IgxActionStripTestingComponent);
6380
fixture.detectChanges();
6481
actionStrip = fixture.componentInstance.actionStrip;
6582
actionStripElement = fixture.componentInstance.actionStripElement;
6683
parentContainer = fixture.componentInstance.parentContainer;
6784
innerContainer = fixture.componentInstance.innerContainer;
68-
}));
85+
});
86+
6987
it('should be overlapping its parent container when no context is applied', () => {
7088
const parentBoundingRect = parentContainer.nativeElement.getBoundingClientRect();
7189
const actionStripBoundingRect = actionStripElement.nativeElement.getBoundingClientRect();
@@ -102,9 +120,8 @@ describe('igxActionStrip', () => {
102120
});
103121

104122
describe('render content as menu', () => {
105-
configureTestSuite();
106-
beforeAll(waitForAsync(() => {
107-
TestBed.configureTestingModule({
123+
configureTestSuite(() => {
124+
return TestBed.configureTestingModule({
108125
declarations: [
109126
IgxActionStripMenuTestingComponent,
110127
IgxActionStripCombinedMenuTestingComponent
@@ -115,8 +132,8 @@ describe('igxActionStrip', () => {
115132
NoopAnimationsModule,
116133
IgxToggleModule
117134
]
118-
}).compileComponents();
119-
}));
135+
});
136+
});
120137

121138
it('should render tree-dot button which toggles the content as menu', () => {
122139
fixture = TestBed.createComponent(IgxActionStripMenuTestingComponent);

0 commit comments

Comments
 (0)