|
| 1 | +describe('Conditional Choices in Tables within Pages', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.visit('/pages_conditional_tables'); |
| 4 | + }); |
| 5 | + |
| 6 | + afterEach(() => { |
| 7 | + cy.exec('rm -f ./cypress/yaml/pages_conditional_tables/values.yaml'); |
| 8 | + cy.clearOPFS(); |
| 9 | + }); |
| 10 | + |
| 11 | + const prefix = 'pages_component.page1.products_table'; |
| 12 | + |
| 13 | + it('should have correct nested field names', () => { |
| 14 | + cy.get(`select[name="${prefix}._1.category"]`).should('exist'); |
| 15 | + cy.get(`select[name="${prefix}._1.product"]`).should('exist'); |
| 16 | + cy.get(`input[name="${prefix}._1.quantity"]`).should('exist'); |
| 17 | + |
| 18 | + cy.get(`select[name="${prefix}._2.category"]`).should('exist'); |
| 19 | + cy.get(`select[name="${prefix}._2.product"]`).should('exist'); |
| 20 | + cy.get(`input[name="${prefix}._2.quantity"]`).should('exist'); |
| 21 | + |
| 22 | + cy.get(`select[name="${prefix}._3.category"]`).should('exist'); |
| 23 | + cy.get(`select[name="${prefix}._3.product"]`).should('exist'); |
| 24 | + cy.get(`input[name="${prefix}._3.quantity"]`).should('exist'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should show fruit choices when category is fruits in column 1', () => { |
| 28 | + cy.get(`select[name="${prefix}._1.category"]`).select('some fruits'); |
| 29 | + |
| 30 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 31 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 32 | + expect(values).to.deep.equal(['apple', 'banana', 'orange']); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should show vegetable choices when category is vegetables in column 1', () => { |
| 37 | + cy.get(`select[name="${prefix}._1.category"]`).select('some vegetables'); |
| 38 | + cy.wait(500); |
| 39 | + |
| 40 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 41 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 42 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should maintain independent choices across different table columns', () => { |
| 47 | + cy.get(`select[name="${prefix}._1.category"]`).select('some fruits'); |
| 48 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 49 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 50 | + expect(values).to.deep.equal(['apple', 'banana', 'orange']); |
| 51 | + }); |
| 52 | + |
| 53 | + cy.get(`select[name="${prefix}._2.category"]`).select('some vegetables'); |
| 54 | + cy.get(`select[name="${prefix}._2.product"] option`).then($options => { |
| 55 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 56 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 57 | + }); |
| 58 | + |
| 59 | + // Column 1 should still show fruits |
| 60 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 61 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 62 | + expect(values).to.deep.equal(['apple', 'banana', 'orange']); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should update product choices when category is changed', () => { |
| 67 | + cy.get(`select[name="${prefix}._1.category"]`).select('some fruits'); |
| 68 | + cy.get(`select[name="${prefix}._1.product"]`).select('apple'); |
| 69 | + |
| 70 | + cy.get(`select[name="${prefix}._1.category"]`).select('some vegetables'); |
| 71 | + cy.wait(500); |
| 72 | + |
| 73 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 74 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 75 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 76 | + }); |
| 77 | + |
| 78 | + cy.get(`select[name="${prefix}._1.product"]`).should('have.value', ''); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should test all three columns independently', () => { |
| 82 | + cy.get(`select[name="${prefix}._1.category"]`).select('some vegetables'); |
| 83 | + cy.wait(500); |
| 84 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 85 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 86 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 87 | + }); |
| 88 | + |
| 89 | + cy.get(`select[name="${prefix}._2.category"]`).select('some vegetables'); |
| 90 | + cy.wait(500); |
| 91 | + cy.get(`select[name="${prefix}._2.product"] option`).then($options => { |
| 92 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 93 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 94 | + }); |
| 95 | + |
| 96 | + cy.get(`select[name="${prefix}._3.category"]`).select('some vegetables'); |
| 97 | + cy.wait(500); |
| 98 | + cy.get(`select[name="${prefix}._3.product"] option`).then($options => { |
| 99 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 100 | + expect(values).to.deep.equal(['carrot', 'broccoli', 'lettuce']); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should work with pre-filled values on initial render', () => { |
| 105 | + cy.get(`select[name="${prefix}._1.category"]`).select('some fruits'); |
| 106 | + cy.get(`select[name="${prefix}._1.product"]`).select('banana'); |
| 107 | + cy.get(`input[name="${prefix}._1.quantity"]`).type('5'); |
| 108 | + |
| 109 | + cy.get('button[name="save"]').click(); |
| 110 | + cy.get('.notification > p').should('be.visible'); |
| 111 | + |
| 112 | + cy.visit('/pages_conditional_tables'); |
| 113 | + |
| 114 | + cy.get(`select[name="${prefix}._1.category"]`).should('have.value', 'some fruits'); |
| 115 | + cy.get(`select[name="${prefix}._1.product"]`).should('have.value', 'banana'); |
| 116 | + cy.get(`select[name="${prefix}._1.product"] option`).then($options => { |
| 117 | + const values = [...$options].map(o => o.value).filter(v => v !== ''); |
| 118 | + expect(values).to.deep.equal(['apple', 'banana', 'orange']); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments