Commit bc99cc17 authored by Alexandros Georgantas's avatar Alexandros Georgantas

Merge branch 'add-dynamic-component-types' into 'master'

Add dynamic component types

See merge request editoria/ucp!23
parents fe4af9b0 f3236cbc
......@@ -13,6 +13,7 @@
"pubsweet-component-theme-editoria",
"editoria-component-login",
"editoria-component-signup",
"editoria-data-model/src/applicationParameter",
"editoria-data-model/src/book",
"editoria-data-model/src/lock",
"editoria-data-model/src/bookCollection",
......
const path = require('path')
const components = require('./components')
const bookBuilder = require('./modules/book-builder')
const winston = require('winston')
// const authsomeMode = require('./modules/authsome')
......@@ -46,7 +45,6 @@ module.exports = {
},
},
},
bookBuilder,
epub: {
fontsPath: '/uploads/fonts',
},
......
......@@ -40,19 +40,27 @@ module.exports = {
{
name: 'Frontmatter',
showNumberBeforeComponents: [],
allowedComponentTypes: ['component'],
allowedComponentTypes: [
{ value: 'component', title: 'Component', predefined: true },
],
defaultComponentType: 'component',
},
{
name: 'Body',
showNumberBeforeComponents: ['chapter'],
allowedComponentTypes: ['chapter', 'part', 'unnumbered'],
allowedComponentTypes: [
{ value: 'chapter', title: 'Chapter', predefined: true },
{ value: 'part', title: 'Part', predefined: true },
{ value: 'unnumbered', title: 'Unnumbered', predefined: true },
],
defaultComponentType: 'chapter',
},
{
name: 'Backmatter',
showNumberBeforeComponents: [],
allowedComponentTypes: ['component'],
allowedComponentTypes: [
{ value: 'component', title: 'Component', predefined: true },
],
defaultComponentType: 'component',
},
],
......
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')
})
it('production editor can navigate to book builder for the book she/he is assigned on', () => {
cy.login('productionEditor')
cy.getCollections().then(res => {
......@@ -19,4 +36,114 @@ describe('BookBuilder', () => {
cy.contains('BACKMATTER')
})
})
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
})
})
})
})
})
})
......@@ -9,6 +9,6 @@ describe('Login page', () => {
cy.get('input[name="username"]').type(username)
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.url().should('include', '/books')
cy.url().should('include', '/books')
})
})
......@@ -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",
......
#!/usr/bin/env node
const logger = require('@pubsweet/logger')
const {
model: ApplicationParameter,
} = require('editoria-data-model/src/applicationParameter')
const config = require('../config/modules/book-builder')
const seed = async () => {
const areas = Object.keys(config)
await Promise.all(
areas.map(async area => {
const parameters = await new ApplicationParameter({
context: 'bookBuilder',
area,
config: JSON.stringify(config[area]),
}).save()
logger.info(
`New Application Parameter created: ${JSON.stringify(config[area])}`,
)
return parameters
}),
)
}
seed()
......@@ -13201,11 +13201,6 @@ pkginfo@0.3.x:
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21"
integrity sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=
pkginfo@0.x.x:
version "0.4.1"
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff"
integrity sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=
platform@1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.5.tgz#fb6958c696e07e2918d2eeda0f0bc9448d733444"
......@@ -13836,19 +13831,7 @@ promisify-event@^1.0.0:
dependencies:
pinkie-promise "^2.0.0"
prompt@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prompt/-/prompt-1.0.0.tgz#8e57123c396ab988897fb327fd3aedc3e735e4fe"
integrity sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=
dependencies:
colors "^1.1.2"
pkginfo "0.x.x"
read "1.0.x"
revalidator "0.1.x"
utile "0.3.x"
winston "2.1.x"
prompt@flatiron/prompt#1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87:
prompt@^1.0.0, prompt@flatiron/prompt#1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87:
version "1.0.0"
resolved "https://codeload.github.com/flatiron/prompt/tar.gz/1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87"
dependencies:
......@@ -18213,19 +18196,6 @@ winston@0.8.x:
pkginfo "0.3.x"
stack-trace "0.0.x"
winston@2.1.x:
version "2.1.1"
resolved "https://registry.yarnpkg.com/winston/-/winston-2.1.1.tgz#3c9349d196207fd1bdff9d4bc43ef72510e3a12e"
integrity sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=
dependencies:
async "~1.0.0"
colors "1.0.x"
cycle "1.0.x"
eyes "0.1.x"
isstream "0.1.x"
pkginfo "0.3.x"
stack-trace "0.0.x"
winston@2.x, winston@^2.2.0:
version "2.4.4"
resolved "https://registry.yarnpkg.com/winston/-/winston-2.4.4.tgz#a01e4d1d0a103cf4eada6fc1f886b3110d71c34b"
......
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