From 89646b7484d5a6beef1be7b222bb193605769061 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Fri, 12 Nov 2021 11:12:14 +0000 Subject: [PATCH] test(integration): add case for viewing a request by an author Refs #388, #425 --- integration/src/api.ts | 31 +++++++++++++++++++ .../browser/author-requested-a-review.spec.ts | 13 ++++++++ ...th-author-request-Desktop-Chrome-linux.png | 3 ++ .../with-author-request-iPhone-11-linux.png | 3 ++ integration/src/fixtures.ts | 8 +++++ 5 files changed, 58 insertions(+) create mode 100644 integration/src/browser/author-requested-a-review.spec.ts create mode 100644 integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-Desktop-Chrome-linux.png create mode 100644 integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-iPhone-11-linux.png diff --git a/integration/src/api.ts b/integration/src/api.ts index c22795e2..17996600 100644 --- a/integration/src/api.ts +++ b/integration/src/api.ts @@ -45,6 +45,7 @@ const rapidReviewSchema = z.object({ const requestSchema = z.object({ uuid: z.string(), + isPreprintAuthor: z.boolean(), }) const templateSchema = z.object({ @@ -140,6 +141,36 @@ export async function ensureRequest( .then(response => response.data); } +export async function ensureRequestByAuthor( + fetch: Fetch, + preprint: string, +): Promise { + const request = await fetch(`/api/v2/preprints/${preprint}/requests`, { + headers: adminHeaders, + }) + .then(response => response.json()) + .then(dataSchema(z.array(requestSchema)).parse) + .then(response => response.data) + .then(requests => requests.find(request => request.isPreprintAuthor)); + + if (request) { + return request; + } + + return await fetch(`/api/v2/preprints/${preprint}/requests?isAuthor=true`, { + method: 'POST', + body: JSON.stringify({ preprint }), + headers: { + 'Content-Type': 'application/json', + ...adminHeaders, + }, + }) + .then(ensureSuccess) + .then(response => response.json()) + .then(dataSchema(requestSchema).parse) + .then(response => response.data); +} + export async function ensureFullReview( fetch: Fetch, preprint: string, diff --git a/integration/src/browser/author-requested-a-review.spec.ts b/integration/src/browser/author-requested-a-review.spec.ts new file mode 100644 index 00000000..4be48695 --- /dev/null +++ b/integration/src/browser/author-requested-a-review.spec.ts @@ -0,0 +1,13 @@ +import { expect, test } from './test'; +import { screenshot } from './utils'; + +test.asALoggedInUser('see an author-requested review', async ({ page, preprint, requestByAuthor }) => { + await page.goto(`preprints/${preprint.uuid}`); + + await page.click(':text("Add Request")'); + + const paper = page.locator('.MuiDrawer-paper'); + + await expect(paper.locator('.MuiAvatarGroup-avatar')).toContainText('Author'); + expect(await screenshot(paper)).toMatchSnapshot('with-author-request.png'); +}); diff --git a/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-Desktop-Chrome-linux.png b/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-Desktop-Chrome-linux.png new file mode 100644 index 00000000..71c89761 --- /dev/null +++ b/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-Desktop-Chrome-linux.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27bb159786fb09f39ef2fd8b80c206ed01691aa61b2fd19b4d7a03ba02d80d76 +size 85397 diff --git a/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-iPhone-11-linux.png b/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-iPhone-11-linux.png new file mode 100644 index 00000000..3263187b --- /dev/null +++ b/integration/src/browser/author-requested-a-review.spec.ts-snapshots/with-author-request-iPhone-11-linux.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52e922c379367636faa18f804a3e87e90e338d14949df2bc511c7c629f55b99f +size 171171 diff --git a/integration/src/fixtures.ts b/integration/src/fixtures.ts index 959af369..54d8717c 100644 --- a/integration/src/fixtures.ts +++ b/integration/src/fixtures.ts @@ -16,11 +16,13 @@ import { ensureCommunity, ensureFullReview, ensurePreprint, + ensureRequestByAuthor, ensureTemplate, findUser, FullReview, Preprint, RapidReview, + Request, Template, User, } from './api'; @@ -41,6 +43,7 @@ type DataFixtures = { community: Community; fullReview: FullReview; preprint: Preprint; + requestByAuthor: Request; template: Template; }; @@ -115,6 +118,11 @@ export const dataFixtures: Fixtures< await use(preprint); }, + requestByAuthor: async ({ fetch, preprint }, use) => { + const requestByAuthor = await ensureRequestByAuthor(fetch, preprint.uuid); + + await use(requestByAuthor); + }, template: async ({ community, faker, fetch }, use) => { const template = await ensureTemplate(fetch, community.uuid, { title: faker.lorem.words(),