Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 701b624

Browse files
authored
feat(tests): add more Cypress E2E tests for grid with Editors (#532)
* feat(tests): add more Cypress E2E tests for grid with Editors
1 parent 14f2fa0 commit 701b624

File tree

4 files changed

+213
-24
lines changed

4 files changed

+213
-24
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,44 @@
123123
"@types/dompurify": "^2.0.1",
124124
"@types/flatpickr": "^3.1.2",
125125
"@types/jest": "^24.0.25",
126-
"@types/jquery": "^3.3.37",
126+
"@types/jquery": "^3.5.0",
127127
"@types/moment": "^2.13.0",
128128
"@types/node": "^13.13.4",
129129
"@types/text-encoding-utf-8": "^1.0.1",
130130
"babel-jest": "^24.9.0",
131131
"bootstrap": "3.4.1",
132-
"codecov": "^3.6.1",
132+
"codecov": "^3.7.0",
133133
"codelyzer": "~4.5.0",
134-
"conventional-changelog": "^3.1.18",
135-
"copyfiles": "^2.2.0",
134+
"conventional-changelog": "^3.1.21",
135+
"copyfiles": "^2.3.0",
136136
"core-js": "^2.6.11",
137137
"cross-env": "^7.0.2",
138138
"custom-event-polyfill": "^1.0.7",
139139
"del": "^5.1.0",
140-
"del-cli": "^3.0.0",
140+
"del-cli": "^3.0.1",
141141
"gulp": "^4.0.2",
142-
"gulp-bump": "^3.1.3",
143-
"gulp-sass": "^4.0.2",
142+
"gulp-bump": "^3.2.0",
143+
"gulp-sass": "^4.1.0",
144144
"gulp-yuidoc": "^0.1.2",
145145
"jest": "^24.9.0",
146146
"jest-extended": "^0.11.5",
147147
"jest-junit": "^6.4.0",
148148
"jest-preset-angular": "^6.0.1",
149149
"ng-packagr": "~5.3.0",
150150
"ngx-bootstrap": "^4.3.0",
151-
"node-sass": "4.14.0",
151+
"node-sass": "4.14.1",
152152
"npm-run-all": "^4.1.5",
153-
"postcss-cli": "^7.1.0",
153+
"postcss-cli": "^7.1.1",
154154
"require-dir": "^1.2.0",
155155
"rimraf": "^3.0.2",
156156
"run-sequence": "^2.2.1",
157-
"standard-version": "^8.0.1",
157+
"standard-version": "^8.0.2",
158158
"ts-node": "~3.3.0",
159159
"tsickle": "^0.34.0",
160160
"tslib": "^1.11.0",
161161
"tslint": "^5.12.0",
162162
"typescript": ">=3.1.1 <3.2.0",
163-
"uglify-js": "^3.8.0",
163+
"uglify-js": "^3.10.0",
164164
"vinyl-paths": "^2.1.0",
165165
"yargs": "^15.1.0",
166166
"zone.js": "^0.8.29"

src/app/examples/grid-editor.component.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ <h2>{{title}}</h2>
77
<span id="radioAutoEdit">
88
<label class="radio-inline control-label" for="radioTrue">
99
<input type="radio" name="inlineRadioOptions" id="radioTrue" checked [value]="isAutoEdit"
10-
(change)="setAutoEdit(true)"> ON (single-click)
10+
(change)="setAutoEdit(true)"> ON (single-click)
1111
</label>
1212
<label class="radio-inline control-label" for="radioFalse">
1313
<input type="radio" name="inlineRadioOptions" id="radioFalse" [value]="isAutoEdit"
14-
(change)="setAutoEdit(false)"> OFF (double-click)
14+
(change)="setAutoEdit(false)"> OFF (double-click)
1515
</label>
1616
</span>
1717
<div class="row col-sm-12">
@@ -21,8 +21,8 @@ <h2>{{title}}</h2>
2121
Undo last edit(s)
2222
</button>
2323
<label class="checkbox-inline control-label" for="autoCommitEdit">
24-
<input type="checkbox" id="autoCommitEdit" [checked]="gridOptions.autoCommitEdit"
25-
(click)="changeAutoCommit()">
24+
<input type="checkbox" id="autoCommitEdit" data-test="auto-commit" [checked]="gridOptions.autoCommitEdit"
25+
(click)="changeAutoCommit()">
2626
Auto Commit Edit
2727
</label>
2828
</span>
@@ -31,15 +31,15 @@ <h2>{{title}}</h2>
3131
<button class="btn btn-default btn-sm" (click)="angularGrid.filterService.clearFilters()">Clear Filters</button>
3232
<button class="btn btn-default btn-sm" (click)="angularGrid.sortService.clearSorting()">Clear Sorting</button>
3333
<button class="btn btn-default btn-sm btn-info" (click)="addItem()"
34-
title="Clear Filters &amp; Sorting to see it better">Add item</button>
34+
title="Clear Filters &amp; Sorting to see it better">Add item</button>
3535
<button class="btn btn-default btn-sm btn-danger" (click)="deleteItem()">Delete item</button>
3636
</div>
3737
<div class="row" style="margin-top: 5px">
38-
<button class="btn btn-default btn-sm" (click)="dynamicallyAddTitleHeader()">
38+
<button class="btn btn-default btn-sm" data-test="add-title-column" (click)="dynamicallyAddTitleHeader()">
3939
<i class="fa fa-plus"></i>
4040
Dynamically Duplicate Title Column
4141
</button>
42-
<button class="btn btn-default btn-sm" (click)="dynamicallyRemoveLastColumn()">
42+
<button class="btn btn-default btn-sm" data-test="remove-title-column" (click)="dynamicallyRemoveLastColumn()">
4343
<i class="fa fa-minus"></i>
4444
Dynamically Remove Last Column
4545
</button>
@@ -58,11 +58,11 @@ <h2>{{title}}</h2>
5858
</div>
5959

6060
<div class="col-sm-12 row">
61-
<angular-slickgrid gridId="grid2" (onAngularGridCreated)="angularGridReady($event)"
62-
(sgOnCellChange)="onCellChanged($event.detail.eventData, $event.detail.args)"
63-
(sgOnClick)="onCellClicked($event.detail.eventData, $event.detail.args)"
64-
(sgOnValidationError)="onValidationError($event.detail.eventData, $event.detail.args)"
65-
[columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions" [dataset]="dataset">
61+
<angular-slickgrid gridId="grid3" (onAngularGridCreated)="angularGridReady($event)"
62+
(sgOnCellChange)="onCellChanged($event.detail.eventData, $event.detail.args)"
63+
(sgOnClick)="onCellClicked($event.detail.eventData, $event.detail.args)"
64+
(sgOnValidationError)="onValidationError($event.detail.eventData, $event.detail.args)"
65+
[columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions" [dataset]="dataset">
6666
</angular-slickgrid>
6767
</div>
6868
</div>

src/app/examples/grid-editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const taskFormatter = (row, cell, value, columnDef, dataContext) => {
6565
})
6666
@Injectable()
6767
export class GridEditorComponent implements OnInit {
68-
title = 'Example 3: Editors';
68+
title = 'Example 3: Editors / Delete';
6969
subTitle = `
7070
Grid with Inline Editors and onCellClick actions (<a href="https://github.com/ghiscoding/Angular-Slickgrid/wiki/Editors" target="_blank">Wiki docs</a>).
7171
<ul>
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/// <reference types="cypress" />
2+
3+
function removeExtraSpaces(textS) {
4+
return `${textS}`.replace(/\s+/g, ' ').trim();
5+
}
6+
7+
describe('Example 3 - Grid with Editors', () => {
8+
const GRID_ROW_HEIGHT = 35;
9+
const fullTitles = [
10+
'', '', 'Title', 'Title, Custom Editor', 'Duration (days)', '% Complete',
11+
'Start', 'Finish', 'City of Origin', 'Country of Origin', 'Country of Origin Name',
12+
'Effort Driven', 'Prerequisites',
13+
];
14+
15+
it('should display Example title', () => {
16+
cy.visit(`${Cypress.config('baseExampleUrl')}/editor`);
17+
cy.get('h2').should('contain', 'Example 3: Editors / Delete');
18+
});
19+
20+
it('should have exact Column Titles in the grid', () => {
21+
cy.get('#grid3')
22+
.find('.slick-header-columns')
23+
.children()
24+
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
25+
});
26+
27+
it('should enable "Auto Commit Edit"', () => {
28+
cy.get('[data-test=auto-commit]')
29+
.click();
30+
});
31+
32+
it('should be able to change all values of 3rd row', () => {
33+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(2)`).should('contain', 'Task 2').click();
34+
35+
// change Title & Custom Title
36+
cy.get('.editor-title > textarea').type('Task 2222');
37+
cy.get('.editor-title .btn-save').click();
38+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(2)`).should('contain', 'Task 2222');
39+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(3)`).should('contain', 'Task 2222');
40+
41+
// change duration
42+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(4)`).click();
43+
cy.get('.slider-editor input[type=range]').as('range')
44+
.invoke('val', 25)
45+
.trigger('change')
46+
.type('{enter}', { force: true });
47+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(4)`).should('contain', '25');
48+
49+
// change % Complete
50+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(5)`).click();
51+
cy.get('[name=editor-complete].ms-drop > ul > li > label:nth(5)').contains('95').click();
52+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(5)`)
53+
.find('.percent-complete-bar[style="background:green; width:95%"]');
54+
55+
// change Finish date
56+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(6)`).click();
57+
cy.get('.flatpickr-monthDropdown-months:visible')
58+
.select('January', { force: true });
59+
cy.get('.numInput.cur-year:visible').type('2009');
60+
cy.get('.flatpickr-day:visible:nth(25)').click('bottom', { force: true })
61+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(6)`).should('contain', '2009-01-22');
62+
63+
// change City of Origin
64+
// cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(8)`).click({ force: true });
65+
// cy.get('input.autocomplete.editor-cityOfOrigin.ui-autocomplete-input')
66+
// .type('Venice');
67+
68+
// change Effort Driven
69+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(11)`).click();
70+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 2}px"] > .slick-cell:nth(11) > input.editor-checkbox.editor-effort-driven`).check();
71+
72+
cy.get('.slick-viewport.slick-viewport-top.slick-viewport-left')
73+
.scrollTo('top');
74+
});
75+
76+
it('should dynamically add 2x new "Title" columns', () => {
77+
const updatedTitles = [
78+
'', '', 'Title', 'Title, Custom Editor', 'Duration (days)', '% Complete',
79+
'Start', 'Finish', 'City of Origin', 'Country of Origin', 'Country of Origin Name',
80+
'Effort Driven', 'Prerequisites', 'Title', 'Title'
81+
];
82+
83+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0');
84+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(13)`).should('not.exist');
85+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(14)`).should('not.exist');
86+
87+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`)
88+
.should('contain', 'Task 0')
89+
.should('have.length', 1);
90+
91+
cy.get('#grid3')
92+
.find('.slick-header-columns')
93+
.children()
94+
.each(($child, index) => expect($child.text()).to.eq(updatedTitles[index]));
95+
96+
cy.get('[data-test=add-title-column]')
97+
.click()
98+
.click();
99+
100+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0');
101+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(3)`).should('contain', 'Task 0');
102+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(13)`).should('contain', 'Task 0');
103+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(14)`).should('contain', 'Task 0');
104+
});
105+
106+
it('should be able to change value of 1st row "Title" column and expect same value set in all 3 "Title" columns', () => {
107+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0').click();
108+
109+
// change Title & Custom Title
110+
cy.get('.editor-title > textarea').type('Task 0000');
111+
cy.get('.editor-title .btn-save').click();
112+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0000');
113+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(3)`).should('contain', 'Task 0000');
114+
115+
// change duration
116+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(4)`).click();
117+
cy.get('.slider-editor input[type=range]').as('range')
118+
.invoke('val', 50)
119+
.trigger('change')
120+
.type('{enter}', { force: true });
121+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(4)`).should('contain', '50');
122+
123+
// change % Complete
124+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(5)`).click();
125+
cy.get('[name=editor-complete].ms-drop > ul > li > label:nth(5)').contains('95').click();
126+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(5)`)
127+
.find('.percent-complete-bar[style="background:green; width:95%"]');
128+
129+
// change Finish date
130+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(6)`).click();
131+
cy.get('.flatpickr-monthDropdown-months:visible')
132+
.select('January', { force: true });
133+
cy.get('.numInput.cur-year:visible').type('2009');
134+
cy.get('.flatpickr-day:visible:nth(25)').click('bottom', { force: true })
135+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(6)`).should('contain', '2009-01-22');
136+
137+
// change Effort Driven
138+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(11)`).click();
139+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(11) > input.editor-checkbox.editor-effort-driven`).check().blur();
140+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(10)`).click(); // the blur seems to not always work, so just click on another cell
141+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(11)`).find('.fa-check.checkmark-icon');
142+
143+
cy.get('.slick-viewport.slick-viewport-top.slick-viewport-left')
144+
.scrollTo('top');
145+
});
146+
147+
it('should be able to dynamically remove last 2 added Title columns', () => {
148+
cy.get('[data-test=remove-title-column]')
149+
.click()
150+
.click();
151+
152+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0');
153+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(13)`).should('not.exist');
154+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(14)`).should('not.exist');
155+
});
156+
157+
it('should be able to change values again of 1st row "Title" column and expect same value set in all 3 "Title" columns', () => {
158+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0').click();
159+
160+
// change Title & Custom Title
161+
cy.get('.editor-title > textarea').type('Task 0000');
162+
cy.get('.editor-title .btn-save').click();
163+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(2)`).should('contain', 'Task 0000');
164+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(3)`).should('contain', 'Task 0000');
165+
166+
// change duration
167+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(4)`).click();
168+
cy.get('.slider-editor input[type=range]').as('range')
169+
.invoke('val', 50)
170+
.trigger('change')
171+
.type('{enter}', { force: true });
172+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(4)`).should('contain', '50');
173+
174+
// change % Complete
175+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(5)`).click();
176+
cy.get('[name=editor-complete].ms-drop > ul > li > label:nth(3)').contains('97').click();
177+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(5)`)
178+
.find('.percent-complete-bar[style="background:green; width:97%"]');
179+
180+
// change Finish date
181+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(6)`).click();
182+
cy.get('.flatpickr-day:visible:nth(24)').click('bottom', { force: true })
183+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(6)`).should('contain', '2009-01-21');
184+
185+
// // change Effort Driven
186+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(11)`).click();
187+
cy.get(`[style="top:${GRID_ROW_HEIGHT * 0}px"] > .slick-cell:nth(11) > input.editor-checkbox.editor-effort-driven`).uncheck();
188+
});
189+
});

0 commit comments

Comments
 (0)