Commit fc05ec10 authored by Ana Ellis's avatar Ana Ellis
Browse files

feat: refactored with new test setup

parent ba64a761
Pipeline #7656 failed with stages
in 6 minutes and 15 seconds
const logger = require('@pubsweet/logger')
const { Collection, Fragment, User } = require('pubsweet-server/src/models')
const { setupDb } = require('@pubsweet/db-manager')
export async function setupWithOneSubmittedManuscript() {
await setupDb({
username: 'admin',
password: 'password',
email: 'admin@example.com',
admin: true,
clobber: true,
})
const user = await new User({
username: 'john',
email: 'john@example.com',
password: 'johnjohn',
admin: true,
}).save()
const collection = new Collection({
title: 'My Blog',
owners: [user.id],
})
await collection.save()
const fragment1 = await new Fragment({
type: 'fragment',
files: {
manuscript: {
url: '/uploads/ec0a2df13f11ef9feaf4411b3ffd8c47.docx',
name: 'testSubmission1.docx',
},
supplementary: [],
},
notes: {
specialInstructions: 'special instructions...',
fundingAcknowledgement: '<p>funding acknowledgement...</p>',
},
owners: [user.id],
source:
'<html xmlns="http://www.w3.org/1999/xhtml">\n<head><title>This is a dummy document for testing purposes</title>\n<meta charset="UTF-8"/></head>\n<body>\n<container id="main">\n<h1>This is a dummy document for testing purposes</h1></container>\n\n</body></html>',
version: 1,
metadata: {
title: 'This is a dummy document for testing purposes',
authors: [
{
email: 'email@example.com',
lastName: 'John',
firstName: 'Cena',
affiliation: 'WWE',
},
],
abstract:
'This is a dummy document for testing purposes This is a dummy document for testing purposes This is a dummy document for testing purposes This is a dummy document for testing purposes This is a dummy document for testing purposes',
keywords: ['keywords...'],
articleType: 'original-research',
articleSection: ['clinical-psychology'],
},
submitted: '2018-05-23T07:17:38.601Z',
suggestions: {
editors: {
suggested: ['Marge Simpson'],
},
reviewers: {
suggested: ['Daffy Duck'],
},
},
declarations: {
openData: 'no',
preregistered: 'no',
researchNexus: 'no',
openPeerReview: 'no',
streamlinedReview: 'no',
previouslySubmitted: 'no',
},
fragmentType: 'version',
}).save()
collection.addFragment(fragment1)
await collection.save()
logger.info('Seeding complete.')
}
import faker from 'faker'
import DestinationRequest from 'testcafe-hammerhead/lib/request-pipeline/destination-request'
import start from 'pubsweet/src/startup/start'
import {
addUser,
createTables,
addCollection,
addFragment,
} from '@pubsweet/db-manager'
import { addUser, createTables } from '@pubsweet/db-manager'
let server
......@@ -33,17 +28,4 @@ export async function setup(user) {
return { userData }
}
export async function setupManuscript(collection, fragment) {
const fragmentData = fragment || { fragmentType: 'version' }
const collectionData = collection || {
title: faker.lorem.words(),
}
await addFragment(fragmentData)
await addCollection(collectionData)
return { fragmentData, collectionData }
}
export function teardown() {}
......@@ -7,7 +7,7 @@ const reviewers = {
collabraHome: Selector('nav a'),
reviewerSelect: ReactSelector('CreatableSelect Select'),
reviewer: Selector('#react-select-3--option-0'),
reviewer: Selector('#react-select-3--option-1'),
inviteReviewer: Selector('button[type=submit]'),
backToControlPanel: Selector('a').withText('Back to Control Panel'),
......
import config from 'config'
import { Selector } from 'testcafe'
import { startServer, setup, setupManuscript, teardown } from './helpers/setup'
import { startServer, teardown } from './helpers/setup'
import { setupWithOneSubmittedManuscript } from './fixtures/manuscript-setup/setup-one-submitted'
import { login, dashboard, reviewers, review } from './pageObjects'
import { collection1, fragment1 } from './fixtures/submittedManuscript'
const goodInkConfig = {
inkEndpoint: 'http://inkdemo-api.coko.foundation/',
......@@ -13,7 +13,7 @@ const goodInkConfig = {
},
}
let author
const user = { username: 'john', password: 'johnjohn' }
fixture
.only('Assign reviewers')
......@@ -24,12 +24,8 @@ fixture
.afterEach(teardown)
test.before(async t => {
const result = await setup()
await setupManuscript(collection1, fragment1)
author = result.userData
await login.doLogin(author.username, author.password)
await setupWithOneSubmittedManuscript()
await login.doLogin(user.username, user.password)
})('Assign reviewer', async t => {
await t
.expect(dashboard.invitedReviewsCount.innerText)
......@@ -50,11 +46,11 @@ test.before(async t => {
.click(reviewers.reviewerSelect)
await t
.expect(await Selector(reviewers.reviewer.withText(author.username)).exists)
.expect(await Selector(reviewers.reviewer.withText(user.username)).exists)
.ok()
await t
.click(reviewers.reviewer.withText(author.username))
.click(reviewers.reviewer.withText(user.username))
.expect(await Selector(reviewers.inviteReviewer).exists)
.ok()
.click(reviewers.inviteReviewer)
......
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