Skip to content
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

Refactor/login page cypress testing #62

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Binary file added cypress/downloads/downloads.html
Binary file not shown.
211 changes: 175 additions & 36 deletions cypress/e2e/LoginSpec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ describe('testing for Login page', () => {
cy.get('[data-testid="login-button"]').click()
});

it('checks for the elements on the page', () => {
cy.get('.turing-logo').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > h1').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > h1').should('contain', 'Please login')
it.skip('checks for the elements on the page', () => {
cy.get('.login-form-wrap > .form-inputs > .flex > .turing-logo').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > h1').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > h1').should('contain', 'Please login')

.get('.login-form-wrap > .form-inputs > form > .email-input > label').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .email-input > label').should('contain', 'Email:')
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').should('contain', '')
.get('.login-form-wrap > .form-inputs > form > .email-input > label').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .email-input > label').should('contain', 'Email:')
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').should('contain', '')

.get('.login-form-wrap > .form-inputs > form > .password-input > label').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .password-input > label').should('contain', 'Password:')
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').should('contain', '')
.get('.login-form-wrap > .form-inputs > form > .password-input > label').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .password-input > label').should('contain', 'Password:')
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').should('contain', '')

.get('.login-form-wrap > .form-inputs > form > .login-btn').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .login-btn').should('contain', 'Login')
Expand All @@ -28,22 +28,154 @@ describe('testing for Login page', () => {
.get('a').should('be.visible')
.get('a').should('contain', 'Here')

.get('.login-form-wrap > .quad-color-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .cyan-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .yellow-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .red-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .green-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .cyan-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .yellow-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .red-bar').should('be.visible')
.get('.login-form-wrap > .quad-color-bar > .green-bar').should('be.visible')

.get('.login-form-wrap > .title-wrap').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-name').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-name').should('contain', 'Tracker')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-author').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-author').should('contain', 'by Turing')
.get('.login-form-wrap > .title-wrap > .app-tagline').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-tagline').should('contain', 'Job hunting made easier')
.get('.login-form-wrap > .title-wrap').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-name').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-name').should('contain', 'Tracker')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-author').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-name-and-author > .app-author').should('contain', 'by Turing')
.get('.login-form-wrap > .title-wrap > .app-tagline').should('be.visible')
.get('.login-form-wrap > .title-wrap > .app-tagline').should('contain', 'Job hunting made easier')
});

it('tests login page funtionality', () => {
it.skip('checks the navigation to the user registration page', () => { // This test is needs the UserRegistration branch to merge to main
cy.get('.login-form-wrap > .form-inputs > form > .no-account-message > a').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .no-account-message > a').click()
.get('.turing-logo').should('be.visible')
.get('.login-form-wrap > .form-inputs > form > .create-account').should('contain', 'Create Account')
});

it('logs in a user successfully', () => {
cy.get('.login-form-wrap > .form-inputs > form > .email-input > #email').type("[email protected]")
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').type("W3reD1dYouC0meFromW3reDidY0uGo!$")
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 200,
body: {
"token": "fake-token",
"user":{
"data": {
"id": "21",
"type": "user",
"attributes": {
"name": "Cotton Eyed Joe",
"email": "[email protected]"
}
}
}
}
})
cy.intercept("GET", "http://localhost:3001/api/v1/users/21/dashboard", {
statusCode: 200,
body: {
"data": {
"id": "21",
"type": "dashboard",
"attributes": {
"id": 21,
"name": "Cotton Eyed Joe",
"email": "[email protected]",
"dashboard": {
"weekly_summary": {
"job_applications": [
{
"id": 1,
"position_title": "Jr. CTO",
"date_applied": "2024-10-31",
"status": 1,
"notes": "Fingers crossed!",
"job_description": "Looking for Turing grad/jr dev to be CTO",
"application_url": "www.example.com",
"contact_information": "[email protected]",
"created_at": "2024-12-14T17:20:41.979Z",
"updated_at": "2024-12-14T17:20:41.979Z",
"company_id": 1,
"user_id": 5
},
{
"id": 2,
"position_title": " CTO",
"date_applied": "2024-10-31",
"status": 2,
"notes": "Fingers crossed!",
"job_description": "Looking for Turing grad/jr dev to be CTO",
"application_url": "www.testexample.com",
"contact_information": "[email protected]",
"created_at": "2024-12-14T17:37:28.465Z",
"updated_at": "2024-12-14T17:37:28.465Z",
"company_id": 2,
"user_id": 5
}
],
"contacts": [
{
"id": 1,
"first_name": "Jonny",
"last_name": "Smith",
"email": "[email protected]",
"phone_number": "555-785-5555",
"notes": "Good contact for XYZ",
"created_at": "2024-12-14T17:55:21.875Z",
"updated_at": "2024-12-14T17:55:21.875Z",
"user_id": 5,
"company_id": 1
},
{
"id": 2,
"first_name": "Josnny",
"last_name": "Smsith",
"email": "[email protected]",
"phone_number": "555-785-5555",
"notes": "Good contact for XYZ",
"created_at": "2024-12-15T01:57:14.557Z",
"updated_at": "2024-12-15T01:57:14.557Z",
"user_id": 5,
"company_id": 1
}
],
"companies": [
{
"id": 1,
"user_id": 5,
"name": "New Company",
"website": "www.company.com",
"street_address": "123 Main St",
"city": "New York",
"state": "NY",
"zip_code": "10001",
"notes": "This is a new company.",
"created_at": "2024-12-14T17:20:10.909Z",
"updated_at": "2024-12-14T17:20:10.909Z"
},
{
"id": 2,
"user_id": 5,
"name": "New Company1",
"website": "www.company1.com",
"street_address": "1231 Main St",
"city": "New York",
"state": "NY",
"zip_code": "10001",
"notes": "This is a new company1.",
"created_at": "2024-12-14T17:37:24.153Z",
"updated_at": "2024-12-14T17:37:24.153Z"
}
]
}
}
}
}
}
})
.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.flex > .flex-grow > .fixed > h1').should('contain', 'Welcome, Cotton Eyed Joe')
});

it.skip('tries to log in as a user that doesn\'t exist', () => {
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 401,
body: {
Expand All @@ -53,17 +185,24 @@ describe('testing for Login page', () => {
}).as("postUserInfo");

cy.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').then(($input) => {
expect($input[0].validationMessage).to.eq('Please fill out this field.')
})
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').type('[email protected]')
.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').then(($input) => {
expect($input[0].validationMessage).to.eq('Please fill out this field.')
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').then(($input) => {
expect($input[0].validationMessage).to.eq('Please fill out this field.')
})
.get('.login-form-wrap > .form-inputs > form > .email-input > #email').type('[email protected]')
.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').then(($input) => {
expect($input[0].validationMessage).to.eq('Please fill out this field.')
})
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').type("NotARealPassword")
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 401,
body: {
"message": "Invalid login credentials",
"status": 401
}
})
.get('.login-form-wrap > .form-inputs > form > .password-input > #password').type("NotARealPassword")
.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.login-form-wrap > .form-inputs > .failed-login').should('be.visible')
.get('.login-form-wrap > .form-inputs > .failed-login').should('contain', 'Error in Login: Invalid login credentials')
.get('.login-form-wrap > .form-inputs > form > .login-btn').click()
.get('.login-form-wrap > .form-inputs > .failed-login').should('be.visible')
.get('.login-form-wrap > .form-inputs > .failed-login').should('contain', 'Error in Login: Invalid login credentials')
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/dashBoardSpec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Dash Board after loggging in', () => {
})

it("Should have a header with the users name once data is loaded", () => {
cy.get("h1").should("have.text", "Welcome,Danny DeVito");
cy.get("h1").should("have.text", "Welcome, Danny DeVito");
});

it("Should show how many job applications where submitted in the week", () => {
Expand Down
3 changes: 1 addition & 2 deletions src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ const LoginForm: React.FC = () => {
data-testid="login-button">
Login
</button>
<p className='no-account-message font-[Helvetica Neue] font-sans'>No Account? Click <Link to="/UserRegistration">Here</Link> To Register.</p>

<p className='no-account-message font-[Helvetica Neue] font-sans'>No Account? Click <Link to='/UserRegistration' className='font-[Helvetica Neue] font-sans text-cyan-700'>Here</Link> To Register.</p>
</form>
{errorMessage && <p className='failed-login flex justify-center items-center rounded-md border-red-600 border-2 bg-slate-700 w-[50%] h-[5%] absolute top-[25%] left-[25%] font-[Helvetica Neue] font-sans font-semibold text-lg text-red-600'>{errorMessage}</p>}
{successMessage && <p className='success-login flex justify-center items-center rounded-md border-green-600 border-2 bg-slate-700 w-[50%] h-[5%] absolute top-[25%] left-[25%] font-[Helvetica Neue] font-sans font-semibold text-lg text-green-600'>{successMessage}</p>}
Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const DashBoard : React.FC = () => {
return (
<>
<div className="fixed top-[15vh] left-[25vh] right-0 font-bold font-size-[4vh] text-5xl text-cyan-600">
<h1>Welcome,{userData.user.data.attributes.name}</h1>
<h1>Welcome, {userData.user.data.attributes.name}</h1>
</div>
<div className="ml-2 fixed top-[20vh] left-[25vh]">

Expand Down