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

fix(componenttypes): tests write

parent b8f07f79
const checkComponentTypeToDivision = (division, el) => {
cy.wrap(el.parent().next())
.find(`[role="option"]`)
.each(($el, index, $list) => {
expect($el).to.contain(division.allowedComponentTypes[index].title)
})
}
const addBookComponent = division =>
cy
.get(`[data-test-id="${division.name}-division"]`)
.find('button')
.first()
.click({ force: true })
describe('BookBuilder', () => {
before(() => {
cy.exec('node ./scripts/truncateDB.js')
cy.exec('node ./scripts/seedApplicationParameter.js')
cy.exec('node ./scripts/createBooksWithUsersAndTeams.js')
cy.exec('node ./scripts/createBookComponents.js')
})
it('production editor can navigate to book builder for the book she/he is assigned on', () => {
cy.login('productionEditor')
cy.getCollections().then(res => {
......@@ -21,17 +36,114 @@ describe('BookBuilder', () => {
cy.contains('BACKMATTER')
})
})
it('admin can see the correct bookComponent Types to coresponding divisions', () => {
// cy.login('admin')
// 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.get('[data-test-id="book"]')
// })
it('user can see the correct bookComponent Types to coresponding divisions', () => {
cy.login('admin')
cy.getApplicationParameters().then(parameters => {
const {
body: {
data: { getApplicationParameters },
},
} = parameters
const { config } = getApplicationParameters.find(
parameter => parameter.area === 'divisions',
)
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`)
config.map(division => {
addBookComponent(division).then(() => {
cy.get(`[data-test-id="${division.name}-division"]`)
.find(`[data-test-id="component-types"]`)
.click({ force: true })
.then(el => {
checkComponentTypeToDivision(division, el)
})
})
return true
})
})
})
})
it('user can add custom bookComponent Types to divisions', () => {
cy.login('admin')
cy.getApplicationParameters().then(parameters => {
const {
body: {
data: { getApplicationParameters },
},
} = parameters
const { config } = getApplicationParameters.find(
parameter => parameter.area === 'divisions',
)
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`)
config.map(division => {
addBookComponent(division).then(() => {
cy.get(`[data-test-id="${division.name}-division"]`)
.find(`[data-test-id="component-types"]`)
.click({ force: true })
.then(el => {
const elem = el.parent().next()
cy.wrap(elem)
.find(`button`)
.click({ force: true })
cy.wrap(elem)
.find('#addComponentType')
.type('test')
cy.wrap(elem)
.find(`button`)
.click({ force: true })
})
})
return true
})
cy.getApplicationParameters().then(parameter => {
const {
body: {
data: { getApplicationParameters: applicationParameters },
},
} = parameter
const { config: applicationConfig } = applicationParameters.find(
param => param.area === 'divisions',
)
applicationConfig.map(division => {
cy.get(`[data-test-id="${division.name}-division"]`)
.find(`[data-test-id="component-types"]`)
.then(el => {
checkComponentTypeToDivision(division, el)
})
return true
})
})
})
})
})
})
......@@ -122,3 +122,26 @@ Cypress.Commands.add('getBookComponents', id => {
body: { query: getBookQuery },
})
})
Cypress.Commands.add('getApplicationParameters', () => {
const token = window.localStorage.getItem('token')
const ApplicationParameterQuery = `query ($context: String, $area: String) {
getApplicationParameters(context: $context, area: $area) {
id
context
area
config
}
}`
return cy.request({
method: 'POST',
url: '/graphql',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
authorization: token ? `Bearer ${token}` : '',
},
body: { query: ApplicationParameterQuery },
})
})
......@@ -180,7 +180,7 @@
"cypress": "cypress open",
"resetdb": "pubsweet setupdb --clobber && npm run seed",
"start:services": "docker-compose up postgres",
"seed": "node ./scripts/seedGlobalTeams.js && node ./scripts/seedBookCollection.js",
"seed": "node ./scripts/seedGlobalTeams.js && node ./scripts/seedBookCollection.js && node ./scripts/seedApplicationParameter.js",
"seed:createBooksWithUsersAndTeams": "node ./scripts/createBooksWithUsersAndTeams.js",
"test": "NODE_ENV=test jest",
"test:watch": "NODE_ENV=test jest --watch",
......
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