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
fix: TT-593 unit test coverage
  • Loading branch information
wilc0519 committed Apr 27, 2022
commit 1d5656afb89055c4a1547d0e2de07e155eeca96b
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { DataTableDirective } from 'angular-datatables';
import { DataTablesModule } from 'angular-datatables';
import { NgxPaginationModule } from 'ngx-pagination';
import { Entry } from 'src/app/modules/shared/models';
import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/substract-date.pipe';
import { getReportDataSource } from 'src/app/modules/time-clock/store/entry.selectors';
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Reports Page', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [],
imports: [NgxPaginationModule, DataTablesModule],
declarations: [TimeEntriesTableComponent, SubstractDatePipe],
providers: [provideMockStore({ initialState: state })],
}).compileComponents();
Expand Down Expand Up @@ -85,7 +86,9 @@ describe('Reports Page', () => {
});

it('after the component is initialized it should initialize the table', () => {
component.dtElement = null;
spyOn(component.dtTrigger, 'next');

component.ngAfterViewInit();

expect(component.dtTrigger.next).toHaveBeenCalled();
Expand Down Expand Up @@ -137,11 +140,6 @@ describe('Reports Page', () => {

it('when the rerenderDataTable method is called and dtElement and dtInstance are defined, the destroy and next methods are called ',
() => {
component.dtElement = {
dtInstance: {
then : (dtInstance: DataTables.Api) => { dtInstance.destroy(); }
}
} as unknown as DataTableDirective;
spyOn(component.dtElement.dtInstance, 'then');
component.ngAfterViewInit();
expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { ParseDateTimeOffset } from './parse-date-time-offset';
describe('ParseDateToUtcComponent', () => {

it('returns converted date when his offset is 300', () => {
let parseTimeOffset = new ParseDateTimeOffset();
const parseTimeOffset = new ParseDateTimeOffset();
const date = '2022-03-30T13:00:00Z';
const timezone_offset = 300;
const dateOffset:string = '08:00';
const timezoneOffset = 300;
const dateOffset = '08:00';

expect(parseTimeOffset.parseDateTimeOffset(date, timezone_offset)).toEqual(dateOffset);
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual(dateOffset);
});

it('returns converted date when his offset is 420', () => {
let parseTimeOffset = new ParseDateTimeOffset();
const parseTimeOffset = new ParseDateTimeOffset();
const date = '2022-03-30T16:30:00Z';
const timezone_offset = 420;
const dateOffset:string = '09:30';
const timezoneOffset = 420;
const dateOffset = '09:30';

expect(parseTimeOffset.parseDateTimeOffset(date, timezone_offset)).toEqual(dateOffset);
expect(parseTimeOffset.parseDateTimeOffset(date, timezoneOffset)).toEqual(dateOffset);
});

});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as moment from 'moment';

export class ParseDateTimeOffset {
parseDateTimeOffset(date:string, offset): string{
return moment.utc(date).utcOffset(-1*offset).format("HH:mm");

parseDateTimeOffset(date: string, offset): string {
return moment.utc(date).utcOffset(-1 * offset).format('HH:mm');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
isActiveEntryOverlapping = false;
calendarView: CalendarView = CalendarView.Month;
actualDate: Date;
dateTimeOffset : ParseDateTimeOffset;
dateTimeOffset: ParseDateTimeOffset;
constructor(
private store: Store<EntryState>,
private toastrService: ToastrService,
Expand Down