koel/cypress/support/commands.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-12-30 00:30:32 +00:00
import '@testing-library/cypress/add-commands'
import AUTWindow = Cypress.AUTWindow
import Chainable = Cypress.Chainable
2020-12-30 19:28:39 +00:00
function _login(dataFixture, redirectTo = '/'): Chainable<AUTWindow> {
window.localStorage.setItem('api-token', 'mock-token')
cy.intercept('api/data', {
2020-12-30 19:28:39 +00:00
fixture: dataFixture
})
return cy.visit(redirectTo)
2020-12-30 19:28:39 +00:00
}
Cypress.Commands.add('$login', (redirectTo = '/') => _login('data.get.200.json', redirectTo))
Cypress.Commands.add('$loginAsNonAdmin', (redirectTo = '/') => _login('data-non-admin.get.200.json', redirectTo))
2020-12-30 18:44:47 +00:00
Cypress.Commands.add('$each', (dataset: Array<Array<any>>, callback: Function) => {
dataset.forEach(args => callback(...args))
})
2020-12-30 22:37:41 +00:00
Cypress.Commands.add('$confirm', () => {
cy.get('.alertify .ok')
.click()
})
Cypress.Commands.add('$findInTestId', (selector: string) => {
const [testId, ...rest] = selector.split(' ')
return cy.findByTestId(testId.trim()).find(rest.join(' '))
})
2021-01-01 13:31:53 +00:00
Cypress.Commands.add('$clickSidebarItem', (sidebarItemText: string): Chainable<JQuery> => {
return cy.get('#sidebar')
.findByText(sidebarItemText)
.click()
})