Skip to content

Commit 41d4571

Browse files
author
thegreatyamori
committed
test: TT-155 modify test expectations
1 parent f8d3db3 commit 41d4571

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Reports Page', () => {
2121
description: 'any comment',
2222
uri: 'custom uri',
2323
project_id: '123',
24-
project_name: 'Time-Tracker'
24+
project_name: 'Time-Tracker',
2525
};
2626

2727
const state: EntryState = {
@@ -33,38 +33,41 @@ describe('Reports Page', () => {
3333
timeEntriesSummary: null,
3434
timeEntriesDataSource: {
3535
data: [timeEntry],
36-
isLoading: false
36+
isLoading: false,
3737
},
3838
reportDataSource: {
3939
data: [timeEntry],
40-
isLoading: false
41-
}
40+
isLoading: false,
41+
},
4242
};
4343

44-
beforeEach(waitForAsync(() => {
45-
TestBed.configureTestingModule({
46-
imports: [],
47-
declarations: [TimeEntriesTableComponent, SubstractDatePipe],
48-
providers: [provideMockStore({ initialState: state })],
49-
}).compileComponents();
50-
store = TestBed.inject(MockStore);
51-
52-
}));
44+
beforeEach(
45+
waitForAsync(() => {
46+
TestBed.configureTestingModule({
47+
imports: [],
48+
declarations: [TimeEntriesTableComponent, SubstractDatePipe],
49+
providers: [provideMockStore({ initialState: state })],
50+
}).compileComponents();
51+
store = TestBed.inject(MockStore);
52+
})
53+
);
5354

54-
beforeEach(waitForAsync(() => {
55-
fixture = TestBed.createComponent(TimeEntriesTableComponent);
56-
component = fixture.componentInstance;
57-
store.setState(state);
58-
getReportDataSourceSelectorMock = store.overrideSelector(getReportDataSource, state.reportDataSource);
59-
fixture.detectChanges();
60-
}));
55+
beforeEach(
56+
waitForAsync(() => {
57+
fixture = TestBed.createComponent(TimeEntriesTableComponent);
58+
component = fixture.componentInstance;
59+
store.setState(state);
60+
getReportDataSourceSelectorMock = store.overrideSelector(getReportDataSource, state.reportDataSource);
61+
fixture.detectChanges();
62+
})
63+
);
6164

6265
it('component should be created', async () => {
6366
expect(component).toBeTruthy();
6467
});
6568

6669
it('on success load time entries, the report should be populated', () => {
67-
component.reportDataSource$.subscribe(ds => {
70+
component.reportDataSource$.subscribe((ds) => {
6871
expect(ds.data).toEqual(state.reportDataSource.data);
6972
});
7073
});
@@ -78,16 +81,20 @@ describe('Reports Page', () => {
7881

7982
fit('when the uri starts with http or https it should return true and open the url in a new tab', () => {
8083
const uriExpected = 'http://customuri.com';
84+
spyOn(component, 'isValidUri').and.returnValue(true);
8185
spyOn(window, 'open');
82-
const isValidUri = uriExpected.startsWith('http' || 'https');
83-
expect(isValidUri).toBeTrue();
84-
expect(window.open).toHaveBeenCalled();
86+
87+
expect(component.isLinkExternal(uriExpected)).not.toEqual('');
88+
expect(window.open).toHaveBeenCalledWith(uriExpected, '_blank');
89+
expect(component.isValidUri).toHaveBeenCalled();
8590
});
8691

8792
it('when the uri starts without http or https it should return false and not navigate or open a new tab', () => {
8893
const uriExpected = timeEntry.uri;
89-
const isValidUri = uriExpected.startsWith('http' || 'https');
90-
expect(isValidUri).toBeFalse();
94+
spyOn(component, 'isValidUri').and.returnValue(false);
95+
96+
expect(component.isLinkExternal(uriExpected)).toEqual('');
97+
expect(component.isValidUri).toHaveBeenCalled();
9198
});
9299

93100
afterEach(() => {

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8686
}
8787
}
8888

89-
isLinkExternal(uri: string) {
89+
isLinkExternal(uri: string): WindowProxy | string {
9090
return this.isValidUri(uri) ? window.open(uri, '_blank') : '';
9191
}
9292

9393
isValidUri(uri: string) {
9494
return uri.startsWith('http' || 'https');
9595
}
96-
9796
}

0 commit comments

Comments
 (0)