Skip to content

Commit 426106f

Browse files
edgardavid2015Edgar Guaman
andauthored
fix: TT-336 Fix format Duration column (#749)
* fix: TT-336 Fix format Duration column * code-smell: TT-336 Fixing code smells and test coverage * code-smell: TT-336 Fixing code smells * fix: TT-336 Changes in time entries unit tests * fix: TT-336 Changes in time entries unit tests * fix: TT-336 Deleting a console.log Co-authored-by: Edgar Guaman <[email protected]>
1 parent 6b50b6c commit 426106f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe('Reports Page', () => {
1212
let fixture: ComponentFixture<TimeEntriesTableComponent>;
1313
let store: MockStore<EntryState>;
1414
let getReportDataSourceSelectorMock;
15+
let durationTime: number;
16+
let row: number;
17+
let node: number;
18+
let decimalValidator: RegExp;
1519
const timeEntry: Entry = {
1620
id: '123',
1721
start_date: new Date(),
@@ -62,6 +66,13 @@ describe('Reports Page', () => {
6266
})
6367
);
6468

69+
beforeEach(() => {
70+
durationTime = new Date().setHours(5, 30);
71+
row = 0;
72+
node = 0;
73+
decimalValidator = /^\d+\.\d{0,2}$/;
74+
});
75+
6576
it('component should be created', async () => {
6677
expect(component).toBeTruthy();
6778
});
@@ -107,6 +118,17 @@ describe('Reports Page', () => {
107118
});
108119
});
109120

121+
it('The data should be displayed as a multiple of hour when column is equal to 3', () => {
122+
const column = 3;
123+
124+
expect(component.bodyExportOptions(durationTime, row, column, node)).toMatch(decimalValidator);
125+
});
126+
127+
it('The data should not be displayed as a multiple of hour when column is different of 3', () => {
128+
const column = 4;
129+
expect(component.bodyExportOptions(durationTime, row, column, node)).toBe(durationTime);
130+
});
131+
110132
afterEach(() => {
111133
fixture.destroy();
112134
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { formatDate } from '@angular/common';
22
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
33
import { select, Store } from '@ngrx/store';
44
import { DataTableDirective } from 'angular-datatables';
5+
import * as moment from 'moment';
56
import { Observable, Subject, Subscription } from 'rxjs';
67
import { Entry } from 'src/app/modules/shared/models';
78
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
@@ -28,11 +29,21 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
2829
},
2930
{
3031
extend: 'excel',
32+
exportOptions: {
33+
format: {
34+
body: this.bodyExportOptions
35+
}
36+
},
3137
text: 'Excel',
3238
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
3339
},
3440
{
3541
extend: 'csv',
42+
exportOptions: {
43+
format: {
44+
body: this.bodyExportOptions
45+
}
46+
},
3647
text: 'CSV',
3748
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
3849
},
@@ -83,4 +94,9 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8394
const regex = new RegExp('http*', 'g');
8495
return regex.test(uri);
8596
}
97+
98+
bodyExportOptions(data, row, column, node){
99+
const durationColumnIndex = 3;
100+
return column === durationColumnIndex ? moment.duration(data).asHours().toFixed(2) : data;
101+
}
86102
}

0 commit comments

Comments
 (0)