2020-12-30 00:30:32 +00:00
|
|
|
import '@testing-library/cypress/add-commands'
|
2020-12-30 10:11:59 +00:00
|
|
|
import AUTWindow = Cypress.AUTWindow
|
|
|
|
import Chainable = Cypress.Chainable
|
|
|
|
|
2020-12-30 19:28:39 +00:00
|
|
|
function _login(dataFixture, redirectTo = '/'): Chainable<AUTWindow> {
|
2020-12-30 10:11:59 +00:00
|
|
|
window.localStorage.setItem('api-token', 'mock-token')
|
|
|
|
|
|
|
|
cy.intercept('api/data', {
|
2020-12-30 19:28:39 +00:00
|
|
|
fixture: dataFixture
|
2020-12-30 10:11:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
2020-12-31 19:01:09 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
})
|