Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ describe('Reports Page', () => {
let fixture: ComponentFixture<TimeEntriesTableComponent>;
let store: MockStore<EntryState>;
let getReportDataSourceSelectorMock;
let durationTime: number;
let row: number;
let node: number;
let decimalValidator: RegExp;
const timeEntry: Entry = {
id: '123',
start_date: new Date(),
Expand Down Expand Up @@ -62,6 +66,13 @@ describe('Reports Page', () => {
})
);

beforeEach(() => {
durationTime = new Date().setHours(5, 30);
row = 0;
node = 0;
decimalValidator = /^\d+\.\d{0,2}$/;
});

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

it('The data should be displayed as a multiple of hour when column is equal to 3', () => {
const column = 3;

expect(component.bodyExportOptions(durationTime, row, column, node)).toMatch(decimalValidator);
});

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

afterEach(() => {
fixture.destroy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { formatDate } from '@angular/common';
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import { select, Store } from '@ngrx/store';
import { DataTableDirective } from 'angular-datatables';
import * as moment from 'moment';
import { Observable, Subject, Subscription } from 'rxjs';
import { Entry } from 'src/app/modules/shared/models';
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
Expand All @@ -28,11 +29,21 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
},
{
extend: 'excel',
exportOptions: {
format: {
body: this.bodyExportOptions
}
},
text: 'Excel',
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
},
{
extend: 'csv',
exportOptions: {
format: {
body: this.bodyExportOptions
}
},
text: 'CSV',
filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}`
},
Expand Down Expand Up @@ -83,4 +94,9 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
const regex = new RegExp('http*', 'g');
return regex.test(uri);
}

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