|
| 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