@worktile/gantt 11.0.2 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.all-contributorsrc +53 -0
- package/.angulardoc.json +4 -0
- package/.circleci/config.yml +17 -0
- package/.coveralls.yml +1 -0
- package/.docgenirc.js +64 -0
- package/.editorconfig +22 -0
- package/.prettierrc +24 -0
- package/.travis.yml +23 -0
- package/CHANGELOG.md +564 -0
- package/Dockerfile +4 -0
- package/LICENSE +21 -0
- package/README.md +116 -13
- package/angular.json +136 -0
- package/docs/guides/basic/components.md +54 -0
- package/docs/guides/basic/event.md +70 -0
- package/docs/guides/basic/index.md +4 -0
- package/docs/guides/basic/style.md +68 -0
- package/docs/guides/basic/type.md +70 -0
- package/docs/guides/basic/usage.md +189 -0
- package/docs/guides/index.md +5 -0
- package/docs/guides/intro/getting-started.md +79 -0
- package/docs/guides/intro/index.md +51 -0
- package/docs/index.md +0 -0
- package/example/browserslist +12 -0
- package/example/src/app/app-routing.module.ts +26 -0
- package/example/src/app/app.component.html +2 -0
- package/example/src/app/app.component.ts +11 -0
- package/example/src/app/app.module.ts +57 -0
- package/example/src/app/components/components.component.html +6 -0
- package/example/src/app/components/components.component.ts +33 -0
- package/example/src/app/configuration/parameters/api/zh-cn.js +350 -0
- package/example/src/app/configuration/parameters/doc/zh-cn.md +5 -0
- package/example/src/app/gantt/gantt.component.html +51 -0
- package/example/src/app/gantt/gantt.component.ts +119 -0
- package/example/src/app/gantt-advanced/component/flat.component.html +30 -0
- package/example/src/app/gantt-advanced/component/flat.component.ts +72 -0
- package/example/src/app/gantt-advanced/component/flat.scss +31 -0
- package/example/src/app/gantt-advanced/gantt-advanced.component.html +32 -0
- package/example/src/app/gantt-advanced/gantt-advanced.component.ts +34 -0
- package/example/src/app/gantt-advanced/mocks.ts +158 -0
- package/example/src/app/gantt-groups/gantt-groups.component.html +42 -0
- package/example/src/app/gantt-groups/gantt-groups.component.ts +62 -0
- package/example/src/app/gantt-range/gantt-range.component.html +66 -0
- package/example/src/app/gantt-range/gantt-range.component.ts +67 -0
- package/example/src/app/gantt-range/mocks.ts +150 -0
- package/example/src/app/helper.ts +38 -0
- package/example/src/assets/.gitkeep +0 -0
- package/example/src/environments/environment.prod.ts +3 -0
- package/example/src/environments/environment.ts +16 -0
- package/example/src/favicon.ico +0 -0
- package/example/src/index.html +13 -0
- package/example/src/main.ts +12 -0
- package/example/src/polyfills.ts +63 -0
- package/example/src/styles.scss +56 -0
- package/example/tsconfig.app.json +18 -0
- package/nginx.conf +17 -0
- package/package.json +113 -17
- package/packages/gantt/README.md +24 -0
- package/packages/gantt/karma.conf.js +46 -0
- package/packages/gantt/ng-package.json +7 -0
- package/packages/gantt/ng-package.prod.json +7 -0
- package/packages/gantt/package.json +16 -0
- package/packages/gantt/src/class/date-point.ts +14 -0
- package/{class/event.d.ts → packages/gantt/src/class/event.ts} +12 -6
- package/packages/gantt/src/class/group.ts +36 -0
- package/{class/index.d.ts → packages/gantt/src/class/index.ts} +0 -0
- package/packages/gantt/src/class/item.ts +129 -0
- package/packages/gantt/src/class/test/group.spec.ts +21 -0
- package/packages/gantt/src/class/test/item.spec.ts +102 -0
- package/packages/gantt/src/class/view-type.ts +7 -0
- package/packages/gantt/src/components/bar/bar-drag.ts +298 -0
- package/packages/gantt/src/components/bar/bar.component.html +17 -0
- package/packages/gantt/src/components/bar/bar.component.scss +169 -0
- package/packages/gantt/src/components/bar/bar.component.ts +109 -0
- package/packages/gantt/src/components/bar/test/bar.component.spec.ts +54 -0
- package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +196 -0
- package/packages/gantt/src/components/calendar/calendar.component.html +52 -0
- package/packages/gantt/src/components/calendar/calendar.component.scss +77 -0
- package/packages/gantt/src/components/calendar/calendar.component.ts +100 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +6 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +48 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +13 -0
- package/packages/gantt/src/components/icon/icon.component.scss +13 -0
- package/packages/gantt/src/components/icon/icon.component.ts +28 -0
- package/packages/gantt/src/components/icon/icons.ts +86 -0
- package/packages/gantt/src/components/links/links.component.html +19 -0
- package/packages/gantt/src/components/links/links.component.scss +27 -0
- package/packages/gantt/src/components/links/links.component.ts +263 -0
- package/packages/gantt/src/components/main/gantt-main.component.html +35 -0
- package/packages/gantt/src/components/main/gantt-main.component.ts +35 -0
- package/packages/gantt/src/components/range/range.component.html +8 -0
- package/packages/gantt/src/components/range/range.component.scss +35 -0
- package/packages/gantt/src/components/range/range.component.ts +27 -0
- package/packages/gantt/src/components/range/test/range.component.spec.ts +80 -0
- package/packages/gantt/src/components/table/gantt-table.component.html +105 -0
- package/packages/gantt/src/components/table/gantt-table.component.scss +144 -0
- package/packages/gantt/src/components/table/gantt-table.component.ts +166 -0
- package/packages/gantt/src/components/table/test/table.spec.ts +129 -0
- package/packages/gantt/src/gantt-abstract.ts +14 -0
- package/packages/gantt/src/gantt-dom.service.ts +134 -0
- package/packages/gantt/src/gantt-drag-container.ts +73 -0
- package/packages/gantt/src/gantt-item-upper.ts +50 -0
- package/packages/gantt/src/gantt-print.service.ts +104 -0
- package/packages/gantt/src/gantt-upper.ts +289 -0
- package/packages/gantt/src/gantt.component.html +18 -0
- package/packages/gantt/src/gantt.component.scss +77 -0
- package/packages/gantt/src/gantt.component.ts +134 -0
- package/packages/gantt/src/gantt.module.ts +47 -0
- package/packages/gantt/src/gantt.pipe.ts +31 -0
- package/packages/gantt/src/gantt.styles.ts +28 -0
- package/{public-api.d.ts → packages/gantt/src/public-api.ts} +6 -0
- package/packages/gantt/src/root.component.html +12 -0
- package/packages/gantt/src/root.component.ts +121 -0
- package/packages/gantt/src/styles/index.scss +9 -0
- package/packages/gantt/src/styles/variables.scss +46 -0
- package/packages/gantt/src/table/gantt-column.component.ts +25 -0
- package/packages/gantt/src/table/gantt-table.component.ts +14 -0
- package/packages/gantt/src/table/test/table.spec.ts +56 -0
- package/packages/gantt/src/test/gantt.component.spec.ts +404 -0
- package/packages/gantt/src/test/mocks/data.ts +303 -0
- package/packages/gantt/src/test.ts +21 -0
- package/packages/gantt/src/utils/date.ts +276 -0
- package/packages/gantt/src/utils/helpers.ts +66 -0
- package/packages/gantt/src/utils/test/date.spec.ts +105 -0
- package/packages/gantt/src/utils/test/helpers.spec.ts +73 -0
- package/packages/gantt/src/utils/testing.ts +64 -0
- package/packages/gantt/src/views/day.ts +74 -0
- package/packages/gantt/src/views/factory.ts +25 -0
- package/packages/gantt/src/views/month.ts +66 -0
- package/packages/gantt/src/views/quarter.ts +68 -0
- package/packages/gantt/src/views/test/day.spec.ts +45 -0
- package/packages/gantt/src/views/test/factory.spec.ts +41 -0
- package/packages/gantt/src/views/test/mock.ts +14 -0
- package/packages/gantt/src/views/test/month.spec.ts +45 -0
- package/packages/gantt/src/views/test/quarter.spec.ts +45 -0
- package/packages/gantt/src/views/test/view.spec.ts +144 -0
- package/packages/gantt/src/views/test/week.spec.ts +45 -0
- package/packages/gantt/src/views/test/year.spec.ts +45 -0
- package/packages/gantt/src/views/view.ts +186 -0
- package/packages/gantt/src/views/week.ts +66 -0
- package/packages/gantt/src/views/year.ts +62 -0
- package/packages/gantt/tsconfig.lib.json +20 -0
- package/packages/gantt/tsconfig.lib.prod.json +9 -0
- package/packages/gantt/tsconfig.schematics.json +25 -0
- package/packages/gantt/tsconfig.spec.json +17 -0
- package/packages/gantt/tslint.json +18 -0
- package/scss-bundle.config.json +7 -0
- package/tsconfig.json +26 -0
- package/tslint.json +51 -0
- package/bundles/worktile-gantt.umd.js +0 -3129
- package/bundles/worktile-gantt.umd.js.map +0 -1
- package/bundles/worktile-gantt.umd.min.js +0 -16
- package/bundles/worktile-gantt.umd.min.js.map +0 -1
- package/class/date-point.d.ts +0 -15
- package/class/group.d.ts +0 -22
- package/class/item.d.ts +0 -70
- package/class/view-type.d.ts +0 -7
- package/components/bar/bar-drag.d.ts +0 -34
- package/components/bar/bar.component.d.ts +0 -23
- package/components/calendar/calendar.component.d.ts +0 -25
- package/components/drag-backdrop/drag-backdrop.component.d.ts +0 -6
- package/components/icon/icon.component.d.ts +0 -10
- package/components/icon/icons.d.ts +0 -8
- package/components/links/links.component.d.ts +0 -44
- package/components/main/gantt-main.component.d.ts +0 -18
- package/components/range/range.component.d.ts +0 -10
- package/components/table/gantt-table.component.d.ts +0 -31
- package/esm2015/class/date-point.js +0 -10
- package/esm2015/class/event.js +0 -13
- package/esm2015/class/group.js +0 -17
- package/esm2015/class/index.js +0 -6
- package/esm2015/class/item.js +0 -78
- package/esm2015/class/view-type.js +0 -9
- package/esm2015/components/bar/bar-drag.js +0 -266
- package/esm2015/components/bar/bar.component.js +0 -91
- package/esm2015/components/calendar/calendar.component.js +0 -82
- package/esm2015/components/drag-backdrop/drag-backdrop.component.js +0 -18
- package/esm2015/components/icon/icon.component.js +0 -36
- package/esm2015/components/icon/icons.js +0 -87
- package/esm2015/components/links/links.component.js +0 -207
- package/esm2015/components/main/gantt-main.component.js +0 -35
- package/esm2015/components/range/range.component.js +0 -32
- package/esm2015/components/table/gantt-table.component.js +0 -128
- package/esm2015/gantt-dom.service.js +0 -101
- package/esm2015/gantt-drag-container.js +0 -57
- package/esm2015/gantt-item-upper.js +0 -55
- package/esm2015/gantt-print.service.js +0 -92
- package/esm2015/gantt-upper.js +0 -231
- package/esm2015/gantt.component.js +0 -105
- package/esm2015/gantt.module.js +0 -43
- package/esm2015/gantt.pipe.js +0 -33
- package/esm2015/gantt.styles.js +0 -15
- package/esm2015/public-api.js +0 -16
- package/esm2015/root.component.js +0 -111
- package/esm2015/table/gantt-column.component.js +0 -28
- package/esm2015/table/gantt-table.component.js +0 -18
- package/esm2015/utils/date.js +0 -160
- package/esm2015/utils/helpers.js +0 -45
- package/esm2015/views/day.js +0 -54
- package/esm2015/views/factory.js +0 -23
- package/esm2015/views/month.js +0 -48
- package/esm2015/views/quarter.js +0 -51
- package/esm2015/views/view.js +0 -121
- package/esm2015/views/week.js +0 -49
- package/esm2015/views/year.js +0 -50
- package/esm2015/worktile-gantt.js +0 -16
- package/fesm2015/worktile-gantt.js +0 -2491
- package/fesm2015/worktile-gantt.js.map +0 -1
- package/gantt-dom.service.d.ts +0 -29
- package/gantt-drag-container.d.ts +0 -20
- package/gantt-item-upper.d.ts +0 -17
- package/gantt-print.service.d.ts +0 -10
- package/gantt-upper.d.ts +0 -62
- package/gantt.component.d.ts +0 -28
- package/gantt.module.d.ts +0 -2
- package/gantt.pipe.d.ts +0 -11
- package/gantt.styles.d.ts +0 -15
- package/root.component.d.ts +0 -25
- package/style.scss +0 -645
- package/table/gantt-column.component.d.ts +0 -12
- package/table/gantt-table.component.d.ts +0 -7
- package/utils/date.d.ts +0 -59
- package/utils/helpers.d.ts +0 -11
- package/views/day.d.ts +0 -14
- package/views/factory.d.ts +0 -8
- package/views/month.d.ts +0 -12
- package/views/quarter.d.ts +0 -12
- package/views/view.d.ts +0 -56
- package/views/week.d.ts +0 -12
- package/views/year.d.ts +0 -12
- package/worktile-gantt.d.ts +0 -15
- package/worktile-gantt.metadata.json +0 -1
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { GanttGroupInternal } from './../class/group';
|
|
2
|
+
import { GanttItemInternal } from './../class/item';
|
|
3
|
+
import { Component, DebugElement, ViewChild } from '@angular/core';
|
|
4
|
+
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
|
5
|
+
import { By } from '@angular/platform-browser';
|
|
6
|
+
import { GanttBarClickEvent, GanttGroup, GanttItem } from '../class';
|
|
7
|
+
import { GanttViewType } from '../class/view-type';
|
|
8
|
+
import { GanttPrintService } from '../gantt-print.service';
|
|
9
|
+
import { NgxGanttComponent } from '../gantt.component';
|
|
10
|
+
import { NgxGanttModule } from '../gantt.module';
|
|
11
|
+
import { GanttDate } from '../utils/date';
|
|
12
|
+
import { getMockGroupItems, getMockGroups, getMockItems } from './mocks/data';
|
|
13
|
+
import { CommonModule } from '@angular/common';
|
|
14
|
+
import { GanttCalendarComponent } from '../components/calendar/calendar.component';
|
|
15
|
+
import { NgxGanttBarComponent } from '../components/bar/bar.component';
|
|
16
|
+
import { GanttIconComponent } from '../components/icon/icon.component';
|
|
17
|
+
import { NgxGanttRootComponent } from '../root.component';
|
|
18
|
+
import { of } from 'rxjs';
|
|
19
|
+
import { delay } from 'rxjs/operators';
|
|
20
|
+
|
|
21
|
+
const mockItems = getMockItems();
|
|
22
|
+
const mockGroupItems = getMockGroupItems();
|
|
23
|
+
const mockGroups = getMockGroups();
|
|
24
|
+
|
|
25
|
+
// Basic Component
|
|
26
|
+
@Component({
|
|
27
|
+
selector: 'test-gantt-basic',
|
|
28
|
+
template: ` <ngx-gantt #gantt [start]="start" [end]="end" [items]="items" [viewType]="viewType" (barClick)="barClick($event)">
|
|
29
|
+
<ngx-gantt-table>
|
|
30
|
+
<ngx-gantt-column name="标题" width="200px">
|
|
31
|
+
<ng-template #cell let-item="item">
|
|
32
|
+
{{ item.title }}
|
|
33
|
+
</ng-template>
|
|
34
|
+
</ngx-gantt-column>
|
|
35
|
+
</ngx-gantt-table>
|
|
36
|
+
</ngx-gantt>`
|
|
37
|
+
})
|
|
38
|
+
export class TestGanttBasicComponent {
|
|
39
|
+
@ViewChild('gantt') ganttComponent: NgxGanttComponent;
|
|
40
|
+
|
|
41
|
+
constructor() {}
|
|
42
|
+
|
|
43
|
+
start = new GanttDate('2020-09-02 00:00:00').getUnixTime();
|
|
44
|
+
|
|
45
|
+
end = new GanttDate('2021-12-01 00:00:00').getUnixTime();
|
|
46
|
+
|
|
47
|
+
viewType = 'month';
|
|
48
|
+
|
|
49
|
+
items = mockItems;
|
|
50
|
+
|
|
51
|
+
barClick(event: GanttBarClickEvent) {
|
|
52
|
+
console.log(event);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// With Group Component
|
|
57
|
+
@Component({
|
|
58
|
+
selector: 'test-gantt-with-groups',
|
|
59
|
+
template: ` <button class="expand" (click)="gantt.expandAll()">全部展开</button>
|
|
60
|
+
<button class="collapse" (click)="gantt.collapseAll()">全部收起</button>
|
|
61
|
+
<ngx-gantt #gantt [groups]="groups" [items]="items" [viewType]="viewType" [disabledLoadOnScroll]="true">
|
|
62
|
+
<ng-template #groupHeader let-group="group">
|
|
63
|
+
<div class="test-gantt-with-groups-group-header"></div>
|
|
64
|
+
</ng-template>
|
|
65
|
+
<ng-template #group let-group="group">
|
|
66
|
+
<div class="test-gantt-with-groups-group"></div>
|
|
67
|
+
</ng-template>
|
|
68
|
+
<ngx-gantt-table>
|
|
69
|
+
<ngx-gantt-column name="标题" width="200px">
|
|
70
|
+
<ng-template #cell let-item="item">
|
|
71
|
+
{{ item.title }}
|
|
72
|
+
</ng-template>
|
|
73
|
+
</ngx-gantt-column>
|
|
74
|
+
</ngx-gantt-table>
|
|
75
|
+
</ngx-gantt>`
|
|
76
|
+
})
|
|
77
|
+
export class TestGanttWithGroupsComponent {
|
|
78
|
+
@ViewChild('gantt') ganttComponent: NgxGanttComponent;
|
|
79
|
+
|
|
80
|
+
constructor() {}
|
|
81
|
+
|
|
82
|
+
viewType = 'month';
|
|
83
|
+
|
|
84
|
+
groups = mockGroups;
|
|
85
|
+
|
|
86
|
+
items = mockGroupItems;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// load children
|
|
90
|
+
@Component({
|
|
91
|
+
selector: 'test-gantt-load-children',
|
|
92
|
+
template: ` <ngx-gantt #gantt [items]="items" [viewType]="viewType" [async]="async" [childrenResolve]="childrenResolve">
|
|
93
|
+
<ngx-gantt-table>
|
|
94
|
+
<ngx-gantt-column name="标题" width="200px">
|
|
95
|
+
<ng-template #cell let-item="item">
|
|
96
|
+
{{ item.title }}
|
|
97
|
+
</ng-template>
|
|
98
|
+
</ngx-gantt-column>
|
|
99
|
+
</ngx-gantt-table>
|
|
100
|
+
</ngx-gantt>`
|
|
101
|
+
})
|
|
102
|
+
export class TestGanttLoadChildrenComponent {
|
|
103
|
+
@ViewChild('gantt') ganttComponent: NgxGanttComponent;
|
|
104
|
+
|
|
105
|
+
constructor() {}
|
|
106
|
+
|
|
107
|
+
viewType = 'month';
|
|
108
|
+
|
|
109
|
+
items = mockItems;
|
|
110
|
+
|
|
111
|
+
async = false;
|
|
112
|
+
|
|
113
|
+
childrenResolve = this.getChildren.bind(this);
|
|
114
|
+
|
|
115
|
+
getChildren() {
|
|
116
|
+
return of([
|
|
117
|
+
{
|
|
118
|
+
id: new Date().getTime(),
|
|
119
|
+
title: new Date().getTime(),
|
|
120
|
+
start: Math.floor(new Date().getTime() / 1000),
|
|
121
|
+
draggable: true,
|
|
122
|
+
linkable: false
|
|
123
|
+
}
|
|
124
|
+
]).pipe(delay(1000));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface TestGanttComponentBase {
|
|
129
|
+
ganttComponent: NgxGanttComponent;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function assertGanttView<T extends TestGanttComponentBase>(
|
|
133
|
+
fixture: ComponentFixture<T>,
|
|
134
|
+
expected: {
|
|
135
|
+
firstPrimaryDataPointText: string;
|
|
136
|
+
lastPrimaryDataPointText: string;
|
|
137
|
+
firstSecondaryDataPointText: string;
|
|
138
|
+
lastSecondaryDataPointText: string;
|
|
139
|
+
}
|
|
140
|
+
) {
|
|
141
|
+
const calendarElement = fixture.debugElement.query(By.directive(GanttCalendarComponent));
|
|
142
|
+
const primaryElements = calendarElement.queryAll(By.css('.primary-text'));
|
|
143
|
+
const secondaryElements = calendarElement.queryAll(By.css('.secondary-text'));
|
|
144
|
+
expect(primaryElements.length).toEqual(fixture.componentInstance.ganttComponent.view.primaryDatePoints.length);
|
|
145
|
+
expect(secondaryElements.length).toEqual(fixture.componentInstance.ganttComponent.view.secondaryDatePoints.length);
|
|
146
|
+
expect(primaryElements[0].nativeElement.textContent).toContain(expected.firstPrimaryDataPointText);
|
|
147
|
+
expect(primaryElements[primaryElements.length - 1].nativeElement.textContent).toContain(expected.lastPrimaryDataPointText);
|
|
148
|
+
expect(secondaryElements[0].nativeElement.textContent).toContain(expected.firstSecondaryDataPointText);
|
|
149
|
+
expect(secondaryElements[secondaryElements.length - 1].nativeElement.textContent).toContain(expected.lastSecondaryDataPointText);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function assertItem(item: DebugElement, ganttItem: GanttItemInternal) {
|
|
153
|
+
const elem = item.nativeElement as HTMLElement;
|
|
154
|
+
const top = elem.style.getPropertyValue('top');
|
|
155
|
+
const left = elem.style.getPropertyValue('left');
|
|
156
|
+
const width = elem.style.getPropertyValue('width');
|
|
157
|
+
expect(top).toEqual(ganttItem.refs.y + 'px');
|
|
158
|
+
expect(left).toEqual(ganttItem.refs.x + 'px');
|
|
159
|
+
expect(width).toEqual(ganttItem.refs.width + 'px');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function assertItems<T extends TestGanttComponentBase>(fixture: ComponentFixture<T>, expectedItems: GanttItem[]) {
|
|
163
|
+
const ganttComponent = fixture.componentInstance.ganttComponent;
|
|
164
|
+
const items = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent));
|
|
165
|
+
expect(items.length).toEqual(expectedItems.length);
|
|
166
|
+
items.forEach((item: DebugElement, index: number) => {
|
|
167
|
+
expect(ganttComponent.items[index].id).toEqual(expectedItems[index].id);
|
|
168
|
+
assertItem(item, ganttComponent.items[index]);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function assertGroups<T extends TestGanttComponentBase>(fixture: ComponentFixture<T>, expectedGroups: GanttGroup[]) {
|
|
173
|
+
const ganttComponent = fixture.componentInstance.ganttComponent;
|
|
174
|
+
const groups = fixture.debugElement.queryAll(By.css('.gantt-group'));
|
|
175
|
+
groups.forEach((group: DebugElement, groupIndex: number) => {
|
|
176
|
+
expect(ganttComponent.groups[groupIndex].id).toEqual(expectedGroups[groupIndex].id);
|
|
177
|
+
const items = group.queryAll(By.directive(NgxGanttBarComponent));
|
|
178
|
+
items.forEach((item: DebugElement, itemIndex: number) => {
|
|
179
|
+
assertItem(item, ganttComponent.groups[groupIndex].items[itemIndex]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
describe('ngx-gantt', () => {
|
|
185
|
+
describe('#basic', () => {
|
|
186
|
+
let fixture: ComponentFixture<TestGanttBasicComponent>;
|
|
187
|
+
let ganttComponentInstance: TestGanttBasicComponent;
|
|
188
|
+
let ganttDebugElement: DebugElement;
|
|
189
|
+
let ganttComponent: NgxGanttComponent;
|
|
190
|
+
|
|
191
|
+
beforeEach(async () => {
|
|
192
|
+
TestBed.configureTestingModule({
|
|
193
|
+
imports: [CommonModule, NgxGanttModule],
|
|
194
|
+
declarations: [TestGanttBasicComponent],
|
|
195
|
+
providers: [GanttPrintService]
|
|
196
|
+
}).compileComponents();
|
|
197
|
+
fixture = TestBed.createComponent(TestGanttBasicComponent);
|
|
198
|
+
fixture.detectChanges();
|
|
199
|
+
ganttDebugElement = fixture.debugElement.query(By.directive(NgxGanttComponent));
|
|
200
|
+
ganttComponentInstance = fixture.componentInstance;
|
|
201
|
+
ganttComponent = ganttComponentInstance.ganttComponent;
|
|
202
|
+
fixture.detectChanges();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should create ganttComponent', () => {
|
|
206
|
+
expect(ganttComponentInstance).toBeTruthy();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should render month view', () => {
|
|
210
|
+
assertGanttView(fixture, {
|
|
211
|
+
firstPrimaryDataPointText: '2020年Q3',
|
|
212
|
+
lastPrimaryDataPointText: '2021年Q4',
|
|
213
|
+
firstSecondaryDataPointText: '7月',
|
|
214
|
+
lastSecondaryDataPointText: '12月'
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should render items', () => {
|
|
219
|
+
assertItems(fixture, mockItems);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should bar click', fakeAsync(() => {
|
|
223
|
+
const barClickSpy = spyOn(ganttComponentInstance, 'barClick').and.callFake((event: GanttBarClickEvent) => {
|
|
224
|
+
expect(event.event.type).toEqual('click');
|
|
225
|
+
expect(event.item.title).toEqual(mockItems[0].title);
|
|
226
|
+
});
|
|
227
|
+
const bar = fixture.debugElement.query(By.directive(NgxGanttBarComponent)).query(By.css('.gantt-bar-content'));
|
|
228
|
+
bar.nativeElement.click();
|
|
229
|
+
expect(barClickSpy).toHaveBeenCalledTimes(1);
|
|
230
|
+
}));
|
|
231
|
+
|
|
232
|
+
it('should register print service', () => {
|
|
233
|
+
expect(TestBed.inject(GanttPrintService)['root']).toEqual(
|
|
234
|
+
ganttDebugElement.query(By.directive(NgxGanttRootComponent)).nativeElement
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should re render view when change view type', () => {
|
|
239
|
+
ganttComponentInstance.viewType = GanttViewType.day;
|
|
240
|
+
fixture.detectChanges();
|
|
241
|
+
assertGanttView(fixture, {
|
|
242
|
+
firstPrimaryDataPointText: '2020年09月',
|
|
243
|
+
lastPrimaryDataPointText: '2021年12月',
|
|
244
|
+
firstSecondaryDataPointText: '31',
|
|
245
|
+
lastSecondaryDataPointText: '5'
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('should re render items when change items', () => {
|
|
250
|
+
const newItems = mockItems.slice(0, 5);
|
|
251
|
+
ganttComponentInstance.items = [...newItems];
|
|
252
|
+
fixture.detectChanges();
|
|
253
|
+
assertItems(fixture, newItems);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('should has empty class when has no items', () => {
|
|
257
|
+
ganttComponentInstance.items = [];
|
|
258
|
+
fixture.detectChanges();
|
|
259
|
+
const ganttTableElement = ganttDebugElement.query(By.css('.gantt-table'));
|
|
260
|
+
expect(ganttTableElement.nativeElement.classList).toContain('gantt-table-empty');
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should re render when scroll load', () => {});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('#with groups', () => {
|
|
267
|
+
let fixture: ComponentFixture<TestGanttWithGroupsComponent>;
|
|
268
|
+
let ganttComponentInstance: TestGanttWithGroupsComponent;
|
|
269
|
+
let ganttDebugElement: DebugElement;
|
|
270
|
+
let ganttComponent: NgxGanttComponent;
|
|
271
|
+
|
|
272
|
+
beforeEach(async () => {
|
|
273
|
+
TestBed.configureTestingModule({
|
|
274
|
+
imports: [CommonModule, NgxGanttModule],
|
|
275
|
+
declarations: [TestGanttWithGroupsComponent],
|
|
276
|
+
providers: [GanttPrintService]
|
|
277
|
+
}).compileComponents();
|
|
278
|
+
fixture = TestBed.createComponent(TestGanttWithGroupsComponent);
|
|
279
|
+
fixture.detectChanges();
|
|
280
|
+
ganttDebugElement = fixture.debugElement.query(By.directive(NgxGanttComponent));
|
|
281
|
+
ganttComponentInstance = fixture.componentInstance;
|
|
282
|
+
ganttComponent = ganttComponentInstance.ganttComponent;
|
|
283
|
+
fixture.detectChanges();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should render groups', () => {
|
|
287
|
+
const groups = fixture.debugElement.queryAll(By.css('.gantt-group'));
|
|
288
|
+
expect(groups.length).toEqual(mockGroups.length);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should render group items', () => {
|
|
292
|
+
assertGroups(fixture, mockGroups);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should render custom group template', () => {
|
|
296
|
+
const groups = fixture.debugElement.queryAll(By.css('.test-gantt-with-groups-group'));
|
|
297
|
+
const groupHeaders = fixture.debugElement.queryAll(By.css('.test-gantt-with-groups-group-header'));
|
|
298
|
+
expect(groups.length).toEqual(mockGroups.length);
|
|
299
|
+
expect(groupHeaders.length).toEqual(mockGroups.length);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should re render groups when change groups', () => {
|
|
303
|
+
const newGroups = mockItems.slice(0, 2);
|
|
304
|
+
ganttComponentInstance.groups = [...newGroups];
|
|
305
|
+
fixture.detectChanges();
|
|
306
|
+
assertGroups(fixture, newGroups);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('should group can be expanded', () => {
|
|
310
|
+
const groupTitle = fixture.debugElement.query(By.css('.gantt-table-group-title'));
|
|
311
|
+
groupTitle.nativeElement.click();
|
|
312
|
+
const afterCollapseItems = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent));
|
|
313
|
+
expect(ganttComponent.groups[0].expanded).toBe(false);
|
|
314
|
+
expect(afterCollapseItems.length).toEqual(mockGroupItems.length - ganttComponent.groups[0].items.length);
|
|
315
|
+
|
|
316
|
+
groupTitle.nativeElement.click();
|
|
317
|
+
const afterExpandItems = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent));
|
|
318
|
+
expect(ganttComponent.groups[0].expanded).toBe(true);
|
|
319
|
+
expect(afterExpandItems.length).toEqual(mockGroupItems.length);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('should expand all groups ', () => {
|
|
323
|
+
const groupExpandAll = fixture.debugElement.query(By.css('.expand'));
|
|
324
|
+
groupExpandAll.nativeElement.click();
|
|
325
|
+
const afterExpandItems = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent));
|
|
326
|
+
ganttComponent.groups.forEach((group: GanttGroupInternal) => {
|
|
327
|
+
expect(group.expanded).toBe(true);
|
|
328
|
+
});
|
|
329
|
+
expect(afterExpandItems.length).toEqual(mockGroupItems.length);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('should collapse all groups ', () => {
|
|
333
|
+
const groupCollapseAll = fixture.debugElement.query(By.css('.collapse'));
|
|
334
|
+
groupCollapseAll.nativeElement.click();
|
|
335
|
+
const afterCollapseItems = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent));
|
|
336
|
+
ganttComponent.groups.forEach((group: GanttGroupInternal) => {
|
|
337
|
+
expect(group.expanded).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
expect(afterCollapseItems.length).toEqual(0);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe('#load children', () => {
|
|
344
|
+
let fixture: ComponentFixture<TestGanttLoadChildrenComponent>;
|
|
345
|
+
let ganttComponentInstance: TestGanttLoadChildrenComponent;
|
|
346
|
+
let ganttDebugElement: DebugElement;
|
|
347
|
+
let ganttComponent: NgxGanttComponent;
|
|
348
|
+
|
|
349
|
+
beforeEach(async () => {
|
|
350
|
+
TestBed.configureTestingModule({
|
|
351
|
+
imports: [CommonModule, NgxGanttModule],
|
|
352
|
+
declarations: [TestGanttLoadChildrenComponent],
|
|
353
|
+
providers: [GanttPrintService]
|
|
354
|
+
}).compileComponents();
|
|
355
|
+
fixture = TestBed.createComponent(TestGanttLoadChildrenComponent);
|
|
356
|
+
fixture.detectChanges();
|
|
357
|
+
ganttDebugElement = fixture.debugElement.query(By.directive(NgxGanttComponent));
|
|
358
|
+
ganttComponentInstance = fixture.componentInstance;
|
|
359
|
+
ganttComponent = ganttComponentInstance.ganttComponent;
|
|
360
|
+
fixture.detectChanges();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('should show expand icon and load children', () => {
|
|
364
|
+
const ganttIcons = fixture.debugElement.queryAll(By.directive(GanttIconComponent));
|
|
365
|
+
expect(ganttIcons.length).toEqual(2);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('should load children', () => {
|
|
369
|
+
const ganttIcon = fixture.debugElement.queryAll(By.directive(GanttIconComponent))[0];
|
|
370
|
+
ganttIcon.nativeElement.click();
|
|
371
|
+
fixture.detectChanges();
|
|
372
|
+
const afterExpandItems = fixture.debugElement.queryAll(By.css('.gantt-table-item'));
|
|
373
|
+
expect(ganttComponent.items[0].expanded).toBe(true);
|
|
374
|
+
expect(afterExpandItems.length).toEqual(mockItems.length + ganttComponent.items[0].children.length);
|
|
375
|
+
|
|
376
|
+
ganttIcon.nativeElement.click();
|
|
377
|
+
fixture.detectChanges();
|
|
378
|
+
const afterCollapseItems = fixture.debugElement.queryAll(By.css('.gantt-table-item'));
|
|
379
|
+
expect(ganttComponent.items[0].expanded).toBe(false);
|
|
380
|
+
expect(afterCollapseItems.length).toEqual(mockItems.length);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should load async children', fakeAsync(() => {
|
|
384
|
+
ganttComponentInstance.async = true;
|
|
385
|
+
fixture.detectChanges();
|
|
386
|
+
const ganttIcon = fixture.debugElement.queryAll(By.directive(GanttIconComponent))[1];
|
|
387
|
+
ganttIcon.nativeElement.click();
|
|
388
|
+
tick(2000);
|
|
389
|
+
fixture.detectChanges();
|
|
390
|
+
const afterExpandItems = fixture.debugElement.queryAll(By.css('.gantt-table-item'));
|
|
391
|
+
expect(ganttComponent.items[1].expanded).toBe(true);
|
|
392
|
+
expect(afterExpandItems.length).toEqual(mockItems.length + 1);
|
|
393
|
+
|
|
394
|
+
ganttIcon.nativeElement.click();
|
|
395
|
+
tick(2000);
|
|
396
|
+
fixture.detectChanges();
|
|
397
|
+
const afterCollapseItems = fixture.debugElement.queryAll(By.css('.gantt-table-item'));
|
|
398
|
+
expect(ganttComponent.items[1].expanded).toBe(false);
|
|
399
|
+
expect(afterCollapseItems.length).toEqual(mockItems.length);
|
|
400
|
+
}));
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
describe('#draggable', () => {});
|
|
404
|
+
});
|