Skip to content

Commit 19bf35a

Browse files
author
Edgar Guaman
committed
code-smell: TT-336 Fixing code smells and test coverage
1 parent 778918b commit 19bf35a

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Reports Page', () => {
1212
let fixture: ComponentFixture<TimeEntriesTableComponent>;
1313
let store: MockStore<EntryState>;
1414
let getReportDataSourceSelectorMock;
15+
let durationTime: number;
1516
const timeEntry: Entry = {
1617
id: '123',
1718
start_date: new Date(),
@@ -62,6 +63,10 @@ describe('Reports Page', () => {
6263
})
6364
);
6465

66+
beforeEach(() => {
67+
durationTime = new Date().setHours(5, 30);
68+
});
69+
6570
it('component should be created', async () => {
6671
expect(component).toBeTruthy();
6772
});
@@ -107,6 +112,14 @@ describe('Reports Page', () => {
107112
});
108113
});
109114

115+
it('The data should be displayed as a multiple of hour when column is equal to 3', () => {
116+
expect(component.bodyExportOptions(durationTime, 0, 3, 0)).toMatch(/^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)$/);
117+
});
118+
119+
it('The data should not be displayed as a multiple of hour when column is different of 3', () => {
120+
expect(component.bodyExportOptions(durationTime, 0, 4, 0)).toBe(durationTime);
121+
});
122+
110123
afterEach(() => {
111124
fixture.destroy();
112125
});

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
3131
extend: 'excel',
3232
exportOptions: {
3333
format: {
34-
body: (data, row, column, node) => {
35-
return column === 3 ?
36-
moment.duration(data).asHours().toFixed(4).slice(0, -1) :
37-
data;
38-
},
34+
body: this.bodyExportOptions
3935
}
4036
},
4137
text: 'Excel',
@@ -45,11 +41,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
4541
extend: 'csv',
4642
exportOptions: {
4743
format: {
48-
body: (data, row, column, node) => {
49-
return column === 3 ?
50-
moment.duration(data).asHours().toFixed(4).slice(0, -1) :
51-
data;
52-
},
44+
body: this.bodyExportOptions
5345
}
5446
},
5547
text: 'CSV',
@@ -102,4 +94,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
10294
const regex = new RegExp('http*', 'g');
10395
return regex.test(uri);
10496
}
97+
98+
bodyExportOptions(data, row, column, node){
99+
console.log(data);
100+
const durationColumnIndex = 3;
101+
return column === durationColumnIndex ? moment.duration(data).asHours().toFixed(2) : data;
102+
}
105103
}

0 commit comments

Comments
 (0)