Commit 9d2d402e authored by Yannis Barlas's avatar Yannis Barlas

test(*): fill out author data in form with cypress

parent 3919a501
......@@ -45,7 +45,11 @@ const SubmitButton = props => {
})
}
return <Action onClick={onClick}>New Submission</Action>
return (
<Action data-test-id="new-submission-button" onClick={onClick}>
New Submission
</Action>
)
}
const Action = styled(UIAction)`
......
......@@ -90,7 +90,7 @@ const AuthorInput = props => {
const autoCompleteProps = omit(props, ['label', 'name', 'value'])
return (
<div>
<div data-test-id={`authorinput-${name}`}>
{label && (
<Label>
{label} {required && ' *'}{' '}
......@@ -100,6 +100,7 @@ const AuthorInput = props => {
<Wrapper>
<StyledAutoComplete
data-test-id={`authorinput-${authorName}`}
error={get(errors, authorName)}
fetchData={getWBPerson}
hideErrorMessage
......@@ -128,6 +129,7 @@ const AuthorInput = props => {
<AffiliationsWrapper>
<TextField
data-test-id={`authorinput-${affiliationsName}`}
inline
label="Affiliations"
name={affiliationsName}
......
......@@ -97,6 +97,7 @@ const Credit = props => {
closeMenuOnSelect={false}
isDisabled={readOnly}
isMulti
// menuIsOpen
onBlur={handleBlur}
onChange={handleChange}
options={options}
......
......@@ -55,6 +55,7 @@ const InitialSubmission = props => {
/>
<TextField
data-test-id="author-email"
error={get(errors, 'author.email')}
label="Email address"
name="author.email"
......
......@@ -15,7 +15,7 @@ import _, {
union,
} from 'lodash'
let defaultFormValues = {
const defaultFormValues = {
acknowledgements: '',
author: {
affiliations: '',
......@@ -192,196 +192,196 @@ let defaultFormValues = {
title: '',
}
if (process.env.NODE_ENV === 'development') {
defaultFormValues = {
acknowledgements: '',
author: {
affiliations: 'University of Chicago.',
credit: ['software'],
email: 'john@john.com',
name: 'John A Bryden',
WBId: 'WBPerson6903',
},
coAuthors: [
{
affiliations: 'University of Minnesota',
credit: ['formalAnalysis'],
id: uuid(),
name: 'Yanna Cen',
WBId: 'WBPerson18694',
},
{
affiliations: 'University of Chicago',
credit: ['dataCuration'],
id: uuid(),
name: 'Alec Barret',
WBId: 'WBPerson15466',
},
],
comments: '<p>some comments here</p>',
disclaimer: true,
funding: 'blah',
geneExpression: {
antibodyUsed: 'an antibody',
backboneVector: {
name: '',
WBId: '',
},
coinjected: '',
constructComments: '',
constructionDetails: '',
detectionMethod: 'antibody',
dnaSequence: [
{
id: uuid(),
name: '',
WBId: '',
},
],
expressionPattern: {
name: 'some expression',
WBId: '1',
},
fusionType: {
name: '',
WBId: '',
},
genotype: '',
injectionConcentration: '',
inSituDetails: '',
integratedBy: {
name: '',
WBId: '',
},
observeExpression: {
certainly: [
{
certainly: {
id: uuid(),
name: '',
WBId: '',
},
during: {
id: uuid(),
name: '',
WBId: '',
},
id: uuid(),
subcellularLocalization: {
id: uuid(),
name: '',
WBId: '',
},
},
],
not: [
{
during: {
id: uuid(),
name: 'soma',
WBId: '67',
},
id: uuid(),
not: {
id: uuid(),
name: '',
WBId: '',
},
subcellularLocalization: {
id: uuid(),
name: '',
WBId: '',
},
},
],
partially: [
{
during: {
id: uuid(),
name: '',
WBId: '',
},
id: uuid(),
partially: {
id: uuid(),
name: '',
WBId: '',
},
subcellularLocalization: {
id: uuid(),
name: '',
WBId: '',
},
},
],
possibly: [
{
during: {
id: uuid(),
name: '',
WBId: '',
},
id: uuid(),
possibly: {
id: uuid(),
name: '',
WBId: '',
},
subcellularLocalization: {
id: uuid(),
name: '',
WBId: '',
},
},
],
},
reporter: {
name: '',
WBId: '',
},
species: {
name: 'Caenorhabditis brenneri',
WBId: 'Caenorhabditis brenneri',
},
strain: '',
transgeneName: '',
transgeneUsed: [
{
id: uuid(),
name: 'Some',
WBId: '',
},
{
id: uuid(),
name: 'Some',
WBId: '',
},
],
utr: {
name: '',
WBId: '',
},
variation: {
name: '',
WBId: '',
},
},
image: {},
imageCaption: '<p>fdsfsd</p>',
laboratory: {
name: 'Jean-Claude Labbe',
WBId: 'UM',
},
methods: '<p>Yello</p>',
patternDescription: '<p>Hello there</p>',
references: '<p>fdsfdsfsd</p>',
suggestedReviewer: {
name: 'John C Cooper',
WBId: 'lklajfldjsf',
},
title: '<p>titlez <em>mymy</em> <strong>here</strong><sup>there</sup></p>',
}
}
// if (process.env.NODE_ENV === 'development') {
// defaultFormValues = {
// acknowledgements: '',
// author: {
// affiliations: 'University of Chicago.',
// credit: ['software'],
// email: 'john@john.com',
// name: 'John A Bryden',
// WBId: 'WBPerson6903',
// },
// coAuthors: [
// {
// affiliations: 'University of Minnesota',
// credit: ['formalAnalysis'],
// id: uuid(),
// name: 'Yanna Cen',
// WBId: 'WBPerson18694',
// },
// {
// affiliations: 'University of Chicago',
// credit: ['dataCuration'],
// id: uuid(),
// name: 'Alec Barret',
// WBId: 'WBPerson15466',
// },
// ],
// comments: '<p>some comments here</p>',
// disclaimer: true,
// funding: 'blah',
// geneExpression: {
// antibodyUsed: 'an antibody',
// backboneVector: {
// name: '',
// WBId: '',
// },
// coinjected: '',
// constructComments: '',
// constructionDetails: '',
// detectionMethod: 'antibody',
// dnaSequence: [
// {
// id: uuid(),
// name: '',
// WBId: '',
// },
// ],
// expressionPattern: {
// name: 'some expression',
// WBId: '1',
// },
// fusionType: {
// name: '',
// WBId: '',
// },
// genotype: '',
// injectionConcentration: '',
// inSituDetails: '',
// integratedBy: {
// name: '',
// WBId: '',
// },
// observeExpression: {
// certainly: [
// {
// certainly: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// during: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// id: uuid(),
// subcellularLocalization: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// },
// ],
// not: [
// {
// during: {
// id: uuid(),
// name: 'soma',
// WBId: '67',
// },
// id: uuid(),
// not: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// subcellularLocalization: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// },
// ],
// partially: [
// {
// during: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// id: uuid(),
// partially: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// subcellularLocalization: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// },
// ],
// possibly: [
// {
// during: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// id: uuid(),
// possibly: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// subcellularLocalization: {
// id: uuid(),
// name: '',
// WBId: '',
// },
// },
// ],
// },
// reporter: {
// name: '',
// WBId: '',
// },
// species: {
// name: 'Caenorhabditis brenneri',
// WBId: 'Caenorhabditis brenneri',
// },
// strain: '',
// transgeneName: '',
// transgeneUsed: [
// {
// id: uuid(),
// name: 'Some',
// WBId: '',
// },
// {
// id: uuid(),
// name: 'Some',
// WBId: '',
// },
// ],
// utr: {
// name: '',
// WBId: '',
// },
// variation: {
// name: '',
// WBId: '',
// },
// },
// image: {},
// imageCaption: '<p>fdsfsd</p>',
// laboratory: {
// name: 'Jean-Claude Labbe',
// WBId: 'UM',
// },
// methods: '<p>Yello</p>',
// patternDescription: '<p>Hello there</p>',
// references: '<p>fdsfdsfsd</p>',
// suggestedReviewer: {
// name: 'John C Cooper',
// WBId: 'lklajfldjsf',
// },
// title: '<p>titlez <em>mymy</em> <strong>here</strong><sup>there</sup></p>',
// }
// }
const dataToFormValues = data => {
const defaultValues = cloneDeep(defaultFormValues)
......
......@@ -48,7 +48,7 @@ const AuthorSectionItem = props => {
)
return (
<Wrapper>
<Wrapper data-test-id="dashboard-section-item-author">
<SectionItemWithStatus actionsComponent={ActionsComponent} {...props} />
</Wrapper>
)
......
......@@ -41,7 +41,7 @@ const Section = props => {
const emptyMessage = 'There are no articles to display'
return (
<div>
<div data-test-id="dashboard-section">
<Header>
<Title>{label}</Title>
<HeaderActions>{actions}</HeaderActions>
......
......@@ -91,7 +91,9 @@ const StyledSelect = props => {
}),
}
return <Select {...rest} styles={stylesFromTheme} />
return (
<Select classNamePrefix="react-select" {...rest} styles={stylesFromTheme} />
)
}
export default withTheme(StyledSelect)
// const clearDb = require('../support/clearDb')
describe('Author creates new submission', () => {
beforeEach(() => {
cy.login('author')
cy.visit('/dashboard')
})
it('should create a new submission', () => {
cy.get('[data-test-id="dashboard-section"]').should('have.length', 2)
cy.getById('dashboard-section-item-author').should('have.length', 0)
cy.getById('new-submission-button').click()
cy.url().should('include', '/article')
cy.contains('Submit your article').should('exist')
cy.contains('Dashboard').click()
cy.url().should('include', '/dashboard')
cy.getById('dashboard-section-item-author').should('have.length', 1)
})
it('should make initial submission', () => {
cy.getById('new-submission-button').click()
cy.getById('authorinput-author.name')
.type('John Brown')
.get('[data-test-id="authorinput-author"] .react-select__control')
.click()
.get(
'[data-test-id="authorinput-author"] .react-select__option:nth-child(1)',
)
.click()
.get(
'[data-test-id="authorinput-author"] .react-select__option:nth-child(1)',
)
.click()
.getById('authorinput-author.affiliations')
.type('University of Chicago')
.getById('author-email')
.type('johnbrown@example.com')
cy.getById('authorinput-coAuthors[0].name').type('Han')
})
})
......@@ -11,7 +11,62 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const { Manuscript, Team, TeamMember } = require('@pubsweet/models')
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
async clearDb() {
await Team.query()
.delete()
.whereNot({ global: true })
await TeamMember.query().delete()
await Manuscript.query().delete()
return null
},
// async seedUsers() {
// const users = [
// {
// email: 'author@example.com',
// password: 'password',
// username: 'author',
// },
// {
// email: 'editor@example.com',
// password: 'password',
// username: 'editor',
// },
// {
// email: 'scienceOfficer@example.com',
// password: 'password',
// username: 'scienceOfficer',
// },
// {
// email: 'reviewer@example.com',
// password: 'password',
// username: 'reviewer',
// },
// ]
// // logger.info('>>>>> Creating test users')
// const newUsers = users.map(
// user =>
// new User({
// ...user,
// }),
// )
// await Promise.all(newUsers.map(u => u.save()))
// // .then(res => {
// // logger.info('>>>>> All test users successfully created')
// // })
// return null
// },
})
}
......@@ -55,3 +55,5 @@ Cypress.Commands.add('login', role => {
window.localStorage.setItem('token', token)
})
})
Cypress.Commands.add('getById', id => cy.get(`[data-test-id="${id}"]`))
beforeEach(() => {
cy.task('clearDb')
})
......@@ -16,6 +16,7 @@
// Import commands.js using ES2015 syntax:
import './commands'
import './credentials'
import './db'
// Alternatively you can use CommonJS syntax:
// require('./commands')
......@@ -152,9 +152,9 @@
"resetdb": "sh ./scripts/resetDb.sh",
"seed:demo": "node ./scripts/seedDemoData.js",
"server": "pubsweet server",
"server:dev": "nodemon --exec 'pubsweet server' --watch server",
"server:dev": "NODE_ENV=development sh ./scripts/runDevServer.sh",
"server:production": "./scripts/runProductionServer.sh",
"server:test": "sh ./scripts/runTestServer.sh",
"server:test": "NODE_ENV=test sh ./scripts/runTestServer.sh",
"setupdb": "sh ./scripts/setupDb.sh",
"test": "jest --maxWorkers=1 --config=.jest.config.js"
},
......
const logger = require('@pubsweet/logger')
const { Manuscript, Team, TeamMember } = require('@pubsweet/models')
logger.info('ENV is', process.env.NODE_ENV)
const clear = async () => {
try {
await Team.query()
.delete()
.whereNot({ global: true })
await TeamMember.query().delete()
await Manuscript.query().delete()
} catch (e) {
logger.error(e)
}
}
clear()
source ./scripts/setupDb.sh
node ./scripts/seedTeams.js
node ./scripts/seedUsers.js
node_modules/.bin/nodemon --exec 'pubsweet server' --watch server
......@@ -2,7 +2,6 @@
const path = require('path')
const webpack = require('webpack')
// const ThemePlugin = require('pubsweet-theme-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const fs = require('fs-extra')
......@@ -47,7 +46,6 @@ module.exports = [
joi: 'joi-browser',
config: clientConfigPath,
},
// plugins: [new ThemePlugin(config['pubsweet-client'].theme)],
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
......@@ -69,6 +67,8 @@ module.exports = [
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
],
node: {
......
......@@ -2,7 +2,6 @@
const path = require('path')
const webpack = require('webpack')
// const ThemePlugin = require('pubsweet-theme-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const fs = require('fs-extra')
......@@ -23,6 +22,7 @@ module.exports = [
// The configuration for the client
name: 'app',
target: 'web',
mode: 'development',
context: path.join(__dirname, '..', 'app'),
entry: {
app: ['react-hot-loader/patch', 'webpack-hot-middleware/client', './app'],
......@@ -32,6 +32,7 @@ module.exports = [
filename: '[name].js',
publicPath: '/assets/',
},
devtool: 'cheap-module-source-map',
module: {
rules,
},
......@@ -45,7 +46,6 @@ module.exports = [
joi: 'joi-browser',
config: clientConfigPath,
},
// plugins: [new ThemePlugin(config['pubsweet-client'].theme)],
extensions: ['.js', '.jsx', '.json', '.scss'],
enforceExtension: false,
},
......
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