Skip to content
Prev Previous commit
Next Next commit
refactor: TT-304 Handle message: Rewriting method and unit tests for …
…that method
  • Loading branch information
Edgar Guaman committed Aug 21, 2021
commit b927d9615f9a7422e2b704582b4af49349fca45e
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</tr>
<app-loading-bar *ngIf="dataSource.isLoading"></app-loading-bar>
<tbody *ngIf="!dataSource.isLoading">
<tr *ngIf="checkIfDataSourceIsLoadingorEmpty(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
16 changes: 3 additions & 13 deletions src/app/modules/time-entries/pages/time-entries.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,23 +669,13 @@ describe('TimeEntriesComponent', () => {
expect(HTMLTimeEntriesView).not.toBeNull();
});

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

it('checkIfDataSourceIsLoading should be true when dataSource.isLoading is true', () => {
it('checkIfDataSourceIsLoadingorEmpty should be true when dataSource is Loading and data is not empty', () => {
state.timeEntriesDataSource.isLoading = true;

state.timeEntriesDataSource.data = [];
expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeTrue();
});

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

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

expect(component.checkIfDataSourceIsLoadingorEmpty(state.timeEntriesDataSource)).toBeTrue();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}

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