Skip to content

Commit b66bd92

Browse files
authored
Merge pull request swimlane#563 from gerhardboer/fix-497
Fix 497 & 562
2 parents a63a0ac + 47f1b8b commit b66bd92

16 files changed

+463
-69
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {AutoRowHeightPage} from "../pages/auto-row-height.po";
2+
import {all} from "q";
3+
4+
describe('Auto row height', () => {
5+
6+
let autoRowHeight;
7+
8+
beforeAll(() => {
9+
autoRowHeight = new AutoRowHeightPage();
10+
11+
autoRowHeight.navigateTo();
12+
});
13+
14+
it('should show 3 columns', () => {
15+
expect(autoRowHeight.table.columnCount).toBe(3);
16+
});
17+
18+
it('should have a bigger first row', () => {
19+
20+
all([
21+
autoRowHeight.table.rowSize(0),
22+
autoRowHeight.table.rowSize(1)
23+
])
24+
.then((sizes) => {
25+
let [row1, row2] = sizes;
26+
27+
expect(row1.height > row2.height).toBe(true);
28+
});
29+
});
30+
31+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {FixedRowHeightPage} from "../pages/fixed-row-height.po";
2+
import {all} from "q";
3+
4+
describe('Fixed row height', () => {
5+
6+
let fixedRowHeight;
7+
8+
beforeAll(() => {
9+
fixedRowHeight = new FixedRowHeightPage();
10+
11+
fixedRowHeight.navigateTo();
12+
});
13+
14+
it('should show 3 columns', () => {
15+
expect(fixedRowHeight.table.columnCount).toBe(3);
16+
});
17+
18+
it('should have same rowheights for row 1 & 2', () => {
19+
20+
all([
21+
fixedRowHeight.table.rowSize(0),
22+
fixedRowHeight.table.rowSize(1)
23+
])
24+
.then((sizes) => {
25+
let [row1, row2] = sizes;
26+
27+
expect(row1.height).toBe(row2.height);
28+
});
29+
});
30+
31+
});
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import {FixedRowHeightPage} from "../pages/fixed-row-height.po";
2+
3+
describe('Drag and drop columns [ Name, Company, Gender ]', () => {
4+
5+
let page;
6+
7+
let NAME = 0,
8+
COMPANY = 1,
9+
GENDER = 2;
10+
11+
beforeEach(() => {
12+
page = new FixedRowHeightPage();
13+
14+
page.navigateTo();
15+
});
16+
17+
// columns are [ Name, Company, Gender ]
18+
describe('when the first column is dragged to the second ', () => {
19+
20+
beforeEach(() => {
21+
expect(page.table.columnText(NAME)).toBe('Name');
22+
expect(page.table.columnText(COMPANY)).toBe('Company');
23+
});
24+
25+
it('then it should swap the columns [ Company, Name, Gender ]', () => {
26+
page.table.drag(NAME, COMPANY)
27+
.then(() => {
28+
expect(page.table.columnText(NAME)).toBe('Company');
29+
expect(page.table.columnText(COMPANY)).toBe('Name');
30+
});
31+
});
32+
});
33+
34+
// columns are [ Name, Company, Gender ]
35+
describe('when the first column is dragged to the third', () => {
36+
37+
beforeEach(() => {
38+
// page.printColumns();
39+
expect(page.table.columnText(NAME)).toBe('Name');
40+
expect(page.table.columnText(GENDER)).toBe('Gender');
41+
});
42+
43+
it('then it should swap the columns [ Gender, Company, Name ]', () => {
44+
page.table.drag(NAME, GENDER)
45+
.then(() => {
46+
// page.printColumns();
47+
expect(page.table.columnText(NAME)).toBe('Gender');
48+
expect(page.table.columnText(GENDER)).toBe('Name');
49+
});
50+
});
51+
});
52+
53+
// columns are [ Name, Company, Gender ]
54+
describe('when the second column is dragged to the third', () => {
55+
beforeEach(() => {
56+
expect(page.table.columnText(COMPANY)).toBe('Company');
57+
expect(page.table.columnText(GENDER)).toBe('Gender');
58+
});
59+
60+
it('then it should swap the columns [ Name, Gender, Company ]', () => {
61+
page.table.drag(COMPANY, GENDER)
62+
.then(() => {
63+
expect(page.table.columnText(COMPANY)).toBe('Gender');
64+
expect(page.table.columnText(GENDER)).toBe('Company');
65+
});
66+
});
67+
});
68+
69+
// columns are [ Name, Company, Gender ]
70+
describe('when the third column is dragged to the second', () => {
71+
beforeEach(() => {
72+
expect(page.table.columnText(GENDER)).toBe('Gender');
73+
expect(page.table.columnText(COMPANY)).toBe('Company');
74+
});
75+
76+
it('then it should swap the columns [ Name, Gender, Company ]', () => {
77+
page.table.drag(GENDER, COMPANY)
78+
.then(() => {
79+
expect(page.table.columnText(GENDER)).toBe('Company');
80+
expect(page.table.columnText(COMPANY)).toBe('Gender');
81+
});
82+
});
83+
});
84+
85+
// columns are [ Name, Company, Gender ]
86+
describe('when the third column is dragged to the first', () => {
87+
beforeEach(() => {
88+
expect(page.table.columnText(GENDER)).toBe('Gender');
89+
expect(page.table.columnText(NAME)).toBe('Name');
90+
});
91+
92+
it('then it should swap the columns [ Gender, Company, Name ]', () => {
93+
page.table.drag(GENDER, NAME)
94+
.then(() => {
95+
expect(page.table.columnText(GENDER)).toBe('Name');
96+
expect(page.table.columnText(NAME)).toBe('Gender');
97+
});
98+
});
99+
});
100+
101+
});

e2e/pages/auto-row-height.po.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {BasePage} from "./util/base.po";
2+
3+
export class AutoRowHeightPage extends BasePage {
4+
5+
_pageTitle = 'Fluid Row Heights';
6+
7+
navigateTo() {
8+
return super.navigateTo('/')
9+
.then(() => {
10+
expect(this.title).toBe(this._pageTitle)
11+
});
12+
}
13+
14+
}

e2e/pages/fixed-row-height.po.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {BasePage} from "./util/base.po";
2+
3+
export class FixedRowHeightPage extends BasePage {
4+
5+
_pageTitle = 'Fix Row Height';
6+
_menuTitle = 'Fixed Row Height';
7+
8+
navigateTo() {
9+
return super.navigateTo('/')
10+
.then(() =>
11+
this.menuItem(this._menuTitle).click()
12+
)
13+
.then(() => {
14+
expect(this.title).toBe(this._pageTitle)
15+
});
16+
}
17+
18+
}

e2e/pages/util/base.po.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {browser, by, element } from "protractor";
2+
import {NgxDataTablePo} from "./datatable.po";
3+
4+
export class BasePage {
5+
6+
table: NgxDataTablePo = new NgxDataTablePo();
7+
8+
navigateTo(url) {
9+
browser.driver.manage().window().setSize(1000, 1000);
10+
11+
return browser.get(url)
12+
}
13+
14+
get title(): any {
15+
return element(by.css('content div>h3')).getText();
16+
}
17+
18+
menuItem(label): any {
19+
return element.all(by.css('.main-ul a'))
20+
.filter(el => el.getText().then(menuItem => menuItem == label))
21+
.first();
22+
}
23+
24+
printColumns() {
25+
this.table.columns()
26+
.map(el => el.getText().then(_ => _))
27+
.then(cols => console.log(cols));
28+
}
29+
30+
31+
}

e2e/pages/util/datatable.po.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {browser, by, element, ElementArrayFinder} from "protractor";
2+
3+
export class NgxDataTablePo {
4+
5+
columns(): ElementArrayFinder {
6+
return element.all(by.css('datatable-header-cell'))
7+
}
8+
9+
rows(): ElementArrayFinder {
10+
return element.all(by.css('datatable-row-wrapper'))
11+
}
12+
13+
columnByIdx(idx) {
14+
return this.columns()
15+
.get(idx)
16+
}
17+
18+
get columnCount(): any {
19+
return this.columns().count();
20+
}
21+
22+
columnText(idx) {
23+
return this.columns()
24+
.get(idx)
25+
.getText()
26+
}
27+
28+
drag(colFromIdx, colToIdx) {
29+
let distance = colFromIdx > colToIdx
30+
? -200
31+
: 200;
32+
33+
// works on browser of 1000 x 1000
34+
if (colFromIdx + colToIdx == 2) {
35+
distance *= 2;
36+
}
37+
38+
return this.columnByIdx(colFromIdx).$('.draggable').getWebElement()
39+
.then(el => browser.actions()
40+
.mouseDown(el)
41+
.perform()
42+
)
43+
.then(() => {
44+
browser.sleep(600)
45+
})
46+
// .then(() => this.columnByIdx(colToIdx).$('.draggable').getWebElement())
47+
.then((el) => browser.actions()
48+
.mouseMove({ x: distance, y: 0})
49+
.mouseUp()
50+
.perform()
51+
);
52+
}
53+
54+
rowSize(idx: number): any {
55+
return this.rows().get(idx)
56+
.getWebElement()
57+
.then(_ => _.getSize())
58+
}
59+
60+
61+
}

e2e/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"declaration": false,
5+
"emitDecoratorMetadata": true,
6+
"experimentalDecorators": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"outDir": "../dist/out-tsc-e2e",
10+
"sourceMap": true,
11+
"target": "es5",
12+
"typeRoots": [
13+
"../node_modules/@types"
14+
]
15+
}
16+
}

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636
"package:replace-scss": "node ./config/replace-scss.js",
3737
"package:css": "node-sass -o release/ src/themes && node-sass -o release/components src/components",
3838
"package:minify": "uglifyjs release/index.js --source-map release/index.min.js.map --source-map-url release/index.js.map --compress --mangle --screw-ie8 --output release/index.min.js",
39-
"deploy": "node ./config/deploy.js"
39+
"deploy": "node ./config/deploy.js",
40+
"pree2e:full": "npm run build:release",
41+
"e2e:full": "npm run e2e",
42+
"e2e": "npm-run-all -p -r e2e:server protractor",
43+
"e2e:server": "http-server dist -p 8888",
44+
"preprotractor": "npm run webdriver:update",
45+
"protractor": "protractor",
46+
"webdriver:update": "webdriver-manager update"
4047
},
4148
"repository": {
4249
"type": "git",
@@ -68,6 +75,7 @@
6875
"core-js": "^2.4.0"
6976
},
7077
"devDependencies": {
78+
7179
"@angular/common": "~4.0.0-rc.1",
7280
"@angular/compiler": "~4.0.0-rc.1",
7381
"@angular/compiler-cli": "^4.0.0-rc.1",
@@ -93,6 +101,7 @@
93101
"html-webpack-plugin": "^2.22.0",
94102
"istanbul-instrumenter-loader": "^2.0.0",
95103
"jasmine-core": "^2.5.2",
104+
"jasmine-spec-reporter": "^3.2.0",
96105
"karma": "^1.5.0",
97106
"karma-chrome-launcher": "^2.0.0",
98107
"karma-coverage": "^1.1.1",
@@ -102,6 +111,7 @@
102111
"karma-sourcemap-loader": "^0.3.7",
103112
"karma-webpack": "^2.0.1",
104113
"node-sass": "^4.0.0",
114+
"protractor": "^5.1.1",
105115
"npm-run-all": "^4.0.2",
106116
"postcss": "^5.2.15",
107117
"postcss-loader": "^1.3.3",
@@ -113,6 +123,7 @@
113123
"style-loader": "^0.13.2",
114124
"to-string-loader": "^1.1.5",
115125
"ts-helpers": "^1.1.2",
126+
"ts-node": "^2.1.0",
116127
"tslint": "^4.5.1",
117128
"tslint-config-swimlane": "^2.0.1",
118129
"tslint-loader": "^3.4.3",

protractor.conf.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Protractor configuration file, see link for more information
2+
// https://github.com/angular/protractor/blob/master/lib/config.ts
3+
4+
/*global jasmine */
5+
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
6+
7+
exports.config = {
8+
allScriptsTimeout: 11000,
9+
specs: [
10+
'./e2e/**/*.e2e-spec.ts'
11+
],
12+
capabilities: {
13+
'browserName': 'chrome'
14+
},
15+
directConnect: true,
16+
baseUrl: 'http://localhost:8888/',
17+
framework: 'jasmine',
18+
jasmineNodeOpts: {
19+
showColors: true,
20+
defaultTimeoutInterval: 30000,
21+
print: function() {}
22+
},
23+
useAllAngular2AppRoots: true,
24+
beforeLaunch: function() {
25+
require('ts-node').register({
26+
project: 'e2e'
27+
});
28+
},
29+
onPrepare: function() {
30+
require("zone.js/dist/zone-node");
31+
32+
jasmine.getEnv().addReporter(new SpecReporter());
33+
}
34+
};

0 commit comments

Comments
 (0)