Skip to content

Commit

Permalink
Merge pull request #834 from research-software-directory/e2e-improve
Browse files Browse the repository at this point in the history
Improve e2e tests stability
  • Loading branch information
dmijatovic authored Apr 13, 2023
2 parents 33b2f18 + 9892cc9 commit b2e6418
Show file tree
Hide file tree
Showing 96 changed files with 979 additions and 304 deletions.
19 changes: 3 additions & 16 deletions e2e/.env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ RSD_AUTH_URL=http://auth:7000
# Allowed values are: SURFCONEXT, HELMHOLTZAAI, ORCID or LOCAL
# if env value is not provided default provider is set to be SURFCONEXT
# if you add the value "LOCAL", then local accounts are enabled, USE THIS FOR TESTING PURPOSES ONLY
# NOTE! in e2e ONLY LOCAL provider works because it does not requires secrets/tokens
# in e2e we use LOCAL but we list other 2 providers to test selection modal which otherwise will not be shown.
RSD_AUTH_PROVIDERS=SURFCONEXT;ORCID;LOCAL

# Define a semicolon-separated list of user email addresses (exact match incl. the letter casing) of RSD admins.
# When someome authenticates with an email address in this list,
# they will get a token with as role rsd_admin, meaning they
# have admin rights for all the tables.
# consumed by: authentication
RSD_ADMIN_EMAIL_LIST=[email protected];[email protected]
[email protected]

# Define a semicolon-separated list of user email addresses which are allowed to
# login to the RSD. If the variable is left empty, or is not defined, all users
Expand All @@ -77,21 +79,6 @@ SURFCONEXT_SCOPES=openid
# consumed by: frontend/utils/loginHelpers
SURFCONEXT_RESPONSE_MODE=form_post

# Helmholtz AAI
# consumed by: authentication, frontend/utils/loginHelpers
HELMHOLTZAAI_CLIENT_ID=rsd-dev
# consumed by: authentication, frontend/utils/loginHelpers
HELMHOLTZAAI_REDIRECT=http://localhost/auth/login/helmholtzaai
# consumed by: authentication, frontend/utils/loginHelpers
HELMHOLTZAAI_WELL_KNOWN_URL=https://login-dev.helmholtz.de/oauth2/.well-known/openid-configuration
# consumed by: authentication, frontend/utils/loginHelpers
HELMHOLTZAAI_SCOPES=openid+profile+email+eduperson_principal_name
# consumed by: frontend/utils/loginHelpers
HELMHOLTZAAI_RESPONSE_MODE=query
# consumed by: authentication
# uncomment if you want to allow users from non-Helmholtz centres or social IdPs:
HELMHOLTZAAI_ALLOW_EXTERNAL_USERS=true

# ORCID
# consumed by: authentication, frontend/utils/loginHelpers
ORCID_CLIENT_ID=APP-4D4D69ASWTYOI9QI
Expand Down
4 changes: 2 additions & 2 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
# SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) (dv4all)
# SPDX-FileCopyrightText: 2022 - 2023 dv4all
# SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) (dv4all)
#
# SPDX-License-Identifier: Apache-2.0

# ensure same version is used in package.json for local testing
FROM mcr.microsoft.com/playwright:v1.31.0-focal
FROM mcr.microsoft.com/playwright:v1.32.0-focal

# create working dir
WORKDIR /app
Expand Down
27 changes: 25 additions & 2 deletions e2e/README.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!--
SPDX-FileCopyrightText: 2021 - 2022 Dusan Mijatovic (dv4all)
SPDX-FileCopyrightText: 2021 - 2022 dv4all
SPDX-FileCopyrightText: 2021 - 2023 Dusan Mijatovic (dv4all)
SPDX-FileCopyrightText: 2021 - 2023 dv4all
SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: CC-BY-4.0
Expand Down Expand Up @@ -94,3 +95,25 @@ npx playwright install --with-deps
# install linter
npm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
```

## Generating mention requests

When adding references to research publications for software (mentions) and projects (input/output) RSD needs to make api calls to doi.org, crossref and datacite api's. These calls prove to be "heavy" and less reliable when executed as e2e tests in CI.

To improve e2e tests reliabilty and reduce dependency on external api availablity the json response can be generated once and then reused during test. The json data is saved in mocks/data folder. The files contain DOI in the name.

### How to generate data files

The specific tests are created for generating json files. These test files are in generate folder.

1. **Start RSD**

```bash
docker-compose up -d
```

2. **Start generate project in headed mode**

```bash
npm run e2e:generate
```
3 changes: 2 additions & 1 deletion e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
# SPDX-FileCopyrightText: 2022 - 2023 dv4all
# SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
#
# SPDX-License-Identifier: Apache-2.0

Expand All @@ -11,7 +12,7 @@ services:
build:
context: ./
dockerfile: Dockerfile
image: rsd/e2e-tests:1.0.1
image: rsd/e2e-tests:1.1.0
volumes:
- ./test-results:/app/test-results/
- ./playwright-report:/app/playwright-report
Expand Down
82 changes: 82 additions & 0 deletions e2e/generate/gen_project.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
//
// SPDX-License-Identifier: Apache-2.0

import {test, expect} from '@playwright/test'
import {mockProject} from '../mocks/mockProject'
import {createProject} from '../helpers/project'
import {mockCitations} from '../mocks/mockCitations'
import {openEditPage, openEditSection} from '../helpers/utils'
import {saveCitation} from '../helpers/citations'

// run tests in serial mode
// we first need first to create software
test.describe.serial('Project', async () => {
test('Create project', async ({page}) => {
// we use chrome project mocks by default
const proj = mockProject['chrome']
// start from homepage
await page.goto('/')
// create project
const slug = await createProject({
page,
title: proj.title,
desc: proj.desc,
slug: proj.slug
})
// expect slug
expect(slug).toEqual(proj.slug)
})

test('Add impact', async ({page}) => {
// https://playwright.dev/docs/test-timeouts#test-timeout
// this test need to be marked as slow because it saves all data per DOI
test.slow()
// get mock software for the browser
const project = mockProject['chrome']

// directly open edit software page
const url = `/projects/${project.slug}`
await openEditPage(page, url, project.title)

// navigate to organisations sectiont
await openEditSection(page, 'Impact')

// save all impact requests
const keys = Object.keys(mockCitations)
for (const key of keys) {
const citations = mockCitations[key]
// add citations using doi
for (const item of citations.dois.impact) {
await saveCitation(page, item, 'impact_for_project')
}
}
})

test('Add output', async ({page}) => {
// https://playwright.dev/docs/test-timeouts#test-timeout
// this test need to be marked as slow because it saves all data per DOI
test.slow()
// get mock software for the browser
const project = mockProject['chrome']

// directly open edit software page
const url = `/projects/${project.slug}`
await openEditPage(page, url, project.title)

// navigate to organisations sectiont
await openEditSection(page, 'Output')

// save all impact requests
const keys = Object.keys(mockCitations)
for (const key of keys) {
const citations = mockCitations[key]
// add citations using doi
for (const item of citations.dois.output) {
await saveCitation(page, item, 'output_for_project')
}
}
})
})
58 changes: 58 additions & 0 deletions e2e/generate/gen_software.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) (dv4all)
// SPDX-FileCopyrightText: 2023 dv4all
//
// SPDX-License-Identifier: Apache-2.0

import {test, expect} from '@playwright/test'
import {mockSoftware} from '../mocks/mockSoftware'
import {createSoftware} from '../helpers/software'
import {mockCitations} from '../mocks/mockCitations'
import {openEditPage, openEditSection} from '../helpers/utils'
import {saveCitation} from '../helpers/citations'

// run tests in serial mode
// we first need first to create software
test.describe.serial('Software', async () => {

test('Create software', async ({page}) => {
// get mock software for the browser
const software = mockSoftware['chrome']
// start from homepage
await page.goto('/')
// create software
const slug = await createSoftware({
page,
title: software.title,
desc: software.desc,
slug: software.slug
})
// expect slug
expect(slug).toEqual(software.slug)
})

test('Generate mentions using DOI', async ({page}) => {
// https://playwright.dev/docs/test-timeouts#test-timeout
// this test need to be marked as slow because it saves all data per DOI
test.slow()
// get mock software for the browser
const software = mockSoftware['chrome']

// directly open edit software page
const url = `/software/${software.slug}`
await openEditPage(page, url, software.title)

// navigate to organisations sectiont
await openEditSection(page, 'Mentions')

const keys = Object.keys(mockCitations)
for (const key of keys) {
const citations = mockCitations[key]
// add mentions using doi
for (const item of citations.dois.mention) {
await saveCitation(page, item, 'mention_for_software')
}
}
})
})

Loading

0 comments on commit b2e6418

Please sign in to comment.