-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add generated test case #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||
```javascript | ||||||
import 'cypress-real-events'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import. The Apply this diff if real events aren't required: -import 'cypress-real-events';
- Alternatively, if real browser events are needed for more accurate testing, use 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
|
||||||
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); | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the markdown code fence wrapper.
The file is wrapped in markdown code fence syntax (triple backticks), which is invalid JavaScript. This will cause parse failures when Cypress attempts to load the test file.
Apply this diff to remove the wrapper:
-```javascript import 'cypress-real-events';
Also remove line 59:
-```
🤖 Prompt for AI Agents