Skip to content
Prev Previous commit
Next Next commit
refactor: TT-304 Handle message: Editing methods and unit tests assoc…
…iated
  • Loading branch information
Edgar Guaman committed Aug 21, 2021
commit 88f1a3c6b632a83fb107b1f7f161afe068ac5458
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
<th class="col"></th>
</tr>
</thead>
<tr *ngIf="checkIfDataSourceIsLoading(dataSource)">
<tr *ngIf="checkIfDataSourceIsLoadingorEmpty(dataSource)">
<td class="text-center" colspan="7">{{NO_DATA_MESSAGE}}</td>
</tr>
<app-loading-bar *ngIf="dataSource.isLoading"></app-loading-bar>
<tbody *ngIf="!dataSource.isLoading">
<tr *ngIf="checkIfDataSourceIsEmpty(dataSource)">
<tr *ngIf="checkIfDataSourceIsLoadingorEmpty(dataSource)">
<td class="text-center" colspan="7">{{NO_DATA_MESSAGE}}</td>
</tr>
<tr class="d-flex" *ngFor="let entry of dataSource.data">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,22 @@ describe('TimeEntriesComponent', () => {
});

it('checkIfDataSourceIsLoading should be false when dataSource.isLoading is false', () => {
expect(component.checkIfDataSourceIsLoading(state.timeEntriesDataSource)).toBeFalse();
expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeFalse();
});

it('checkIfDataSourceIsLoading should be true when dataSource.isLoading is true', () => {
state.timeEntriesDataSource.isLoading = true;

expect(component.checkIfDataSourceIsLoading(state.timeEntriesDataSource)).toBeTrue();
expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeTrue();
});

it('checkIfDataSourceIsEmpty should be false when dataSource.data.length is not empty', () => {
expect(component.checkIfDataSourceIsEmpty(state.timeEntriesDataSource)).toBeFalse();
expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeFalse();
});

it('checkIfDataSourceIsEmpty should be true when dataSource.data.length is empty', () => {
state.timeEntriesDataSource.data = [];

expect(component.checkIfDataSourceIsEmpty(state.timeEntriesDataSource)).toBeTrue();
expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeTrue();
});
});
11 changes: 2 additions & 9 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}
}

checkIfDataSourceIsLoading(data: DataSource<Entry>): boolean {
if (data.isLoading) {
return true;
}
return false;
}

checkIfDataSourceIsEmpty(data: DataSource<Entry>): boolean {
if (data.data.length === 0) {
checkIfDataSourceIsLoadingorEmpty(source?: DataSource<Entry>): boolean {
if (source.isLoading || source.data.length === 0) {
return true;
}
return false;
Expand Down