Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code-smell: TT-336 Fixing code smells and test coverage
  • Loading branch information
Edgar Guaman committed Sep 17, 2021
commit 19bf35aee416388e9faee6c0d460fa762e4fb67f
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Reports Page', () => {
let fixture: ComponentFixture<TimeEntriesTableComponent>;
let store: MockStore<EntryState>;
let getReportDataSourceSelectorMock;
let durationTime: number;
const timeEntry: Entry = {
id: '123',
start_date: new Date(),
Expand Down Expand Up @@ -62,6 +63,10 @@ describe('Reports Page', () => {
})
);

beforeEach(() => {
durationTime = new Date().setHours(5, 30);
});

it('component should be created', async () => {
expect(component).toBeTruthy();
});
Expand Down Expand Up @@ -107,6 +112,14 @@ describe('Reports Page', () => {
});
});

it('The data should be displayed as a multiple of hour when column is equal to 3', () => {
expect(component.bodyExportOptions(durationTime, 0, 3, 0)).toMatch(/^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/);
});

it('The data should not be displayed as a multiple of hour when column is different of 3', () => {
expect(component.bodyExportOptions(durationTime, 0, 4, 0)).toBe(durationTime);
});

afterEach(() => {
fixture.destroy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
extend: 'excel',
exportOptions: {
format: {
body: (data, row, column, node) => {
return column === 3 ?
moment.duration(data).asHours().toFixed(4).slice(0, -1) :
data;
},
body: this.bodyExportOptions
}
},
text: 'Excel',
Expand All @@ -45,11 +41,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
extend: 'csv',
exportOptions: {
format: {
body: (data, row, column, node) => {
return column === 3 ?
moment.duration(data).asHours().toFixed(4).slice(0, -1) :
data;
},
body: this.bodyExportOptions
}
},
text: 'CSV',
Expand Down Expand Up @@ -102,4 +94,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
const regex = new RegExp('http*', 'g');
return regex.test(uri);
}

bodyExportOptions(data, row, column, node){
console.log(data);
const durationColumnIndex = 3;
return column === durationColumnIndex ? moment.duration(data).asHours().toFixed(2) : data;
}
}