Skip to content

Commit

Permalink
fix: add gantt view test
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball committed Jan 21, 2021
1 parent f42b7fa commit e25a5b0
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
15 changes: 14 additions & 1 deletion packages/gantt/src/gantt-upper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { Input, TemplateRef, Output, EventEmitter, ContentChild, ElementRef, HostBinding, ChangeDetectorRef, NgZone, SimpleChanges, InjectionToken, Directive } from '@angular/core';
import {
Input,
TemplateRef,
Output,
EventEmitter,
ContentChild,
ElementRef,
HostBinding,
ChangeDetectorRef,
NgZone,
SimpleChanges,
InjectionToken,
Directive
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil, take, skip } from 'rxjs/operators';
import {
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/gantt/src/views/day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class GanttViewDay extends GanttView {
return this.getCellWidth() * 7;
}

getDayOccupancyWidth(date: GanttDate): number {
getDayOccupancyWidth(): number {
return this.cellWidth;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/gantt/src/views/quarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GanttViewQuarter extends GanttView {
getPrimaryDatePoints(): GanttDatePoint[] {
const years = eachYearOfInterval({ start: this.start.value, end: this.end.value });
const points: GanttDatePoint[] = [];
for (let i = 0; i <= years.length; i++) {
for (let i = 0; i < years.length; i++) {
const start = new GanttDate(years[i]);
const point = new GanttDatePoint(
start,
Expand All @@ -47,7 +47,6 @@ export class GanttViewQuarter extends GanttView {
);
points.push(point);
}

return points;
}

Expand Down
86 changes: 86 additions & 0 deletions packages/gantt/src/views/test/view.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { GanttViewMonth } from '../month';
import { GanttViewDay } from '../day';
import { GanttDate } from '../../utils/date';
import { GanttViewQuarter } from '../quarter';

const date = {
start: {
date: new GanttDate(1577808000),
isCustom: true
},
end: {
date: new GanttDate(1609344000),
isCustom: true
}
};

const options = {
cellWidth: 20
};

describe('GanttView', () => {
let ganttViewDay: GanttViewDay;
let ganttViewMonth: GanttViewMonth;
let ganttViewQuarter: GanttViewQuarter;

beforeEach(() => {
ganttViewDay = new GanttViewDay(date.start, date.end, options);
ganttViewMonth = new GanttViewMonth(date.start, date.end, { cellWidth: 310 });
ganttViewQuarter = new GanttViewQuarter(date.start, date.end, { cellWidth: 910 });
});

it(`should has correct view start`, () => {
const startOfDay = ganttViewDay.startOf(date.start.date).getUnixTime();
const startOfMonth = ganttViewMonth.startOf(date.start.date).getUnixTime();
const startOfQuarter = ganttViewQuarter.startOf(date.start.date).getUnixTime();

expect(startOfDay).toEqual(1577635200);
expect(startOfMonth).toEqual(1577808000);
expect(startOfQuarter).toEqual(1577808000);
});

it(`should has correct view end`, () => {
const endOfDay = ganttViewDay.endOf(date.end.date).getUnixTime();
const endOfMonth = ganttViewMonth.endOf(date.end.date).getUnixTime();
const endOfQuarter = ganttViewQuarter.endOf(date.end.date).getUnixTime();
expect(endOfDay).toEqual(1609689599);
expect(endOfMonth).toEqual(1609430399);
expect(endOfQuarter).toEqual(1609430399);
});

it(`should has correct cell width`, () => {
const dayCellWidth = ganttViewDay.getDayOccupancyWidth();
const monthCellWidth = ganttViewMonth.getDayOccupancyWidth(date.start.date);
const quarterCellWidth = ganttViewQuarter.getDayOccupancyWidth(date.start.date);
expect(dayCellWidth).toEqual(20);
expect(monthCellWidth).toEqual(10);
expect(quarterCellWidth).toEqual(10);
});

it(`should has correct primary width`, () => {
const dayPrimaryWidth = ganttViewDay.getPrimaryWidth();
const monthPrimaryWidth = ganttViewMonth.getPrimaryWidth();
const quarterPrimaryWidth = ganttViewQuarter.getPrimaryWidth();
expect(dayPrimaryWidth).toEqual(140);
expect(monthPrimaryWidth).toEqual(930);
expect(quarterPrimaryWidth).toEqual(3640);
});

it(`should has correct primary date points`, () => {
const dayPoints = ganttViewDay.getPrimaryDatePoints();
const monthPoints = ganttViewMonth.getPrimaryDatePoints();
const quarterPoints = ganttViewQuarter.getPrimaryDatePoints();
expect(dayPoints.length).toBe(54);
expect(monthPoints.length).toBe(4);
expect(quarterPoints.length).toBe(1);
});

it(`should has correct secondary date points`, () => {
const dayPoints = ganttViewDay.getSecondaryDatePoints();
const monthPoints = ganttViewMonth.getSecondaryDatePoints();
const quarterPoints = ganttViewQuarter.getSecondaryDatePoints();
expect(dayPoints.length).toBe(371);
expect(monthPoints.length).toBe(12);
expect(quarterPoints.length).toBe(4);
});
});

0 comments on commit e25a5b0

Please sign in to comment.