Skip to content

Commit f805cc6

Browse files
author
Edgar Guaman
committed
refactor: TT-304 Handle message: Making readonly variables, new methods and tests
1 parent 19be26b commit f805cc6

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
<th class="col"></th>
5555
</tr>
5656
</thead>
57-
<tr *ngIf="dataSource.isLoading">
58-
<td class="text-center" colspan="7">No data available in table</td>
57+
<tr *ngIf="checkIfDataSourceIsLoading(dataSource)">
58+
<td class="text-center" colspan="7">{{NO_DATA_MESSAGE}}</td>
5959
</tr>
6060
<app-loading-bar *ngIf="dataSource.isLoading"></app-loading-bar>
6161
<tbody *ngIf="!dataSource.isLoading">
62-
<tr *ngIf="dataSource?.data.length === 0">
63-
<td class="text-center" colspan="7">No data available in table</td>
62+
<tr *ngIf="checkIfDataSourceIsEmpty(dataSource)">
63+
<td class="text-center" colspan="7">{{NO_DATA_MESSAGE}}</td>
6464
</tr>
6565
<tr class="d-flex" *ngFor="let entry of dataSource.data">
6666
<td class="col">{{ entry.start_date | date: 'MM/dd/yyyy' }}</td>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,16 @@ describe('TimeEntriesComponent', () => {
668668

669669
expect(HTMLTimeEntriesView).not.toBeNull();
670670
});
671+
672+
it('checkIfDataSourceIsLoading should be false when dataSource.isLoading is false', () => {
673+
const expectedValue = false;
674+
675+
expect(component.checkIfDataSourceIsLoading(state.timeEntriesDataSource)).toEqual(expectedValue);
676+
});
677+
678+
it('checkIfDataSourceIsEmpty should be false when dataSource.data.length is not zero', () => {
679+
const expectedValue = false;
680+
681+
expect(component.checkIfDataSourceIsEmpty(state.timeEntriesDataSource)).toEqual(expectedValue);
682+
});
671683
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
3838
selectedYear: number;
3939
selectedMonthAsText: string;
4040
isActiveEntryOverlapping = false;
41+
readonly NO_DATA_MESSAGE: string = 'No data available in table';
42+
timeEntry: DataSource<Entry>;
4143
constructor(
4244
private store: Store<EntryState>,
4345
private toastrService: ToastrService,
@@ -216,4 +218,18 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
216218
});
217219
}
218220
}
221+
222+
checkIfDataSourceIsLoading(data: DataSource<Entry>): boolean {
223+
if (data.isLoading) {
224+
return true;
225+
}
226+
return false;
227+
}
228+
229+
checkIfDataSourceIsEmpty(data: DataSource<Entry>): boolean {
230+
if (data.data.length === 0) {
231+
return true;
232+
}
233+
return false;
234+
}
219235
}

0 commit comments

Comments
 (0)