Upload 5.23
This commit is contained in:
102
part5/bloglist-frontend/cypress/e2e/spec.cy.js
Normal file
102
part5/bloglist-frontend/cypress/e2e/spec.cy.js
Normal file
@@ -0,0 +1,102 @@
|
||||
describe('blog app', function () {
|
||||
beforeEach(function () {
|
||||
cy.request('POST', 'http://localhost:3001/api/testing/reset')
|
||||
cy.request('POST', 'http://localhost:3001/api/users/', {
|
||||
name: 'Andrew',
|
||||
username: 'andyyyyy',
|
||||
password: '123456',
|
||||
})
|
||||
cy.request('POST', 'http://localhost:3001/api/users/', {
|
||||
name: 'Matti Luukkainen',
|
||||
username: 'mluukkai',
|
||||
password: 'salainen',
|
||||
})
|
||||
cy.visit('http://localhost:3000')
|
||||
})
|
||||
|
||||
it('front page can be opened', function () {
|
||||
cy.contains('Bloglist')
|
||||
cy.contains('Please log in')
|
||||
cy.contains('Username')
|
||||
cy.contains('Password')
|
||||
cy.contains('Login')
|
||||
})
|
||||
|
||||
describe('when logged in', function () {
|
||||
beforeEach(function () {
|
||||
it('login succeeds with correct credentials', function () {
|
||||
cy.get('.username').type('andyyyyy')
|
||||
cy.get('.password').type('123456')
|
||||
cy.get('.loginButton').click()
|
||||
})
|
||||
|
||||
cy.contains('Andrew logged in')
|
||||
})
|
||||
|
||||
it('a new blog can be created', function () {
|
||||
cy.contains('New blog').click()
|
||||
cy.get('.title').type('a blog created')
|
||||
cy.get('.author').type('cypress')
|
||||
cy.get('.urlAddress').type('cypress.com')
|
||||
cy.get('.createButton').click()
|
||||
cy.contains('a blog created by cypress')
|
||||
})
|
||||
|
||||
it('a blog can be liked', function () {
|
||||
cy.contains('New blog').click()
|
||||
cy.get('.title').type('a blog created')
|
||||
cy.get('.author').type('cypress')
|
||||
cy.get('.urlAddress').type('cypress.com')
|
||||
cy.get('.createButton').click()
|
||||
cy.contains('a blog created by cypress')
|
||||
cy.contains('View').click()
|
||||
cy.contains('+').click()
|
||||
cy.contains('1')
|
||||
})
|
||||
|
||||
it('a blog can be deleted', function () {
|
||||
cy.contains('New blog').click()
|
||||
cy.get('.title').type('a blog created')
|
||||
cy.get('.author').type('cypress')
|
||||
cy.get('.urlAddress').type('cypress.com')
|
||||
cy.get('.createButton').click()
|
||||
cy.contains('a blog created by cypress')
|
||||
cy.contains('View').click()
|
||||
cy.contains('Remove').click()
|
||||
cy.get('html').should('not.contain', 'a blog created by cypress')
|
||||
})
|
||||
|
||||
it('only the creator can delete a blog', function () {
|
||||
cy.contains('New blog').click()
|
||||
cy.get('.title').type('a blog created')
|
||||
cy.get('.author').type('cypress')
|
||||
cy.get('.urlAddress').type('cypress.com')
|
||||
cy.get('.createButton').click()
|
||||
cy.contains('a blog created by cypress')
|
||||
cy.get('.logoutButton').click()
|
||||
cy.get('.username').type('mluukkai')
|
||||
cy.get('.password').type('salainen')
|
||||
cy.get('.loginButton').click()
|
||||
cy.contains('View').click()
|
||||
cy.contains('Remove').click()
|
||||
cy.contains('a blog created by cypress')
|
||||
})
|
||||
|
||||
it('blogs are ordered according to likes', function () {
|
||||
cy.contains('New blog').click()
|
||||
cy.get('.title').type('another blog created')
|
||||
cy.get('.author').type('cypress')
|
||||
cy.get('.urlAddress').type('cypress.com')
|
||||
cy.get('.createButton').click()
|
||||
cy.contains('another blog created by cypress')
|
||||
cy.contains('View').click()
|
||||
cy.contains('+').click()
|
||||
cy.wait(1000)
|
||||
cy.contains('+').click()
|
||||
cy.wait(1000)
|
||||
cy.visit('http://localhost:3000')
|
||||
cy.get('.blog').eq(0).should('contain', 'another blog created by cypress')
|
||||
cy.get('.blog').eq(1).should('contain', 'a blog created by cypress')
|
||||
})
|
||||
})
|
||||
})
|
||||
5
part5/bloglist-frontend/cypress/fixtures/example.json
Normal file
5
part5/bloglist-frontend/cypress/fixtures/example.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "Using fixtures to represent data",
|
||||
"email": "hello@cypress.io",
|
||||
"body": "Fixtures are a great way to mock data for responses to routes"
|
||||
}
|
||||
25
part5/bloglist-frontend/cypress/support/commands.js
Normal file
25
part5/bloglist-frontend/cypress/support/commands.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// ***********************************************
|
||||
// This example commands.js shows you how to
|
||||
// create various custom commands and overwrite
|
||||
// existing commands.
|
||||
//
|
||||
// For more comprehensive examples of custom
|
||||
// commands please read more here:
|
||||
// https://on.cypress.io/custom-commands
|
||||
// ***********************************************
|
||||
//
|
||||
//
|
||||
// -- This is a parent command --
|
||||
// Cypress.Commands.add('login', (email, password) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a child command --
|
||||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a dual command --
|
||||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||
20
part5/bloglist-frontend/cypress/support/e2e.js
Normal file
20
part5/bloglist-frontend/cypress/support/e2e.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// ***********************************************************
|
||||
// This example support/e2e.js is processed and
|
||||
// loaded automatically before your test files.
|
||||
//
|
||||
// This is a great place to put global configuration and
|
||||
// behavior that modifies Cypress.
|
||||
//
|
||||
// You can change the location of this file or turn off
|
||||
// automatically serving support files with the
|
||||
// 'supportFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/configuration
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
Reference in New Issue
Block a user