|
| 1 | +const PAGE = '/tools/longevity-protocol/habits/diet'; |
| 2 | + |
| 3 | +describe('Diet – /tools/longevity-protocol/habits/diet', () => { |
| 4 | + describe('Desktop (1920x900)', () => { |
| 5 | + beforeEach(() => { |
| 6 | + cy.viewport(1920, 900); |
| 7 | + cy.visit(PAGE); |
| 8 | + }); |
| 9 | + |
| 10 | + // 1. H1 existence |
| 11 | + it('has a visible H1', () => { |
| 12 | + cy.checkH1(); |
| 13 | + }); |
| 14 | + |
| 15 | + // 2. Japanese text existence |
| 16 | + it('has Japanese text rendered', () => { |
| 17 | + cy.checkJapaneseText(); |
| 18 | + }); |
| 19 | + |
| 20 | + // 3. WhatToEatOrAvoid – click second selectable item, checkbox state updates |
| 21 | + it('updates checkbox state when clicking a WhatToEatOrAvoid item', () => { |
| 22 | + // Items with role="checkbox" only exist in the "what to eat" section |
| 23 | + cy.scrollTo(0, 1600); |
| 24 | + cy.get('[data-cy="diet-checkbox"]').eq(0).scrollIntoView(); |
| 25 | + |
| 26 | + // First item starts selected – checkmark is present |
| 27 | + cy.get('[data-cy="diet-checkbox"]') |
| 28 | + .eq(0) |
| 29 | + .find('[data-cy="diet-checkmark"]') |
| 30 | + .should('exist'); |
| 31 | + |
| 32 | + // Click the second selectable item |
| 33 | + cy.get('[data-cy="diet-checkbox"]') |
| 34 | + .eq(1) |
| 35 | + .closest('[data-cy="what-to-eat-or-avoid"]') |
| 36 | + .click({ force: true }); |
| 37 | + |
| 38 | + // Second item is now checked |
| 39 | + cy.get('[data-cy="diet-checkbox"]') |
| 40 | + .eq(1) |
| 41 | + .find('[data-cy="diet-checkmark"]') |
| 42 | + .should('exist'); |
| 43 | + |
| 44 | + // First item is now unchecked |
| 45 | + cy.get('[data-cy="diet-checkbox"]') |
| 46 | + .eq(0) |
| 47 | + .find('[data-cy="diet-checkmark"]') |
| 48 | + .should('not.exist'); |
| 49 | + }); |
| 50 | + |
| 51 | + // 4. DietResults – click second item → active states update + YourDiet data changes |
| 52 | + it('activates second DietResults item and updates YourDiet data', () => { |
| 53 | + // Scroll to the DietResults component |
| 54 | + cy.get('[data-cy="diet-results-item"]').first().scrollIntoView(); |
| 55 | + cy.wait(300); |
| 56 | + |
| 57 | + // Dismiss the cookie banner so it does not cover the result items |
| 58 | + cy.get('[data-cy="cookie-box-accept"]').click(); |
| 59 | + |
| 60 | + // Initial state: first item (id=1) is active, second is not |
| 61 | + cy.get('[data-cy="diet-results-item"]') |
| 62 | + .eq(0) |
| 63 | + .should('have.attr', 'data-active', 'true'); |
| 64 | + cy.get('[data-cy="diet-results-item"]') |
| 65 | + .eq(1) |
| 66 | + .should('have.attr', 'data-active', 'false'); |
| 67 | + |
| 68 | + // Capture the current YourDiet selected id before the change |
| 69 | + cy.get('[data-cy="your-diet"]') |
| 70 | + .invoke('attr', 'data-selected-id') |
| 71 | + .then(idBefore => { |
| 72 | + // Click the inner img of the second item; the img click bubbles to the |
| 73 | + // parent div's onClick and avoids any ::after overlay that may block the hit |
| 74 | + cy.get('[data-cy="diet-results-item"]') |
| 75 | + .eq(1) |
| 76 | + .find('img') |
| 77 | + .click({ force: true }); |
| 78 | + |
| 79 | + cy.wait(300); |
| 80 | + |
| 81 | + // Active states have flipped |
| 82 | + cy.get('[data-cy="diet-results-item"]') |
| 83 | + .eq(1) |
| 84 | + .should('have.attr', 'data-active', 'true'); |
| 85 | + cy.get('[data-cy="diet-results-item"]') |
| 86 | + .eq(0) |
| 87 | + .should('have.attr', 'data-active', 'false'); |
| 88 | + |
| 89 | + // YourDiet animation was triggered |
| 90 | + cy.get('[data-cy="your-diet"]').should( |
| 91 | + 'have.attr', |
| 92 | + 'data-active', |
| 93 | + 'true', |
| 94 | + ); |
| 95 | + |
| 96 | + // YourDiet is now displaying a different diet entry (data-selected-id changed) |
| 97 | + cy.get('[data-cy="your-diet"]') |
| 98 | + .invoke('attr', 'data-selected-id') |
| 99 | + .should('not.equal', idBefore); |
| 100 | + }); |
| 101 | + }); |
| 102 | + // 5. All internal and external links are valid (reuses shared checkPageLinks command) |
| 103 | + it('has no broken internal or external links', () => { |
| 104 | + cy.checkPageLinks(); |
| 105 | + }); |
| 106 | + |
| 107 | + // 6. All images load – no undefined in src paths |
| 108 | + it('has no images with undefined or broken src paths', () => { |
| 109 | + cy.get('img').each($img => { |
| 110 | + const src = $img.attr('src'); |
| 111 | + |
| 112 | + expect(src, 'img src should be defined').to.not.be.undefined; |
| 113 | + expect( |
| 114 | + src, |
| 115 | + `img src should not contain "undefined": ${src}`, |
| 116 | + ).to.not.include('undefined'); |
| 117 | + |
| 118 | + if (src && src.startsWith('/')) { |
| 119 | + cy.request({ url: src, failOnStatusCode: false }).then(res => { |
| 120 | + expect(res.status, `Image returned ${res.status}: ${src}`).to.be.lt( |
| 121 | + 400, |
| 122 | + ); |
| 123 | + }); |
| 124 | + } |
| 125 | + }); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + describe('Mobile (390x844)', () => { |
| 130 | + beforeEach(() => { |
| 131 | + cy.viewport(390, 844); |
| 132 | + cy.visit(PAGE); |
| 133 | + }); |
| 134 | + |
| 135 | + // Mobile modal – tapping the heart image in WhatToEatOrAvoid opens the |
| 136 | + // AboutTheProduct modal; closing via the modal close icon dismisses it |
| 137 | + it('opens and closes the mobile AboutTheProduct modal on heart image tap', () => { |
| 138 | + // Dismiss the cookie banner before any interaction |
| 139 | + cy.get('[data-cy="cookie-box-accept"]').click(); |
| 140 | + |
| 141 | + // Scroll to the first WhatToEatOrAvoid card that has a heart trigger |
| 142 | + cy.get('[data-cy="heart-trigger"]').first().scrollIntoView(); |
| 143 | + |
| 144 | + // Tap the heart image – on mobile this opens the modal instead of a tooltip |
| 145 | + cy.get('[data-cy="heart-trigger"]') |
| 146 | + .first() |
| 147 | + .find('img') |
| 148 | + .click({ force: true }); |
| 149 | + |
| 150 | + // AboutTheProduct content is now visible inside the portal modal |
| 151 | + cy.get('[data-cy="about-product"]').should('be.visible'); |
| 152 | + |
| 153 | + // Close via the modal close icon |
| 154 | + cy.get('[data-cy="modal-close-icon"]').click(); |
| 155 | + |
| 156 | + // Modal and its content are gone |
| 157 | + cy.get('[data-cy="about-product"]').should('not.exist'); |
| 158 | + }); |
| 159 | + }); |
| 160 | +}); |
| 161 | + |
| 162 | +export {}; |
0 commit comments