Skip to content

Commit ba7e34b

Browse files
test: TTL-910 update tests
1 parent 027b7a2 commit ba7e34b

File tree

2 files changed

+64
-41
lines changed

2 files changed

+64
-41
lines changed

src/app/modules/reports/components/time-range-custom/time-range-custom.component.spec.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import * as entryActions from '../../../time-clock/store/entry.actions';
88
import * as moment from 'moment';
99
import { SimpleChange } from '@angular/core';
1010

11-
1211
describe('TimeRangeCustomComponent', () => {
1312
let component: TimeRangeCustomComponent;
1413
let fixture: ComponentFixture<TimeRangeCustomComponent>;
1514
let store: MockStore<EntryState>;
1615
const toastrServiceStub = {
1716
error: () => {
1817
return 'test error';
19-
}
18+
},
2019
};
2120

2221
const timeEntry = {
@@ -27,7 +26,7 @@ describe('TimeRangeCustomComponent', () => {
2726
technologies: ['react', 'redux'],
2827
comments: 'any comment',
2928
uri: 'TT-123',
30-
project_id: '1'
29+
project_id: '1',
3130
};
3231

3332
const state = {
@@ -44,13 +43,9 @@ describe('TimeRangeCustomComponent', () => {
4443
beforeEach(async () => {
4544
await TestBed.configureTestingModule({
4645
imports: [FormsModule, ReactiveFormsModule],
47-
declarations: [ TimeRangeCustomComponent ],
48-
providers: [
49-
provideMockStore({ initialState: state }),
50-
{ provide: ToastrService, useValue: toastrServiceStub }
51-
],
52-
})
53-
.compileComponents();
46+
declarations: [TimeRangeCustomComponent],
47+
providers: [provideMockStore({ initialState: state }), { provide: ToastrService, useValue: toastrServiceStub }],
48+
}).compileComponents();
5449
store = TestBed.inject(MockStore);
5550
});
5651

@@ -81,10 +76,12 @@ describe('TimeRangeCustomComponent', () => {
8176

8277
component.onSubmit();
8378

84-
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntriesByTimeRange({
85-
start_date: end.startOf('day'),
86-
end_date: start.endOf('day')
87-
}));
79+
expect(store.dispatch).toHaveBeenCalledWith(
80+
new entryActions.LoadEntriesByTimeRange({
81+
start_date: end.startOf('day'),
82+
end_date: start.endOf('day'),
83+
})
84+
);
8885
});
8986

9087
it('shows an error when the end date is before the start date', () => {
@@ -108,7 +105,6 @@ describe('TimeRangeCustomComponent', () => {
108105

109106
expect(component.range.controls.start.setValue).toHaveBeenCalled();
110107
expect(component.range.controls.end.setValue).toHaveBeenCalled();
111-
112108
});
113109

114110
it('triggers onSubmit to set initial data', () => {
@@ -121,30 +117,41 @@ describe('TimeRangeCustomComponent', () => {
121117

122118
it('When the ngOnChanges method is called, the onSubmit method is called', () => {
123119
const userIdCalled = 'test-user-1';
120+
const projectIdCalled = 'test-project';
121+
const activityIdCalled = 'test-activity';
124122
spyOn(component, 'onSubmit');
125123

126-
component.ngOnChanges({userId: new SimpleChange(null, userIdCalled, false)});
124+
component.ngOnChanges({
125+
userId: new SimpleChange(null, userIdCalled, false),
126+
projectId: new SimpleChange(null, projectIdCalled, false),
127+
activityId: new SimpleChange(null, activityIdCalled, false),
128+
});
127129

128130
expect(component.onSubmit).toHaveBeenCalled();
129131
});
130132

131133
it('When the ngOnChanges method is the first change, the onSubmit method is not called', () => {
132134
const userIdNotCalled = 'test-user-2';
135+
const projectIdNotCalled = 'test-project';
136+
const activityIdNotCalled = 'test-activity';
133137
spyOn(component, 'onSubmit');
134138

135-
component.ngOnChanges({userId: new SimpleChange(null, userIdNotCalled, true)});
139+
component.ngOnChanges({
140+
userId: new SimpleChange(null, userIdNotCalled, true),
141+
projectId: new SimpleChange(null, projectIdNotCalled, true),
142+
activityId: new SimpleChange(null, activityIdNotCalled, true),
143+
});
136144

137145
expect(component.onSubmit).not.toHaveBeenCalled();
138146
});
139147

140148
it('should call range form and delete variable local storage ', () => {
141149
spyOn(localStorage, 'removeItem').withArgs('rangeDatePicker');
142-
component.range.setValue({start: null, end: null});
150+
component.range.setValue({ start: null, end: null });
143151
jasmine.clock().install();
144152
component.dateRangeChange();
145153
jasmine.clock().tick(200);
146154
expect(localStorage.removeItem).toHaveBeenCalledWith('rangeDatePicker');
147155
jasmine.clock().uninstall();
148156
});
149-
150157
});

src/app/modules/reports/components/time-range-form/time-range.component.spec.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Reports Page', () => {
1717
let store: MockStore<EntryState>;
1818

1919
const toastrServiceStub = {
20-
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
20+
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => {},
2121
};
2222

2323
const timeEntry = {
@@ -28,7 +28,7 @@ describe('Reports Page', () => {
2828
technologies: ['react', 'redux'],
2929
comments: 'any comment',
3030
uri: 'custom uri',
31-
project_id: '123'
31+
project_id: '123',
3232
};
3333

3434
const state = {
@@ -42,18 +42,20 @@ describe('Reports Page', () => {
4242
entriesForReport: [timeEntry],
4343
};
4444

45-
beforeEach(waitForAsync(() => {
46-
TestBed.configureTestingModule({
47-
imports: [FormsModule, ReactiveFormsModule],
48-
declarations: [TimeRangeFormComponent, InputDateComponent],
49-
providers: [
50-
provideMockStore({ initialState: state }),
51-
{ provide: ToastrService, useValue: toastrServiceStub },
52-
{ provide: DateAdapter, useClass: DateAdapter }
53-
],
54-
}).compileComponents();
55-
store = TestBed.inject(MockStore);
56-
}));
45+
beforeEach(
46+
waitForAsync(() => {
47+
TestBed.configureTestingModule({
48+
imports: [FormsModule, ReactiveFormsModule],
49+
declarations: [TimeRangeFormComponent, InputDateComponent],
50+
providers: [
51+
provideMockStore({ initialState: state }),
52+
{ provide: ToastrService, useValue: toastrServiceStub },
53+
{ provide: DateAdapter, useClass: DateAdapter },
54+
],
55+
}).compileComponents();
56+
store = TestBed.inject(MockStore);
57+
})
58+
);
5759

5860
beforeEach(() => {
5961
fixture = TestBed.createComponent(TimeRangeFormComponent);
@@ -74,10 +76,12 @@ describe('Reports Page', () => {
7476

7577
component.onSubmit();
7678

77-
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntriesByTimeRange({
78-
start_date: yesterday.startOf('day'),
79-
end_date: today.endOf('day')
80-
}));
79+
expect(store.dispatch).toHaveBeenCalledWith(
80+
new entryActions.LoadEntriesByTimeRange({
81+
start_date: yesterday.startOf('day'),
82+
end_date: today.endOf('day'),
83+
})
84+
);
8185
});
8286

8387
it('setInitialDataOnScreen on ngOnInit', () => {
@@ -128,19 +132,31 @@ describe('Reports Page', () => {
128132
});
129133

130134
it('When the ngOnChanges method is called, the onSubmit method is called', () => {
131-
const userId = 'abcd';
135+
const userIdCalled = 'test-user-2';
136+
const projectIdCalled = 'test-project';
137+
const activityIdCalled = 'test-activity';
132138
spyOn(component, 'onSubmit');
133139

134-
component.ngOnChanges({userId: new SimpleChange(null, userId, false)});
140+
component.ngOnChanges({
141+
userId: new SimpleChange(null, userIdCalled, false),
142+
projectId: new SimpleChange(null, projectIdCalled, false),
143+
activityId: new SimpleChange(null, activityIdCalled, false),
144+
});
135145

136146
expect(component.onSubmit).toHaveBeenCalled();
137147
});
138148

139149
it('When the ngOnChanges method is the first change, the onSubmit method is not called', () => {
140-
const userId = 'abcd';
150+
const userIdNotCalled = 'test-user-2';
151+
const projectIdNotCalled = 'test-project';
152+
const activityIdNotCalled = 'test-activity';
141153
spyOn(component, 'onSubmit');
142154

143-
component.ngOnChanges({userId: new SimpleChange(null, userId, true)});
155+
component.ngOnChanges({
156+
userId: new SimpleChange(null, userIdNotCalled, true),
157+
projectId: new SimpleChange(null, projectIdNotCalled, true),
158+
activityId: new SimpleChange(null, activityIdNotCalled, true),
159+
});
144160

145161
expect(component.onSubmit).not.toHaveBeenCalled();
146162
});

0 commit comments

Comments
 (0)