Skip to content

Commit

Permalink
fix(module: tree): fix tests for 9.0 version (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
simplejason authored and vthinkxie committed Nov 22, 2019
1 parent 1c92b32 commit df789ed
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 44 deletions.
13 changes: 13 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
titleAndCommits: true
types:
- feat
- fix
- docs
- style
- refactor
- perf
- test
- build
- ci
- chore
- revert
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist: trusty
language: node_js
node_js:
- '12.13.1'

env:
- TASK=build
- TASK=test
Expand All @@ -23,10 +22,14 @@ before_script:
- export NG_CLI_ANALYTICS=ci
- npm install -g @angular/cli@next
- npm install -g karma
- npm install -g surge

script:
- npm run $TASK
- |
if [ "$TASK" = "test" ]; then
cat ./coverage/lcov.info | ./node_modules/.bin/codecov
fi
if [ "$TASK" = "build" ]; then
bash ./scripts/surge.sh
fi
8 changes: 8 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"buildOptimizer": true,
"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"
},
"es5": {
"tsConfig": "./site/doc/tsconfig.es5.json"
}
}
},
Expand Down Expand Up @@ -189,6 +192,11 @@
"options": {
"tsConfig": "components/tsconfig.lib.json",
"project": "components/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "components/tsconfig.lib.prod.json"
}
}
},
"test": {
Expand Down
2 changes: 1 addition & 1 deletion components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@angular/cdk": "~9.0.0-rc.2",
"@ant-design/icons-angular": "^8.0.2",
"@ant-design/icons-angular": "^9.0.0-rc.4",
"date-fns": "^1.30.1"
},
"peerDependencies": {
Expand Down
66 changes: 36 additions & 30 deletions components/tree/nz-tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,18 +431,19 @@ describe('nz-tree', () => {

it('test drag event', fakeAsync(() => {
fixture.detectChanges();
const dragStartSpy = spyOn(treeInstance, 'onDragStart');
const dragEnterSpy = spyOn(treeInstance, 'onDragEnter');
const dragOverSpy = spyOn(treeInstance, 'onDragOver');
const dragLeaveSpy = spyOn(treeInstance, 'onDragLeave');
const dropSpy = spyOn(treeInstance, 'onDrop');
const dragEndSpy = spyOn(treeInstance, 'onDragEnd');
// make sure spyOn to execute real functions
const dragStartSpy = spyOn(treeInstance, 'onDragStart').and.callThrough();
const dragEnterSpy = spyOn(treeInstance, 'onDragEnter').and.callThrough();
const dragOverSpy = spyOn(treeInstance, 'onDragOver').and.callThrough();
const dragLeaveSpy = spyOn(treeInstance, 'onDragLeave').and.callThrough();
const dropSpy = spyOn(treeInstance, 'onDrop').and.callThrough();
const dragEndSpy = spyOn(treeInstance, 'onDragEnd').and.callThrough();
let dragNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
let dropNode = treeElement.querySelector("[title='0-0']") as HTMLElement;
let passNode = treeElement.querySelector("[title='0-0-0']") as HTMLElement;

dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dropNode, 'dragenter');
dispatchMouseEvent(dragNode, 'dragstart');
dispatchMouseEvent(dropNode, 'dragenter');
fixture.detectChanges();

// drag - dragenter
Expand All @@ -454,37 +455,37 @@ describe('nz-tree', () => {
expect(dragEnterSpy).toHaveBeenCalledTimes(1);

// dragover
dispatchTouchEvent(passNode, 'dragover');
fixture.detectChanges();
dispatchMouseEvent(passNode, 'dragover');
// fixture.detectChanges();
passNode = treeElement.querySelector("[title='0-0-0']") as HTMLElement;
expect(passNode.parentElement!.classList).toContain('drag-over');
expect(passNode.parentElement!.classList).toContain('drag-over-gap-top');
expect(dragOverSpy).toHaveBeenCalledTimes(1);

// dragleave
dispatchTouchEvent(passNode, 'dragleave');
dispatchMouseEvent(passNode, 'dragleave');
fixture.detectChanges();
passNode = treeElement.querySelector("[title='0-0-0']") as HTMLElement;
expect(passNode.parentElement!.classList.contains('drag-over')).toEqual(false);
expect(passNode.parentElement!.classList.contains('drag-over-gap-top')).toEqual(false);
expect(dragLeaveSpy).toHaveBeenCalledTimes(1);

// drop 0-1 to 0-0
dispatchTouchEvent(dropNode, 'drop');
dispatchMouseEvent(dropNode, 'drop');
fixture.detectChanges();
dropNode = treeElement.querySelector("[title='0-0']") as HTMLElement;
expect(dropSpy).toHaveBeenCalledTimes(1);
expect(dropNode.parentElement!.querySelector("[title='0-1']")).toBeDefined();

// dragend
dispatchTouchEvent(dropNode, 'dragend');
dispatchMouseEvent(dropNode, 'dragend');
fixture.detectChanges();
expect(dragEndSpy).toHaveBeenCalledTimes(1);

// drag 0-0 child node to 0-1
dragNode = treeElement.querySelector("[title='0-0-0']") as HTMLElement;
dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dropNode, 'dragover');
dispatchTouchEvent(dropNode, 'drop');
dispatchMouseEvent(dragNode, 'dragstart');
dispatchMouseEvent(dropNode, 'dragover');
dispatchMouseEvent(dropNode, 'drop');
fixture.detectChanges();
dropNode = treeElement.querySelector("[title='0-1']") as HTMLElement;
expect(dropSpy).toHaveBeenCalledTimes(2);
Expand All @@ -495,19 +496,22 @@ describe('nz-tree', () => {
it('test drag drop with dragPos', () => {
// init selected node
let treeNodes = treeInstance.treeComponent.getTreeNodes();
treeService = treeNodes[1].treeService;

const dragNode = treeElement.querySelectorAll('li')[1]; // 0-0-0
treeService!.setSelectedNode(treeInstance.treeComponent.getTreeNodeByKey('000')!); // set 0-0-0
dispatchTouchEvent(dragNode, 'dragstart');
fixture.detectChanges();
// drop 0-0-0 to 0-0 pre
let targetNode = treeNodes[0]; // 0-0

treeService = treeNodes[1].treeService;
treeService!.dropAndApply(targetNode, -1);
// get treeNodes again
treeNodes = treeInstance.treeComponent.getTreeNodes();
// now ['0-0-0', '0-0', '0-1', '0-2']
expect(treeNodes[0].title).toEqual('0-0-0');
expect(treeNodes[0].level).toEqual(0);

fixture.detectChanges();
// drop 0-0-0 to 0-0-1 next
treeService!.selectedNode = treeNodes[0];
Expand Down Expand Up @@ -542,17 +546,17 @@ describe('nz-tree', () => {
expect(dropSpy).toHaveBeenCalledTimes(0);
expect(dropNode.parentElement!.querySelector("[title='0-1']")).toBeNull();
// dragend
dispatchTouchEvent(dropNode, 'dragend');
dispatchMouseEvent(dropNode, 'dragend');
fixture.detectChanges();
expect(dragEndSpy).toHaveBeenCalledTimes(1);
// drop to itself
dispatchTouchEvent(dragNode, 'dragstart');
dispatchTouchEvent(dragNode, 'dragover');
dispatchTouchEvent(dragNode, 'drop');
dispatchMouseEvent(dragNode, 'dragstart');
dispatchMouseEvent(dragNode, 'dragover');
dispatchMouseEvent(dragNode, 'drop');
fixture.detectChanges();
expect(dropSpy).toHaveBeenCalledTimes(0);
// dragend
dispatchTouchEvent(dropNode, 'dragend');
dispatchMouseEvent(dropNode, 'dragend');
fixture.detectChanges();
expect(dragEndSpy).toHaveBeenCalledTimes(2);
}));
Expand Down Expand Up @@ -603,20 +607,21 @@ describe('nz-tree', () => {
fixture.componentInstance.selectedKeys = [...fixture.componentInstance.selectedKeys];
fixture.componentInstance.searchValue = '100011';
fixture.detectChanges();
let targetNode = treeElement.querySelectorAll('.ant-tree-switcher_open')[0];
const targetNode = treeElement.querySelectorAll('.ant-tree-switcher_open')[0];
dispatchMouseEvent(targetNode, 'click');
fixture.detectChanges();
expect(treeElement.querySelectorAll('.ant-tree-icon-hide')[0].children.length).toBe(3);

fixture.componentInstance.checkedKeys = [...fixture.componentInstance.checkedKeys];
fixture.componentInstance.expandKeys = [...fixture.componentInstance.expandKeys];
fixture.componentInstance.selectedKeys = [...fixture.componentInstance.selectedKeys];
fixture.componentInstance.searchValue = '10001';
fixture.detectChanges();
targetNode = treeElement.querySelectorAll('.ant-tree-switcher_open')[1];
dispatchMouseEvent(targetNode, 'click');
fixture.componentInstance.searchValue = '10001'; // Both root1 and its child nodes will be opened
fixture.detectChanges();
expect(treeElement.querySelectorAll('.ant-tree-switcher_close').length).toEqual(9);
// I'm confused why I added this line to collapse an opened node before, ignore it
// targetNode = treeElement.querySelectorAll('.ant-tree-switcher_open')[1];
// dispatchMouseEvent(targetNode, 'click');
// fixture.detectChanges();
expect(treeElement.querySelectorAll('.ant-tree-switcher_close').length).toEqual(8);
}));

it('should get correctly nodes', () => {
Expand Down Expand Up @@ -723,6 +728,7 @@ export class NzTestTreeBasicControlledComponent {
defaultCheckedKeys = ['0-0-0'];
defaultSelectedKeys = ['0-0-0-0'];
defaultExpandedKeys = ['0-0-0', '0-0-1'];
expandedIcon = '';

nodes: NzTreeNodeOptions[] | NzTreeNode[] = [
{
Expand Down
6 changes: 6 additions & 0 deletions components/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.lib.json",
"angularCompilerOptions": {
"enableIvy": false
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@angular/cdk": "^9.0.0-rc.2",
"@ant-design/icons-angular": "^8.0.3",
"@ant-design/icons-angular": "^9.0.0-rc.4",
"date-fns": "^1.30.1"
},
"devDependencies": {
Expand Down Expand Up @@ -98,7 +98,6 @@
"rxjs": "~6.5.3",
"sitemap": "^4.1.1",
"ts-node": "~8.3.0",
"tslib": "^1.10.0",
"tslint": "~5.18.0",
"typescript": "~3.6.4",
"yaml-front-matter": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ task('build:release', series(
task('build:preview', series(
'clean',
'init:site',
'build:site'
'build:site-doc-es5'
));

task('start:dev', series(
Expand Down
9 changes: 8 additions & 1 deletion scripts/gulp/tasks/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ task('build:site-doc', execNodeTask(
[ 'build', '--project=ng-zorro-antd-doc', '--prod' ]
));

/** Run `ng build --prod --project=ng-zorro-antd-doc --configuration es5` */
task('build:site-doc-es5', execNodeTask(
'@angular/cli',
'ng',
[ 'build', '--project=ng-zorro-antd-doc', '--prod', '--configuration=es5' ]
));

/** Run `ng build --prod --base-href ./ --project=ng-zorro-antd-iframe` */
task('build:site-iframe', execNodeTask(
'@angular/cli',
Expand All @@ -80,7 +87,7 @@ task('build:site-issue-helper', execTask(
));

/** Build all site projects to the output directory. */
task('build:site', series(
task('build:site', process.env.CI ? series('build:site-doc', 'build:site-iframe') : series(
'build:site-doc',
'build:site-iframe',
'build:site-issue-helper'
Expand Down
7 changes: 0 additions & 7 deletions scripts/site/_site/doc/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,5 @@ <h4>
<span>Blog</span>
</a>
</li>
<li nz-menu-item *ngIf="language=='zh'">
<a href="https://ng-china.org" target="_blank">
<nz-badge nzDot>
<a>2019 ngChina 开发者大会</a>
</nz-badge>
</a>
</li>
</ul>
</ng-template>
1 change: 0 additions & 1 deletion scripts/site/_site/doc/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.app.json",
"files": [
"./main.ts",
"./main.server.ts",
"./polyfills.ts"
]
}
6 changes: 6 additions & 0 deletions scripts/site/_site/doc/tsconfig.es5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"target": "es5"
}
}
3 changes: 3 additions & 0 deletions scripts/site/_site/doc/tsconfig.server.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"compilerOptions": {
"outDir": "../../out-tsc/app-server"
},
"files": [
"./main.server.ts"
],
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/surge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export SURGE_LOGIN=ng.zorro.antd@gmail.com
export SURGE_TOKEN=5c751dc2bb966953f09f645f2e5781ac
export DEPLOY_DOMAIN=https://preview-${TRAVIS_PULL_REQUEST}-ng-zorro-antd.surge.sh
surge --project ./dist --domain $DEPLOY_DOMAIN

0 comments on commit df789ed

Please sign in to comment.