Skip to content

Commit d798971

Browse files
committed
added test for cell spanning
1 parent 6ea2104 commit d798971

File tree

6 files changed

+105
-49
lines changed

6 files changed

+105
-49
lines changed

cypress/integration/common/utils.ts

+32-31
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export class Utilities {
2222
return this.config;
2323
}
2424

25-
isMacOs() {
25+
isMacOs(): boolean {
2626
return Cypress.platform === 'darwin';
2727
}
2828

29-
selectCell(clientX: number, clientY: number, customEventArgs = undefined) {
29+
selectCell(clientX: number, clientY: number, customEventArgs = undefined): void {
3030
const scrollableElement = this.getScrollableElement();
3131
if (customEventArgs !== undefined) {
3232
scrollableElement.trigger('pointerdown', clientX, clientY, { ...customEventArgs, pointerType: 'mouse' });
@@ -37,34 +37,35 @@ export class Utilities {
3737
cy.wait(500);
3838
}
3939

40-
scrollTo(left: number, top: number, duration = 500) {
41-
return this.getConfig().pinToBody ? cy.scrollTo(left, top, { duration, ensureScrollable: true }) :
42-
this.getScrollableElement().scrollTo(left, top, { duration, ensureScrollable: true });
40+
scrollTo(left: number, top: number, duration = 500): void {
41+
this.getConfig().pinToBody
42+
? cy.scrollTo(left, top, { duration, ensureScrollable: true })
43+
: this.getScrollableElement().scrollTo(left, top, { duration, ensureScrollable: true });
4344
}
4445

45-
wait() {
46+
wait(): number {
4647
return this.isMacOs() ? 50 : 100;
4748
}
4849

49-
scrollToBottom(left = 0) {
50+
scrollToBottom(left = 0): void {
5051
const offset = this.getBottomAddtionalOffset(true);
51-
return this.scrollTo(left, this.getConfig().rows * this.getConfig().cellHeight + offset);
52+
this.scrollTo(left, this.getConfig().rows * this.getConfig().cellHeight + offset);
5253
}
5354

54-
scrollToRight(top = 0) {
55+
scrollToRight(top = 0): void {
5556
const offset = this.getRightAddtionalOffset();
5657
this.scrollTo(this.getConfig().columns * this.getConfig().cellWidth + offset, top);
5758
}
5859

59-
getCellXCenter() {
60+
getCellXCenter(): number {
6061
return this.getConfig().cellWidth / 2;
6162
}
6263

63-
getCellYCenter() {
64+
getCellYCenter(): number {
6465
return this.getConfig().cellHeight / 2;
6566
}
6667

67-
selectCellInEditMode(clientX: number, clientY: number) {
68+
selectCellInEditMode(clientX: number, clientY: number): void {
6869
this.selectCell(clientX, clientY);
6970
this.keyDown(constants.keyCodes.Enter, { force: true });
7071
}
@@ -79,12 +80,12 @@ export class Utilities {
7980
return +(Math.round(((value + "e+" + places) as unknown) as number) + "e-" + places);
8081
}
8182

82-
resetSelection(x: number, y: number) {
83+
resetSelection(x: number, y: number): void {
8384
this.selectCell(x, y + this.getConfig().cellHeight);
8485
this.selectCell(x, y);
8586
}
8687

87-
keyDown(keyCode: number, customEventArgs?: {}, timeout = 200, log = true) {
88+
keyDown(keyCode: number, customEventArgs?: Record<string, unknown>, timeout = 200, log = true): void {
8889
const rg = this.getReactGridContent();
8990
if (customEventArgs !== undefined) {
9091
rg.trigger('keydown', { ...customEventArgs, keyCode, log, force: true });
@@ -95,62 +96,62 @@ export class Utilities {
9596
cy.wait(timeout, { log });
9697
}
9798

98-
getCell(x: number, y: number) {
99+
getCell(x: number, y: number): Cypress.Chainable {
99100
return cy.get(`[data-cell-colidx=${x}][data-cell-rowidx=${y}]`).eq(0);
100101
}
101102

102-
getScrollableElement() {
103+
getScrollableElement(): Cypress.Chainable {
103104
// TODO is Body correct element for getting scroll and sroll view?
104105
return this.config.pinToBody ? this.getBody() : this.getDivScrollableElement();
105106
}
106107

107-
getDivScrollableElement() {
108+
getDivScrollableElement(): Cypress.Chainable {
108109
return cy.get('.test-grid-container');
109110
}
110111

111-
getReactGrid() {
112+
getReactGrid(): Cypress.Chainable {
112113
return cy.get('.reactgrid');
113114
}
114115

115-
getReactGridContent() {
116+
getReactGridContent(): Cypress.Chainable {
116117
return cy.get('.reactgrid-content');
117118
}
118119

119-
getOuterInput() {
120+
getOuterInput(): Cypress.Chainable {
120121
return cy.get('[data-cy=outer-input]');
121122
}
122123

123-
getCellEditor() {
124+
getCellEditor(): Cypress.Chainable {
124125
return cy.get('.rg-celleditor');
125126
}
126127

127-
getBody() {
128+
getBody(): Cypress.Chainable {
128129
return cy.get('body');
129130
}
130131

131-
getLeftStickyPane() {
132+
getLeftStickyPane(): Cypress.Chainable {
132133
return cy.get('.rg-pane-left');
133134
}
134135

135-
getTopStickyPane() {
136+
getTopStickyPane(): Cypress.Chainable {
136137
return cy.get('.rg-pane-top');
137138
}
138139

139-
getCellFocus() {
140+
getCellFocus(): Cypress.Chainable {
140141
const cell = cy.get('.rg-cell-focus');
141142
cell.should('exist');
142143
return cell;
143144
}
144145

145-
getCellHighlight() {
146+
getCellHighlight(): Cypress.Chainable {
146147
return cy.get('.rg-cell-highlight');
147148
}
148149

149-
getDropdownMenu() {
150+
getDropdownMenu(): Cypress.Chainable {
150151
return cy.get('.dropdown-menu');
151152
}
152153

153-
click(x: number, y: number) {
154+
click(x: number, y: number): void {
154155
this.getScrollableElement().trigger('pointerdown', x, y, { pointerType: 'mouse' });
155156
this.getBody().trigger('pointerup', 0, 0, { pointerType: 'mouse', force: true }); //
156157
}
@@ -300,7 +301,7 @@ export class Utilities {
300301
}
301302
}
302303

303-
assertIsReactGridFocused() {
304+
assertIsReactGridFocused(): void {
304305
cy.focused().should('have.class', 'rg-hidden-element');
305306
}
306307

@@ -339,7 +340,7 @@ export class Utilities {
339340
}
340341
}
341342

342-
testCellEditor(testCase: CellEditorTestParams) {
343+
testCellEditor(testCase: CellEditorTestParams): void {
343344
let test: CellEditorTestParams = this.setScrollValues(testCase);
344345
test = this.moveClickPosByOnePixel(test);
345346
this.scrollTo(test.scroll.x, test.scroll.y);
@@ -348,7 +349,7 @@ export class Utilities {
348349
}
349350

350351

351-
testCellEditorOnSticky(testCase: CellEditorTestParams) {
352+
testCellEditorOnSticky(testCase: CellEditorTestParams): void {
352353
let test: CellEditorTestParams = this.setScrollValues(testCase);
353354
test = this.moveClickPosByOnePixel(test);
354355
if (this.getConfig().pinToBody) {

cypress/integration/common/visit.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,65 @@
11
/// <reference types="cypress" />
22

3-
export function visit() {
3+
export function visit(): void {
44
cy.visit('/');
55
}
66

7-
export function visitSticky() {
7+
export function visitSticky(): void {
88
cy.visit('/enableSticky');
99
}
1010

11-
export function visitFrozenFocus() {
11+
export function visitFrozenFocus(): void {
1212
cy.visit('/enableFrozenFocus');
1313
}
1414

15-
export function visitPinnedToBody() {
15+
export function visitPinnedToBody(): void {
1616
cy.visit('/enablePinnedToBody');
1717
}
1818

19-
export function visitAdditionalContent() {
19+
export function visitAdditionalContent(): void {
2020
cy.visit('/enableAdditionalContent');
2121
}
2222

23-
export function visitAdditionalContentWithFlexRow() {
23+
export function visitAdditionalContentWithFlexRow(): void {
2424
cy.visit('/enableAdditionalContent?flexRow=true');
2525
}
2626

27-
export function visitStickyPinnedToBody() {
27+
export function visitStickyPinnedToBody(): void {
2828
cy.visit('/enableStickyPinnedToBody');
2929
}
3030

31-
export function visitHeaders() {
31+
export function visitHeaders(): void {
3232
cy.visit('/enableHeaders');
3333
}
3434

35-
export function visitColumnAndRowSelections() {
35+
export function visitColumnAndRowSelections(): void {
3636
cy.visit('/enableColumnAndRowSelection');
3737
}
3838

39-
export function visitColumnAndRowSelectionsWithSticky() {
39+
export function visitColumnAndRowSelectionsWithSticky(): void {
4040
cy.visit('/enableColumnAndRowSelectionWithSticky');
4141
}
4242

43-
export function visitSymetric() {
43+
export function visitSymetric(): void {
4444
cy.visit('/enableSymetric');
4545
}
4646

47-
export function visitResponsiveSticky() {
47+
export function visitSpannedCells(): void {
48+
cy.visit('/enableSpannedCells');
49+
}
50+
51+
export function visitResponsiveSticky(): void {
4852
cy.visit('/enableResponsiveSticky');
4953
}
5054

51-
export function visitResponsiveStickyPinnedToBody() {
55+
export function visitResponsiveStickyPinnedToBody(): void {
5256
cy.visit('/enableResponsiveStickyPinnedToBody');
5357
}
5458

55-
export function visitResponsiveStickyPro() {
59+
export function visitResponsiveStickyPro(): void {
5660
cy.visit('/enableResponsiveStickyPro');
5761
}
5862

59-
export function visitResponsiveStickyPinnedToBodyPro() {
63+
export function visitResponsiveStickyPinnedToBodyPro(): void {
6064
cy.visit('/enableResponsiveStickyPinnedToBodyPro');
6165
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { visitSpannedCells } from '../../common/visit';
2+
import { Utilities } from '../../common/utils';
3+
import { enableSpannedCells as config } from '../../../../src/test/testEnvConfig';
4+
5+
const utils = new Utilities(config);
6+
7+
context('Spanning', () => {
8+
9+
beforeEach(() => {
10+
visitSpannedCells();
11+
});
12+
13+
it('should span cells in both axes', () => {
14+
const { idx, idy, colspan = 1, rowspan = 1 } = utils.getConfig().spannedCells[0];
15+
16+
utils.assertElementWidthIsEqual(utils.getCell(idx, idy), utils.getConfig().cellWidth * colspan);
17+
utils.assertElementHeightIsEqual(utils.getCell(idx, idy), utils.getConfig().cellHeight * rowspan);
18+
});
19+
20+
it('should span cells horizontally', () => {
21+
const { idx, idy, colspan = 1, rowspan = 1 } = utils.getConfig().spannedCells[1];
22+
23+
utils.assertElementWidthIsEqual(utils.getCell(idx, idy), utils.getConfig().cellWidth * colspan);
24+
utils.assertElementHeightIsEqual(utils.getCell(idx, idy), utils.getConfig().cellHeight * rowspan);
25+
});
26+
27+
it('should span cells vertically', () => {
28+
const { idx, idy, colspan = 1, rowspan = 1 } = utils.getConfig().spannedCells[2];
29+
30+
utils.assertElementWidthIsEqual(utils.getCell(idx, idy), utils.getConfig().cellWidth * colspan);
31+
utils.assertElementHeightIsEqual(utils.getCell(idx, idy), utils.getConfig().cellHeight * rowspan);
32+
});
33+
34+
35+
it('should render cell highlight on a spanned cell', () => {
36+
const { colspan = 1, rowspan = 1 } = utils.getConfig().spannedCells[0];
37+
38+
utils.assertElementWidthIsEqual(utils.getCellHighlight().eq(0), utils.getConfig().cellWidth * colspan + 1);
39+
utils.assertElementHeightIsEqual(utils.getCellHighlight().eq(0), utils.getConfig().cellHeight * rowspan + 1);
40+
41+
});
42+
43+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"cy:headerRow": "npx cypress run --headless --quiet --browser firefox -s 'cypress/integration/tests/headerRow/*'",
7575
"cy:pinnedToBody": "npx cypress run --headless --quiet --browser firefox -s 'cypress/integration/tests/pinnedToBody/*'",
7676
"cy:stickyPinnedToBody": "npx cypress run --headless --quiet --browser firefox -s 'cypress/integration/tests/stickyPinnedToBody/*'",
77+
"cy:spannedCells": "npx cypress run --headless --quiet --browser firefox -s 'cypress/integration/tests/spannedCells/*'",
7778
"remove-suffix": "cross-env SUFFIX=rc node ./node_modules/npm-version-suffix/run-remove-suffix.js"
7879
},
7980
"husky": {

src/test/testEnvConfig.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ export const enableResponsiveStickyPinnedToBody: TestConfig = {
136136

137137
export const enableSpannedCells: TestConfig = {
138138
...config,
139-
columns: 5,
140-
rows: 5,
141139
spannedCells: [
142140
{ idx: 1, idy: 1, rowspan: 2, colspan: 2 },
143-
{ idx: 2, idy: 3, rowspan: 0, colspan: 3 },
141+
{ idx: 2, idy: 3, colspan: 3 },
142+
{ idx: 6, idy: 5, rowspan: 5 },
144143
],
145144
headerCells: [
146145
{ idx: 2, idy: 1 },
147146
{ idx: 1, idy: 2 },
148147
{ idx: 2, idy: 2 },
149148
{ idx: 3, idy: 3 },
150149
{ idx: 4, idy: 3 },
150+
{ idx: 6, idy: 5 },
151+
{ idx: 6, idy: 6 },
152+
{ idx: 6, idy: 7 },
153+
{ idx: 6, idy: 8 },
154+
{ idx: 6, idy: 9 },
151155
]
152156
}
153157

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"allowJs": true,
2323
"skipLibCheck": true,
2424
"experimentalDecorators": true,
25+
"types": [
26+
"cypress"
27+
],
2528
"noFallthroughCasesInSwitch": true
2629
},
2730
"include": [

0 commit comments

Comments
 (0)