Skip to content

Commit 35cabe8

Browse files
authored
Merge pull request #334 from ioet/309-flaky-tests
closes #309 Removing flaky tests
2 parents d0bd00e + d23732f commit 35cabe8

File tree

5 files changed

+48
-51
lines changed

5 files changed

+48
-51
lines changed

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.spec.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,18 @@ describe('CustomerTableListComponent', () => {
117117
expect(component.customers).toEqual(state.data);
118118
});
119119

120-
// it('on success load customer and the datatable was already initialized, then the datatable should be destroyed ' +
121-
// 'before reloading the customer data', () => {
122-
// const actionSubject = TestBed.get(ActionsSubject) as ActionsSubject;
123-
// component.isDtInitialized = true;
124-
// const action = {
125-
// type: CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS,
126-
// payload: state.data
127-
// };
128-
// const dtApi: DataTables.Api = jasmine.createSpyObj<DataTables.Api>('dtApi', ['destroy']);
129-
// component.dtElement.dtInstance = Promise.resolve(dtApi);
130-
// spyOn(component.dtElement.dtInstance, 'then');
131-
//
132-
// actionSubject.next(action);
133-
//
134-
// expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
135-
// // TODO Improve this test. This is not testing the datatable is destroyed
136-
// // expect(dtApi.destroy).toHaveBeenCalled();
137-
// });
120+
it('on success load customer, the datatable should be reloaded', async () => {
121+
const actionSubject = TestBed.inject(ActionsSubject);
122+
const action = {
123+
type: CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS,
124+
payload: state.data
125+
};
126+
spyOn(component.dtElement.dtInstance, 'then');
127+
128+
actionSubject.next(action);
129+
130+
expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
131+
});
138132

139133
afterEach(() => {
140134
component.dtTrigger.unsubscribe();

src/app/modules/customer-management/components/customer-info/components/customer-list/customer-list.component.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
1+
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild, AfterViewInit} from '@angular/core';
22
import {ActionsSubject, Store} from '@ngrx/store';
33

44
import {Subject, Subscription} from 'rxjs';
@@ -17,7 +17,7 @@ import {DataTableDirective} from 'angular-datatables';
1717
templateUrl: './customer-list.component.html',
1818
styleUrls: ['./customer-list.component.scss'],
1919
})
20-
export class CustomerListComponent implements OnInit, OnDestroy {
20+
export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
2121

2222
@Input() showCustomerForm: boolean;
2323
@Output() changeValueShowCustomerForm = new EventEmitter<boolean>();
@@ -27,7 +27,6 @@ export class CustomerListComponent implements OnInit, OnDestroy {
2727
dtTrigger: Subject<any> = new Subject();
2828
@ViewChild(DataTableDirective, {static: false})
2929
dtElement: DataTableDirective;
30-
isDtInitialized = false;
3130
loadCustomersSubscription: Subscription;
3231
changeCustomerSubscription: Subscription;
3332

@@ -62,6 +61,10 @@ export class CustomerListComponent implements OnInit, OnDestroy {
6261
this.store.dispatch(new LoadCustomers());
6362
}
6463

64+
ngAfterViewInit(): void {
65+
this.rerenderDataTable();
66+
}
67+
6568
ngOnDestroy() {
6669
this.loadCustomersSubscription.unsubscribe();
6770
this.changeCustomerSubscription.unsubscribe();
@@ -78,16 +81,14 @@ export class CustomerListComponent implements OnInit, OnDestroy {
7881
this.store.dispatch(new DeleteCustomer(customerId));
7982
}
8083

81-
/* istanbul ignore next */
8284
private rerenderDataTable(): void {
83-
if (this.isDtInitialized) {
84-
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
85-
dtInstance.destroy();
85+
if (this.dtElement && this.dtElement.dtInstance) {
86+
this.dtElement.dtInstance.then((dtInstances: DataTables.Api) => {
87+
dtInstances.destroy();
8688
this.dtTrigger.next();
8789
});
8890
} else {
8991
this.dtTrigger.next();
90-
this.isDtInitialized = true;
9192
}
9293
}
9394
}

src/app/modules/login/services/azure.ad.b2c.service.spec.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ import { UserAgentApplication, Account } from 'msal';
55
describe('AzureAdB2CService', () => {
66
let service: AzureAdB2CService;
77

8-
const account: Account = {
9-
accountIdentifier: 'abc',
10-
homeAccountIdentifier: 'abc',
11-
userName: 'abc',
12-
name: 'abc',
13-
idToken: {
14-
iss: ' http://hostname.com/12345/v0/',
15-
},
16-
idTokenClaims: {},
17-
sid: 'abc',
18-
environment: 'abc',
19-
};
8+
let account: Account;
209

2110
beforeEach(() => {
2211
TestBed.configureTestingModule({
2312
imports: [],
2413
});
2514
service = TestBed.inject(AzureAdB2CService);
15+
account = {
16+
accountIdentifier: 'abc',
17+
homeAccountIdentifier: 'abc',
18+
userName: 'abc',
19+
name: 'abc',
20+
idToken: {
21+
iss: ' http://hostname.com/12345/v0/',
22+
},
23+
idTokenClaims: {},
24+
sid: 'abc',
25+
environment: 'abc',
26+
};
2627
});
2728

2829
it('should be created', inject([AzureAdB2CService], (apiService: AzureAdB2CService) => {
@@ -54,23 +55,24 @@ describe('AzureAdB2CService', () => {
5455
expect(name).toEqual(account.name);
5556
});
5657

57-
// it('isAdmin false when extension_role !== time-tracker-admin', () => {
58-
// spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(account);
58+
it('isAdmin false when extension_role !== time-tracker-admin', async () => {
59+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(account);
60+
61+
const isAdmin = service.isAdmin();
5962

60-
// const isAdmin = service.isAdmin();
63+
expect(isAdmin).toEqual(false);
64+
});
6165

62-
// expect(isAdmin).toEqual(false);
63-
// });
66+
it('isAdmin when extension_role === time-tracker-admin', async () => {
67+
const adminAccount = {...account};
68+
adminAccount.idToken.extension_role = 'time-tracker-admin';
6469

65-
// it('isAdmin when extension_role === time-tracker-admin', () => {
66-
// const adminAccount = account;
67-
// adminAccount.idToken.extension_role = 'time-tracker-admin';
68-
// spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(adminAccount);
70+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(adminAccount);
6971

70-
// const isAdmin = service.isAdmin();
72+
const isAdmin = service.isAdmin();
7173

72-
// expect(isAdmin).toBeTruthy();
73-
// });
74+
expect(isAdmin).toBeTruthy();
75+
});
7476

7577
it('isLogin returns true if UserAgentApplication has a defined Account', () => {
7678
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValue(account);

src/app/modules/login/services/azure.ad.b2c.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class AzureAdB2CService {
3434
}
3535

3636
isAdmin() {
37+
// console.log("Account: " ,this.msal.getAccount());
3738
return this.msal.getAccount()?.idToken?.extension_role === 'time-tracker-admin';
3839
}
3940

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getActiveTimeEntry } from './../../time-clock/store/entry.selectors';
21
import { ToastrService } from 'ngx-toastr';
32
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
43
import { provideMockStore, MockStore } from '@ngrx/store/testing';

0 commit comments

Comments
 (0)