|
| 1 | +describe('Example 43 - Dynamically Create Grid from CSV / Excel import', () => { |
| 2 | + const defaultCsvTitles = ['First Name', 'Last Name', 'Age', 'Type']; |
| 3 | + const GRID_ROW_HEIGHT = 33; |
| 4 | + |
| 5 | + it('should display Example title', () => { |
| 6 | + cy.visit(`${Cypress.config('baseUrl')}/csv-grid`); |
| 7 | + cy.get('h2').should('contain', 'Example 43: Dynamically Create Grid from CSV / Excel import'); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should load default CSV file and expect default column titles', () => { |
| 11 | + cy.get('[data-test="static-data-btn"]') |
| 12 | + .click(); |
| 13 | + |
| 14 | + cy.get('.slick-header-columns') |
| 15 | + .children() |
| 16 | + .each(($child, index) => expect($child.text()).to.eq(defaultCsvTitles[index])); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should expect default data in the grid', () => { |
| 20 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', 'Bob'); |
| 21 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Smith'); |
| 22 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(2)`).should('contain', '33'); |
| 23 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(3)`).should('contain', 'Teacher'); |
| 24 | + |
| 25 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(0)`).should('contain', 'John'); |
| 26 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 27 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(2)`).should('contain', '20'); |
| 28 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 29 | + |
| 30 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(0)`).should('contain', 'Jane'); |
| 31 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 32 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(2)`).should('contain', '21'); |
| 33 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should sort by "Age" and expect it to be sorted in ascending order', () => { |
| 37 | + cy.get('.slick-header-columns .slick-header-column:nth(2)') |
| 38 | + .click(); |
| 39 | + |
| 40 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', 'John'); |
| 41 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 42 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(2)`).should('contain', '20'); |
| 43 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 44 | + |
| 45 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(0)`).should('contain', 'Jane'); |
| 46 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 47 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(2)`).should('contain', '21'); |
| 48 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 49 | + |
| 50 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(0)`).should('contain', 'Bob'); |
| 51 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(1)`).should('contain', 'Smith'); |
| 52 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(2)`).should('contain', '33'); |
| 53 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(3)`).should('contain', 'Teacher'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should click again the "Age" column and expect it to be sorted in descending order', () => { |
| 57 | + cy.get('.slick-header-columns .slick-header-column:nth(2)') |
| 58 | + .click(); |
| 59 | + |
| 60 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', 'Bob'); |
| 61 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Smith'); |
| 62 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(2)`).should('contain', '33'); |
| 63 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(3)`).should('contain', 'Teacher'); |
| 64 | + |
| 65 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(0)`).should('contain', 'Jane'); |
| 66 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 67 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(2)`).should('contain', '21'); |
| 68 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 1}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 69 | + |
| 70 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(0)`).should('contain', 'John'); |
| 71 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(1)`).should('contain', 'Doe'); |
| 72 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(2)`).should('contain', '20'); |
| 73 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 2}px;"] > .slick-cell:nth(3)`).should('contain', 'Student'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should filter Smith as "Last Name" and expect only 1 row in the grid', () => { |
| 77 | + cy.get('.slick-headerrow .slick-headerrow-column:nth(1) input') |
| 78 | + .type('Smith'); |
| 79 | + |
| 80 | + cy.get('.slick-row') |
| 81 | + .should('have.length', 1); |
| 82 | + |
| 83 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(0)`).should('contain', 'Bob'); |
| 84 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(1)`).should('contain', 'Smith'); |
| 85 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(2)`).should('contain', '33'); |
| 86 | + cy.get(`[style="top: ${GRID_ROW_HEIGHT * 0}px;"] > .slick-cell:nth(3)`).should('contain', 'Teacher'); |
| 87 | + }); |
| 88 | +}); |
0 commit comments