-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cypress and first e2e tests
- Loading branch information
Showing
13 changed files
with
1,352 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
Check warning on line 5 in cypress.config.ts GitHub Actions / checks (17.x)
|
||
// implement node event listeners here | ||
}, | ||
baseUrl: 'http://localhost:3000/', | ||
}, | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
describe('example to-do app', () => { | ||
beforeEach(() => { | ||
cy.visit('https://example.cypress.io/todo'); | ||
}); | ||
|
||
it('displays two todo items by default', () => { | ||
cy.get('.todo-list li').should('have.length', 2); | ||
|
||
cy.get('.todo-list li').first().should('have.text', 'Pay electric bill'); | ||
cy.get('.todo-list li').last().should('have.text', 'Walk the dog'); | ||
}); | ||
|
||
it('can add new todo items', () => { | ||
const newItem = 'Feed the cat'; | ||
|
||
cy.get('[data-test=new-todo]').type(`${newItem}{enter}`); | ||
|
||
cy.get('.todo-list li') | ||
.should('have.length', 3) | ||
.last() | ||
.should('have.text', newItem); | ||
}); | ||
|
||
it('can check off an item as completed', () => { | ||
cy.contains('Pay electric bill') | ||
.parent() | ||
.find('input[type=checkbox]') | ||
.check(); | ||
|
||
cy.contains('Pay electric bill') | ||
.parents('li') | ||
.should('have.class', 'completed'); | ||
}); | ||
|
||
context('with a checked task', () => { | ||
beforeEach(() => { | ||
cy.contains('Pay electric bill') | ||
.parent() | ||
.find('input[type=checkbox]') | ||
.check(); | ||
}); | ||
|
||
it('can filter for uncompleted tasks', () => { | ||
cy.contains('Active').click(); | ||
|
||
cy.get('.todo-list li') | ||
.should('have.length', 1) | ||
.first() | ||
.should('have.text', 'Walk the dog'); | ||
|
||
cy.contains('Pay electric bill').should('not.exist'); | ||
}); | ||
|
||
it('can filter for completed tasks', () => { | ||
cy.contains('Completed').click(); | ||
|
||
cy.get('.todo-list li') | ||
.should('have.length', 1) | ||
.first() | ||
.should('have.text', 'Pay electric bill'); | ||
|
||
cy.contains('Walk the dog').should('not.exist'); | ||
}); | ||
|
||
it('can delete all completed tasks', () => { | ||
cy.contains('Clear completed').click(); | ||
|
||
cy.get('.todo-list li') | ||
.should('have.length', 1) | ||
.should('not.have.text', 'Pay electric bill'); | ||
|
||
cy.contains('Clear completed').should('not.exist'); | ||
}); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { selectByTestId } from '../../helpers/selectByTestId'; | ||
|
||
describe('Routing', () => { | ||
describe('User not authorized', () => { | ||
it('Access to main page', () => { | ||
cy.visit('/'); | ||
cy.get(selectByTestId('MainPage')).should('exist'); | ||
}); | ||
it('To main page', () => { | ||
cy.visit('/profile/1'); | ||
cy.get(selectByTestId('MainPage')).should('exist'); | ||
}); | ||
it('To not found page', () => { | ||
cy.visit('/fasfasfasf'); | ||
cy.get(selectByTestId('NotFoundPage')).should('exist'); | ||
}); | ||
}); | ||
describe('User is authorized', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
}); | ||
it('To profile page', () => { | ||
cy.visit('/profile/1'); | ||
cy.get(selectByTestId('ProfilePage')).should('exist'); | ||
}); | ||
|
||
it('To articles page', () => { | ||
cy.visit('/articles'); | ||
cy.get(selectByTestId('ArticlesPage')).should('exist'); | ||
}); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function selectByTestId(testId: string) { | ||
return `[data-testid=${testId}]`; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { login } from './commands/login'; | ||
|
||
Cypress.Commands.add('login', login); | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
login(email?: string, password?: string): Chainable<void> | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { USER_LOCALSTORAGE_KEY } from '../../../src/shared/const/localstorage'; | ||
|
||
export const login = (username: string = 'testuser', password: string = '123') => { | ||
cy.request({ | ||
method: 'POST', | ||
url: 'http://localhost:8000/login', | ||
body: { | ||
username, | ||
password, | ||
}, | ||
}).then(({ body }) => { | ||
window.localStorage.setItem(USER_LOCALSTORAGE_KEY, JSON.stringify(body)); | ||
}); | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import './commands'; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["es5", "dom"], | ||
"types": ["cypress", "node"], | ||
"allowJs": true, | ||
"isolatedModules": false | ||
}, | ||
"extends": "../tsconfig.json", | ||
"include": ["**/*.ts"] | ||
} |
This file contains 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
Oops, something went wrong.