Commit 5938cddc authored by Alexandros Georgantas's avatar Alexandros Georgantas

test(app): first book builder test added

parent d20bf572
describe('BookBuilder', () => {
before(() => {
cy.exec('node ./scripts/truncateDB.js')
cy.exec('node ./scripts/createBooksWithUsersAndTeams.js')
})
it('production editor can navigate to book builder for the book she/he is assigned on', () => {
cy.login('productionEditor')
cy.getCollections().then(res => {
const { body } = res
const { data } = body
const { getBookCollections } = data
const collection = getBookCollections[0]
const { books } = collection
const productionEditorBook = books[0]
cy.visit(`/books/${productionEditorBook.id}/book-builder`)
cy.contains('FRONTMATTER')
cy.contains('BODY')
cy.contains('BACKMATTER')
})
})
})
......@@ -11,65 +11,55 @@ describe('Dashboard', () => {
it('admin can add books', () => {
cy.login('admin')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="add-book-btn"]').should('have.length', 1)
cy.get('[data-cy="add-book-btn"]').should('not.be.disabled')
})
it('global production editor can add books', () => {
cy.login('globalProductionEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="add-book-btn"]').should('have.length', 1)
cy.get('[data-cy="add-book-btn"]').should('not.be.disabled')
})
it('production editor can not add books', () => {
cy.login('productionEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="add-book-btn"]').should('have.length', 0)
})
it('copy editor can not add books', () => {
cy.login('copyEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="add-book-btn"]').should('have.length', 0)
})
it('author can not add books', () => {
cy.login('author')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="add-book-btn"]').should('have.length', 0)
})
it('admin can see all three books', () => {
cy.login('admin')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="book"]').should('have.length', 3)
})
it('global production editor can not see any book', () => {
cy.login('globalProductionEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="book"]').should('have.length', 0)
})
it('production editor can see only assigned books (1)', () => {
cy.login('productionEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="book"]').should('have.length', 1)
cy.get('[data-cy="book"]').contains('Production Editor Book')
})
it('copy editor can see only assigned books (1)', () => {
cy.login('copyEditor')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="book"]').should('have.length', 1)
cy.get('[data-cy="book"]').contains('Copy Editor Book')
})
it('author can see only assigned books (1)', () => {
cy.login('author')
cy.visit('/books')
cy.wait(1000)
cy.get('[data-cy="book"]').should('have.length', 1)
cy.get('[data-cy="book"]').contains('Author Book')
})
......
......@@ -53,3 +53,41 @@ Cypress.Commands.add('login', role => {
window.localStorage.setItem('token', token)
})
})
Cypress.Commands.add('getCollections', () => {
const token = window.localStorage.getItem('token')
const getCollectionsQuery = `query(
$ascending: Boolean = true
$archived: Boolean = false
$sortKey: String = "title"
) {
getBookCollections {
id
title
books(ascending: $ascending, sortKey: $sortKey, archived: $archived) {
id
title
publicationDate
isPublished
archived
authors {
username
givenName
surname
}
}
}
}
`
return cy.request({
method: 'POST',
url: '/graphql',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
authorization: token ? `Bearer ${token}` : '',
},
body: { query: getCollectionsQuery },
})
})
......@@ -13994,10 +13994,10 @@ pubsweet-component-bookbuilder@^1.2.5:
react-select "^2.1.1"
styled-components "^4.1.3"
pubsweet-component-editoria-dashboard@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/pubsweet-component-editoria-dashboard/-/pubsweet-component-editoria-dashboard-0.2.3.tgz#903f225e9164ecdc3d7db2249498c17fc030c802"
integrity sha512-/ibWcsdnQkRPo9QlWi+/kzu4uUbxH5fezFlJXx3nOAxV8ethKlD5TQpq9DR9MO78Vpdeb8qOKUec4MKw9vXCXA==
pubsweet-component-editoria-dashboard@^0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/pubsweet-component-editoria-dashboard/-/pubsweet-component-editoria-dashboard-0.2.4.tgz#3fecc861630ba444fe2e09a6b5e6e969c89f12e2"
integrity sha512-7ZAIt+PXTj3ZJ4w08Jz0qyRUWZe/zkTEOswd/UH4+dWVF6YBhgDtfxa+/RVICf2+d4fktoi/tymKhdn1T44isw==
dependencies:
"@pubsweet/ui" "^10.0.2"
editoria-common "^0.1.5"
......
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