Commit afb71dc4 authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

test(waxnavigation): navigate backwards

parent 96f1d927
import { flattenDeep, map, concat } from 'lodash'
const visitAndCheck = (currentId, orderedComponent) => {
const visitAndCheck = (currentId, orderedComponent, order) => {
const current = orderedComponent.findIndex(comp => comp.id === currentId)
const next = orderedComponent[current + 1]
const prev = orderedComponent[current - 1]
......@@ -13,21 +13,35 @@ const visitAndCheck = (currentId, orderedComponent) => {
cy.get('[data-testid="previous-component"]')
.contains(`title-${prev.id}`)
.should('be.visible')
} else {
cy.get('[data-testid="previous-component"]').should('not.be.visible')
}
if (next) {
cy.get('[data-testid="next-component"]')
.contains(`title-${next.id}`)
.should('be.visible')
} else {
cy.get('[data-testid="next-component"]').should('not.be.visible')
}
if (order === 'next' && next) {
cy.get(`a:contains("title-${next.id}")`)
.should('be.visible')
.click()
/* eslint-disable */
cy.wait(500)
/* eslint-enable */
visitAndCheck(next.id, orderedComponent, order)
}
visitAndCheck(next.id, orderedComponent)
if (order === 'previous' && prev) {
cy.get(`a:contains("title-${prev.id}")`)
.should('be.visible')
.click()
/* eslint-disable */
cy.wait(500)
/* eslint-enable */
visitAndCheck(prev.id, orderedComponent, order)
}
return true
......@@ -64,7 +78,36 @@ describe('WaxPubsweet', () => {
const currentId = orderedComponent[0].id
cy.visit(`/books/${getBook.id}/bookComponents/${currentId}`)
visitAndCheck(currentId, orderedComponent)
visitAndCheck(currentId, orderedComponent, 'next')
})
})
})
it('navigate within wax from the last to the first bookComponent', async () => {
cy.login('admin')
cy.getCollections().then(res => {
const {
body: {
data: { getBookCollections },
},
} = res
const bookId = getBookCollections[0].books[0].id
cy.getBookComponents(bookId).then(result => {
const {
body: {
data: { getBook },
},
} = result
const orderedComponent = flattenDeep(
concat([
...map(getBook.divisions, division => division.bookComponents),
]),
)
const lastIndex = orderedComponent.length
const currentId = orderedComponent[lastIndex - 1].id
cy.visit(`/books/${getBook.id}/bookComponents/${currentId}`)
visitAndCheck(currentId, orderedComponent, 'previous')
})
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment