-
Notifications
You must be signed in to change notification settings - Fork 41
Junior Developer Challenge: Write a Cypress Test + Fix a Basic Bug #15
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
Open
owl099
wants to merge
10
commits into
pranab1981:main
Choose a base branch
from
owl099:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c514e4e
handled teh onsubmit effect:
owl099 78051dc
Update App.js
owl099 e21dbad
Update LoginForm.js
owl099 a035e00
minor changes in comments
owl099 7a2b281
minor changes LoginForm.js
owl099 2ba6882
Merge branch 'main' of https://github.com/owl099/entry-test
owl099 1e80210
Merge branch 'main' of https://github.com/owl099/entry-test
owl099 4977851
commit
owl099 5b54dba
commit
owl099 f2f543e
Update README.md
owl099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,40 @@ | ||
| describe('Login Component', () => { | ||
| }) | ||
|
|
||
| describe('Login Flow', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/login'); | ||
| }); | ||
|
|
||
| it('displays the login form', () => { | ||
| cy.get('input#name').should('be.visible'); | ||
| cy.get('input#password').should('be.visible'); | ||
| cy.get('button[type="submit"]').contains('Login'); | ||
| }); | ||
|
|
||
| it('allows a user to login and redirects to /welcome', () => { | ||
| cy.get('input#name').type('TestUser'); | ||
| cy.get('input#password').type('password123'); | ||
| cy.get('button[type="submit"]').click(); | ||
|
|
||
| // After login, URL should be /welcome | ||
| cy.url().should('include', '/welcome'); | ||
|
|
||
| // Welcome message should contain username | ||
| cy.contains('Welcome, TestUser!').should('be.visible'); | ||
| }); | ||
|
|
||
| it('logs out and redirects back to login page', () => { | ||
| // First login | ||
| cy.get('input#name').type('TestUser'); | ||
| cy.get('input#password').type('password123'); | ||
| cy.get('button[type="submit"]').click(); | ||
|
|
||
| // Click logout button | ||
| cy.get('button.logout-button').click(); | ||
|
|
||
| // URL should be /login | ||
| cy.url().should('include', '/login'); | ||
|
|
||
| // Login form should be visible again | ||
| cy.get('input#name').should('be.visible'); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,51 @@ | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import './App.css'; | ||
| import { BrowserRouter as Router, Routes, Route, Navigate, useNavigate } from 'react-router-dom'; | ||
| import LoginForm from './components/LoginForm'; | ||
| import Welcome from './components/Welcome'; | ||
|
|
||
| function App() { | ||
| const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
| const [userName, setUserName] = useState(''); | ||
|
|
||
| return ( | ||
| <Router> | ||
| <Routes> | ||
| <Route path="/login" element={<LoginPage setIsLoggedIn={setIsLoggedIn} setUserName={setUserName} />} /> | ||
| <Route | ||
| path="/welcome" | ||
| element={ | ||
| isLoggedIn ? ( | ||
| <Welcome userName={userName} onLogout={() => { | ||
| setIsLoggedIn(false); | ||
| setUserName(''); | ||
| }} /> | ||
| ) : ( | ||
| <Navigate to="/login" replace /> | ||
| ) | ||
| } | ||
| /> | ||
| {/* Redirecting any unknown route to login */} | ||
| <Route path="*" element={<Navigate to="/login" replace />} /> | ||
| </Routes> | ||
| </Router> | ||
| ); | ||
| } | ||
|
|
||
| // Creating a wrapper component for the Login Form to handle login and navigation | ||
| function LoginPage({ setIsLoggedIn, setUserName }) { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const handleLogin = (formData) => { | ||
| // In a real app, you would validate credentials here | ||
|
|
||
| setIsLoggedIn(true); | ||
| setUserName(formData.name); | ||
| // Redirecting to welcome page after login | ||
| navigate('/welcome'); | ||
| }; | ||
|
|
||
| const handleLogout = () => { | ||
| setIsLoggedIn(false); | ||
| setUserName(''); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="App"> | ||
| {isLoggedIn ? ( | ||
| <Welcome userName={userName} onLogout={handleLogout} /> | ||
| ) : ( | ||
| <LoginForm onLogin={handleLogin} /> | ||
| )} | ||
| </div> | ||
| ); | ||
| return <LoginForm onLogin={handleLogin} />; | ||
| } | ||
|
|
||
| export default App; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Verify the react-router-dom version compatibility.
The addition of react-router-dom is appropriate for implementing the routing functionality, but the specified version (
^7.6.0) appears unusually high considering the current stable releases.🌐 Web query:
💡 Result:
As of May 20, 2025, the latest stable version of
react-router-domis v7.5.3, released on May 13, 2025. (npmjs.com)This release includes the
route.lazyobject API, offering more granular control over the lazy loading of route properties. (reactrouter.com)For more details, you can refer to the React Router changelog.
Citations:
Update react-router-dom to the latest stable version
The dependency is currently pinned to a non-existent v7.6.0. As of May 20, 2025 the latest stable release is v7.5.3. Please update your
package.json:This ensures you’re using a valid, supported version.
Citations:
📝 Committable suggestion
🤖 Prompt for AI Agents