pinafore/cypress/support/commands.js

81 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-01-07 00:51:25 +01:00
// ***********************************************
// 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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
2018-02-18 23:31:28 +01:00
Cypress.Commands.add('login', (email, password) => {
// mastodon throws some uncaught TypeErrors
cy.on('uncaught:exception', (err) => {
expect(err.name).to.include('TypeError')
expect(err.message).to.include('Illegal invocation')
return false
})
cy.visit('/settings/instances/add')
2018-02-19 02:54:38 +01:00
cy.wait(500)
2018-02-18 23:31:28 +01:00
cy.get('#instanceInput').clear().type('localhost:3000')
cy.get('.add-new-instance').submit()
2018-02-19 02:54:38 +01:00
cy.wait(500)
2018-02-18 23:31:28 +01:00
cy.url().should('equal', 'http://localhost:3000/auth/sign_in')
cy.get('input#user_email').should('exist')
cy.get('input#user_password').should('exist')
cy.get('input#user_email').type(email)
cy.get('input#user_password').type(password)
cy.get('form#new_user').submit()
cy.url().should('contain', '/oauth/authorize')
cy.get('button').contains('Authorize').click()
cy.url().should('equal', 'http://localhost:4002/')
2018-02-19 00:28:42 +01:00
})
Cypress.Commands.add('getNthVirtualArticle', (n) => {
2018-02-19 01:57:38 +01:00
return cy.get(`.virtual-list-item[aria-hidden=false] article[aria-posinset=${n}]`)
2018-02-19 00:30:42 +01:00
})
2018-02-19 01:43:39 +01:00
Cypress.Commands.add('validateTimeline', (timeline) => {
timeline.forEach((status, i) => {
if (status.content) {
2018-02-19 19:34:36 +01:00
cy.getNthVirtualArticle(i).find('.status-content p').should('contain', status.content)
2018-02-19 01:43:39 +01:00
}
if (status.spoiler) {
2018-02-19 19:34:36 +01:00
cy.getNthVirtualArticle(i).find('.status-spoiler p').should('contain', status.spoiler)
2018-02-19 01:43:39 +01:00
}
2018-02-19 01:57:38 +01:00
if (status.followedBy) {
2018-02-19 19:34:36 +01:00
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', status.followedBy)
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', 'followed you')
2018-02-19 01:57:38 +01:00
}
2018-02-19 18:01:02 +01:00
if (status.rebloggedBy) {
2018-02-19 19:34:36 +01:00
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', status.rebloggedBy)
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', 'boosted')
2018-02-19 18:01:02 +01:00
}
if (status.favoritedBy) {
2018-02-19 19:34:36 +01:00
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', status.favoritedBy)
cy.getNthVirtualArticle(i).find('.status-header span').should('contain', 'favorited')
2018-02-19 18:01:02 +01:00
}
2018-02-19 04:57:27 +01:00
cy.wait(50)
2018-02-19 01:43:39 +01:00
cy.getNthVirtualArticle(i).scrollIntoView()
2018-02-19 02:28:08 +01:00
cy.get('.loading-footer').should('not.exist')
2018-02-19 01:43:39 +01:00
})
2018-02-19 18:17:39 +01:00
})