|
1 | 1 | describe('Column', function () { |
2 | | - before(function () { |
| 2 | + beforeEach(function () { |
3 | 3 | cy.visit('/'); |
4 | 4 | }); |
5 | 5 |
|
@@ -68,48 +68,62 @@ describe('Column', function () { |
68 | 68 | .and('match', /9\dpx/); |
69 | 69 | }); |
70 | 70 |
|
71 | | - it('keeps sticky columns pinned while scrolling horizontally', function () { |
72 | | - const expectPinned = (actual, expected) => { |
73 | | - expect(actual).to.be.closeTo(expected, 1); |
74 | | - }; |
| 71 | + it('pins a column from the dropdown menu', function () { |
| 72 | + cy.clickDropdown(2); |
| 73 | + cy.clickDropdownItem(2, 'Stick to left'); |
| 74 | + |
| 75 | + cy.window().then(win => win.datatable.getColumn(2)) |
| 76 | + .its('sticky') |
| 77 | + .should('eq', true); |
| 78 | + |
| 79 | + cy.get('.dt-scrollable').then(($scrollable) => { |
| 80 | + const scrollable = $scrollable[0]; |
| 81 | + const stickyBodyCell = Cypress.$('.dt-cell--2-0')[0]; |
| 82 | + const initialStickyBodyLeft = stickyBodyCell.getBoundingClientRect().left; |
| 83 | + |
| 84 | + scrollable.scrollLeft = 220; |
| 85 | + scrollable.dispatchEvent(new Event('scroll')); |
| 86 | + |
| 87 | + cy.wait(50).then(() => { |
| 88 | + const nextStickyBodyLeft = stickyBodyCell.getBoundingClientRect().left; |
| 89 | + expect(nextStickyBodyLeft).to.be.closeTo(initialStickyBodyLeft, 1); |
| 90 | + }); |
| 91 | + }); |
| 92 | + }); |
75 | 93 |
|
| 94 | + it('keeps sticky columns pinned while scrolling horizontally', function () { |
76 | 95 | cy.get('.dt-scrollable').then(($scrollable) => { |
77 | 96 | const scrollable = $scrollable[0]; |
78 | | - const stickyCheckboxBodyCell = Cypress.$('.dt-cell--0-0')[0]; |
79 | | - const stickyCheckboxHeaderCell = Cypress.$('.dt-cell--header-0')[0]; |
80 | | - const stickySerialBodyCell = Cypress.$('.dt-cell--1-0')[0]; |
81 | | - const stickySerialHeaderCell = Cypress.$('.dt-cell--header-1')[0]; |
82 | | - const stickyCustomBodyCell = Cypress.$('.dt-cell--2-0')[0]; |
83 | | - const stickyCustomHeaderCell = Cypress.$('.dt-cell--header-2')[0]; |
84 | | - const regularBodyCell = Cypress.$('.dt-cell--4-0')[0]; |
85 | | - |
86 | | - const initialStickyCheckboxBodyLeft = stickyCheckboxBodyCell.getBoundingClientRect().left; |
87 | | - const initialStickyCheckboxHeaderLeft = stickyCheckboxHeaderCell.getBoundingClientRect().left; |
88 | | - const initialStickySerialBodyLeft = stickySerialBodyCell.getBoundingClientRect().left; |
89 | | - const initialStickySerialHeaderLeft = stickySerialHeaderCell.getBoundingClientRect().left; |
90 | | - const initialStickyCustomBodyLeft = stickyCustomBodyCell.getBoundingClientRect().left; |
91 | | - const initialStickyCustomHeaderLeft = stickyCustomHeaderCell.getBoundingClientRect().left; |
92 | | - const initialRegularBodyLeft = regularBodyCell.getBoundingClientRect().left; |
| 97 | + const checkboxBodyCell = Cypress.$('.dt-cell--0-0')[0]; |
| 98 | + const checkboxHeaderCell = Cypress.$('.dt-cell--header-0')[0]; |
| 99 | + const serialBodyCell = Cypress.$('.dt-cell--1-0')[0]; |
| 100 | + const serialHeaderCell = Cypress.$('.dt-cell--header-1')[0]; |
| 101 | + const officeBodyCell = Cypress.$('.dt-cell--4-0')[0]; |
| 102 | + const officeHeaderCell = Cypress.$('.dt-cell--header-4')[0]; |
| 103 | + const nameBodyCell = Cypress.$('.dt-cell--2-0')[0]; |
| 104 | + |
| 105 | + const initialCheckboxLeft = checkboxBodyCell.getBoundingClientRect().left; |
| 106 | + const initialSerialLeft = serialBodyCell.getBoundingClientRect().left; |
| 107 | + const initialNameLeft = nameBodyCell.getBoundingClientRect().left; |
93 | 108 |
|
94 | 109 | scrollable.scrollLeft = 220; |
95 | 110 | scrollable.dispatchEvent(new Event('scroll')); |
96 | 111 |
|
97 | 112 | cy.wait(50).then(() => { |
98 | | - const nextStickyCheckboxBodyLeft = stickyCheckboxBodyCell.getBoundingClientRect().left; |
99 | | - const nextStickyCheckboxHeaderLeft = stickyCheckboxHeaderCell.getBoundingClientRect().left; |
100 | | - const nextStickySerialBodyLeft = stickySerialBodyCell.getBoundingClientRect().left; |
101 | | - const nextStickySerialHeaderLeft = stickySerialHeaderCell.getBoundingClientRect().left; |
102 | | - const nextStickyCustomBodyLeft = stickyCustomBodyCell.getBoundingClientRect().left; |
103 | | - const nextStickyCustomHeaderLeft = stickyCustomHeaderCell.getBoundingClientRect().left; |
104 | | - const nextRegularBodyLeft = regularBodyCell.getBoundingClientRect().left; |
105 | | - |
106 | | - expectPinned(nextStickyCheckboxBodyLeft, initialStickyCheckboxBodyLeft); |
107 | | - expectPinned(nextStickyCheckboxHeaderLeft, initialStickyCheckboxHeaderLeft); |
108 | | - expectPinned(nextStickySerialBodyLeft, initialStickySerialBodyLeft); |
109 | | - expectPinned(nextStickySerialHeaderLeft, initialStickySerialHeaderLeft); |
110 | | - expectPinned(nextStickyCustomBodyLeft, initialStickyCustomBodyLeft); |
111 | | - expectPinned(nextStickyCustomHeaderLeft, initialStickyCustomHeaderLeft); |
112 | | - expect(nextRegularBodyLeft).to.be.lessThan(initialRegularBodyLeft); |
| 113 | + const nextCheckboxBodyLeft = checkboxBodyCell.getBoundingClientRect().left; |
| 114 | + const nextCheckboxHeaderLeft = checkboxHeaderCell.getBoundingClientRect().left; |
| 115 | + const nextSerialBodyLeft = serialBodyCell.getBoundingClientRect().left; |
| 116 | + const nextSerialHeaderLeft = serialHeaderCell.getBoundingClientRect().left; |
| 117 | + const nextOfficeBodyLeft = officeBodyCell.getBoundingClientRect().left; |
| 118 | + const nextOfficeHeaderLeft = officeHeaderCell.getBoundingClientRect().left; |
| 119 | + const nextNameLeft = nameBodyCell.getBoundingClientRect().left; |
| 120 | + |
| 121 | + expect(nextCheckboxBodyLeft).to.be.closeTo(initialCheckboxLeft, 1); |
| 122 | + expect(nextSerialBodyLeft).to.be.closeTo(initialSerialLeft, 1); |
| 123 | + expect(nextCheckboxHeaderLeft).to.be.closeTo(nextCheckboxBodyLeft, 1); |
| 124 | + expect(nextSerialHeaderLeft).to.be.closeTo(nextSerialBodyLeft, 1); |
| 125 | + expect(nextOfficeHeaderLeft).to.be.closeTo(nextOfficeBodyLeft, 1); |
| 126 | + expect(nextNameLeft).to.be.lessThan(initialNameLeft); |
113 | 127 | }); |
114 | 128 | }); |
115 | 129 | }); |
|
0 commit comments