Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub'
28 changes: 28 additions & 0 deletions __tests__/E2E Tests/e2e-admin-test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// tests/e2e-login.spec.ts
import { test, expect } from '@playwright/test'

test('Admin logs in and approves a study', async ({ page }) => {
// Go to the login page
await page.goto('http://localhost:3000/login')

// Fill in email and password
await page.getByLabel('Email').fill('admin1@mail.com')
await page.getByLabel('Password').fill('1234567')

// Click login button
await page.click('button[type="submit"]')

// Wait for redirection or dashboard to appear
await expect(page.locator('text=The Spider Questionnaire')).toBeVisible()

await page.goto('http://localhost:3000/studies')
await page.locator('table button.MuiIconButton-root').first().click()

await page.locator('label:has-text("Decision")').locator('..').click()
await page.getByRole('option', { name: 'Approved' }).click()

await page.click('button[type="submit"]')

await page.waitForURL('http://localhost:3000/all-users/a7ff6f85-a49c-4970-94e0-77496541c123')
expect(page.url()).toBe('http://localhost:3000/all-users/a7ff6f85-a49c-4970-94e0-77496541c123')
})
29 changes: 29 additions & 0 deletions __tests__/E2E Tests/e2e-clinician-view-results.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fs from 'fs'
import path from 'path'

import { test, expect } from '@playwright/test'

test('Clinician logs in, views results and downloads the report as a PDF', async ({ page }) => {
await page.goto('http://localhost:3000/login')
await page.getByLabel('Email').fill('clinician1@mail.com')
await page.getByLabel('Password').fill('1234567')
await page.click('button[type="submit"]')

await page.getByText('The Spider Questionnaire').waitFor()
await page.goto('http://localhost:3000/all-patients')

await page.getByText('patient1 patient1').click()
await page.getByText('Go to record list').click()
await page.getByLabel('view single record').first().click()

const isDownloading = page.waitForEvent('download')

await page.getByRole('button', { name: 'Export' }).click()
const download = await isDownloading

const downloadPath = path.join(__dirname, 'downloads', await download.suggestedFilename())

await download.saveAs(downloadPath)

expect(fs.existsSync(downloadPath)).toBe(true)
})
175 changes: 175 additions & 0 deletions __tests__/E2E Tests/e2e-login-test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import fs from 'fs'
import path from 'path'

import { test, expect } from '@playwright/test'

test('Patient logs in, updates employment, takes questionnaire and views the result', async ({ page }) => {
// Go to the login page
await page.goto('http://localhost:3000/login')

// Fill in email and password
await page.getByLabel('Email').fill('patient1@mail.com')
await page.getByLabel('Password').fill('1234567')

// Click login button
await page.click('button[type="submit"]')

// Wait for redirection or dashboard to appear
await expect(page.locator('text=The Spider Questionnaire')).toBeVisible() // Change to match your app's logged-in view

// move to questionnaire and fill out information form
await page.click('text=Take The Test')

await page.getByText('OK').click()

await expect(page.locator('text=Patient Information')).toBeVisible()

await page.locator('label:has-text("Select Employment Status")').locator('..').click()
await page.getByRole('option', { name: 'In education' }).click()

// Click Next button
await page.getByText('Next').click()

page.on('dialog', async dialog => {
await dialog.accept()
})

const answerValues = ['0', '25', '50', '75', '100']

// Test page 1
for (let i = 6; i <= 9; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const div = page.locator(`#\\3${i} `)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

// Test page 2
for (let i = 10; i <= 12; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

// Test page 3
for (let i = 1; i <= 5; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const div = page.locator(`#\\3${i} `)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

// Test page 4
for (let i = 13; i <= 16; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

// Test page 5
for (let i = 17; i <= 20; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

if (i !== 19) {
await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
} else {
await div.locator(`input[type="checkbox"][value="After a meal"]`).check()
}
}

await page.getByText('Next').click()

// Test page 6
for (let i = 21; i <= 25; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

if (i !== 25) {
await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
} else {
await div.locator(`input[type="radio"][value="66.6"]`).check()
}
}

await page.getByText('Next').click()

// Test page 7
for (let i = 26; i <= 28; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

// Test page 8
for (let i = 29; i <= 31; i++) {
const randomValue = answerValues[Math.floor(Math.random() * answerValues.length)]
const escapedId = `\\3${i.toString()[0]} ${i.toString().slice(1)}`
const div = page.locator(`#${escapedId}`)

await div.locator(`input[type="radio"][value="${randomValue}"]`).check()
}

await page.getByText('Next').click()

await page
.getByText(
'Mark on the graph how much these symptoms have impacted your daily life during the past ONE month. (Optional)'
)
.waitFor({ timeout: 5000 })

const chart = page.getByTestId('spidergram')

const box = await chart.boundingBox()

if (!box) throw new Error('Chart not found')

const { x, y, width, height } = box
const cx = x + width / 2
const cy = y + height / 2

const domains = 8
const radius = Math.min(width, height) * 0.45 * 0.5 // halfway out

for (let i = 0; i < domains; i++) {
const angle = (2 * Math.PI * i) / domains
const clickX = cx + radius * Math.cos(angle)
const clickY = cy + radius * Math.sin(angle)

await page.mouse.click(clickX, clickY)
}

await page.getByText('Submit').click()
await page.waitForURL('http://localhost:3000/my-records')

await page.getByLabel('view single record').first().click()

const isDownloading = page.waitForEvent('download')

await page.getByRole('button', { name: 'Export' }).click()
const download = await isDownloading

const downloadPath = path.join(__dirname, 'downloads', await download.suggestedFilename())

await download.saveAs(downloadPath)

expect(fs.existsSync(downloadPath)).toBe(true)
})
61 changes: 61 additions & 0 deletions __tests__/E2E Tests/e2e-researcher-study-submission.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import path from 'path'

import { test } from '@playwright/test'

test('Researcher logs in and sets up a new study', async ({ page }) => {
// Log in as researcher 1
await page.goto('http://localhost:3000/login')
await page.getByLabel('Email').fill('researcher1@mail.com')
await page.getByLabel('Password').fill('1234567')
await page.click('button[type="submit"]')

// Navigate to study application
await page.getByText('The Spider Questionnaire').waitFor()
await page.goto('http://localhost:3000/my-profile')
await page.getByText('Researcher Account Settings').waitFor()

await page.pause()
const deleteButton = page.locator('button:has-text("Delete")')

if ((await deleteButton.count()) > 0) {
await deleteButton.click()

// If there's a confirm dialog
page.locator('button:has-text("Yes, Delete")').click()
} else {
console.log('No study to delete — skipping delete step')
}

await page.getByText('Add New Study and Apply for Data Access').click()

// Fill in form
await page.getByLabel('Research Title').fill('Test Study')
await page.getByLabel('Research Question').fill('Test Question')
await page.locator('label:has-text("Institution")').locator('..').click()
await page.getByRole('option', { name: 'University College London (UCL)' }).click()
await page.getByLabel('Summary').fill('This is a test description')

const fileInput = page.locator('input[type="file"]')

await fileInput.setInputFiles(path.join('./sample-research-proposal.pdf'))

await page.getByLabel('Expected start date to end date').click()

// Wait for the calendar to appear
await page.locator('.react-datepicker').waitFor({ state: 'visible' })

// Click the start date (e.g., April 2)
await page.locator('.react-datepicker__day--002').last().click()

// Click the end date (e.g., April 10)
await page.locator('.react-datepicker__day--010').last().click()

await page.getByLabel('Age').click()
await page.getByLabel('Ethnicity').click()

await page.getByLabel('Single episode questionnaire').click()
await page.click('button[type="submit"]')

// Check for redirection
await page.getByText('Researcher Account Settings').waitFor()
})
Binary file added __tests__/E2E Tests/sample-research-proposal.pdf
Binary file not shown.
Loading