From c07518282cf912a531a9f3448c9d1f675c495c42 Mon Sep 17 00:00:00 2001 From: eshfaq-ux <64083614+eshfaq-ux@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:56:43 +0530 Subject: [PATCH] feat: Add generated.test.js --- generated.test.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 generated.test.js diff --git a/generated.test.js b/generated.test.js new file mode 100644 index 0000000..c41da4b --- /dev/null +++ b/generated.test.js @@ -0,0 +1,59 @@ +```javascript +import 'cypress-real-events'; + +describe('Navigation Smooth Scrolling', () => { + const navLinks = [ + { text: 'About', id: '#about' }, + { text: 'Services', id: '#services' }, + { text: 'Portfolio', id: '#portfolio' }, + { text: 'Contact', id: '#contact' }, + ]; + + beforeEach(() => { + // Visit the local HTML file. + // The path should be relative to the project's root or configured cypress.json `baseUrl`. + cy.visit('source code/webdev.html'); + // Ensure the page has some height to allow for scrolling + cy.viewport(1280, 2000); + }); + + it('should smoothly scroll the page to the corresponding section when a navigation link is clicked', () => { + navLinks.forEach(link => { + cy.log(`Testing navigation to ${link.id}`); + + // Find the link by its text and click it + cy.get('header nav').contains('a', link.text).click(); + + // The URL hash should update to match the link's href + cy.hash().should('eq', link.id); + + // Verify that the target section is now at or near the top of the viewport. + // This confirms the scroll was successful. We use a small threshold to account for + // minor rendering differences across browsers. + cy.get(link.id).then($section => { + const position = $section[0].getBoundingClientRect(); + expect(position.top).to.be.closeTo(0, 1); // Allow 1px tolerance + }); + + // Scroll back to the top for the next iteration to ensure a consistent starting point + cy.scrollTo('top'); + }); + }); + + it('should scroll to the contact section when the "Get in Touch" button is clicked', () => { + cy.log('Testing "Get in Touch" button'); + + // Click the hero section button + cy.get('#hero .btn').contains('Get in Touch').click(); + + // The URL hash should update to #contact + cy.hash().should('eq', '#contact'); + + // The contact section should be at the top of the viewport + cy.get('#contact').then($section => { + const position = $section[0].getBoundingClientRect(); + expect(position.top).to.be.closeTo(0, 1); + }); + }); +}); +``` \ No newline at end of file