From 51d465681a47f28ded368b74516695e9bbcdf59b Mon Sep 17 00:00:00 2001 From: Dinika Saxena Date: Fri, 23 Feb 2024 10:34:06 +0100 Subject: [PATCH] Fix loading of resources that have encoded chars in id Signed-off-by: Dinika Saxena --- README.md | 6 +++ c.env.json | 22 +++++++++ cypress.config.ts | 9 +++- cypress/e2e/AnalysisPlugin.cy.ts | 16 +++---- cypress/e2e/ResourceContainer.cy.ts | 23 +++++---- docs/development.md | 5 ++ package.json | 6 ++- .../__tests__/WorkSpaceMenuContainer.spec.tsx | 4 +- yarn.lock | 47 ++++++++++++------- 9 files changed, 97 insertions(+), 41 deletions(-) create mode 100644 c.env.json diff --git a/README.md b/README.md index f27af9513..194ec36fb 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ a. To run the tests in headed mode: yarn cy:open ``` +If you encounter issues with `project:setup` or `resources:create` tasks because of SSL or certificate errors when running the tests locally, try the following: + +```sh +NODE_TLS_REJECT_UNAUTHORIZED=0 yarn cy:open +``` + b. To run the tests in headless mode: ```sh diff --git a/c.env.json b/c.env.json new file mode 100644 index 000000000..7ca828fd1 --- /dev/null +++ b/c.env.json @@ -0,0 +1,22 @@ +{ + "use_existing_delta_instance": false, + "NEXUS_API_URL": "https://dev.nise.bbp.epfl.ch/nexus/v1", + "users": { + "morty": { + "username": "localuser", + "password": "localuser", + "realm": { + "name": "Local", + "baseUrl": "https://dev.nise.bbp.epfl.ch/" + } + }, + "morpheus": { + "username": "localuser", + "password": "localuser", + "realm": { + "name": "Local", + "baseUrl": "https://dev.nise.bbp.epfl.ch/" + } + } + } +} diff --git a/cypress.config.ts b/cypress.config.ts index 27c990f6a..e5692858e 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -11,7 +11,7 @@ import setup, { TestUsers } from './cypress/support/setupRealmsAndUsers'; export default defineConfig({ projectId: '1iihco', viewportWidth: 1200, - video: false, + video: true, screenshotOnRunFailure: false, e2e: { baseUrl: 'http://localhost:8000', @@ -24,6 +24,7 @@ export default defineConfig({ DEBUG: 'cypress:launcher:browsers', ELECTRON_DISABLE_GPU: 'true', ELECTRON_EXTRA_LAUNCH_ARGS: '--disable-gpu', + NODE_TLS_REJECT_UNAUTHORIZED: 0, }, setupNodeEvents(on, config) { on('before:browser:launch', (browser, launchOptions) => { @@ -141,12 +142,16 @@ export default defineConfig({ token: authToken, }); - return await createResource({ + const createdResource = await createResource({ nexus, orgLabel, projectLabel, resource: resourcePayload, }); + if (!createResource) { + throw new Error('Test Resource was not created'); + } + return createdResource; } catch (e) { console.log( 'Error encountered in analysisResource:create task.', diff --git a/cypress/e2e/AnalysisPlugin.cy.ts b/cypress/e2e/AnalysisPlugin.cy.ts index c045a467d..493bbf5c9 100644 --- a/cypress/e2e/AnalysisPlugin.cy.ts +++ b/cypress/e2e/AnalysisPlugin.cy.ts @@ -54,14 +54,14 @@ describe('Report (formerly Analysis) Plugin', () => { ); }); - // after(function() { - // cy.task('project:teardown', { - // nexusApiUrl: Cypress.env('NEXUS_API_URL'), - // authToken: this.nexusToken, - // orgLabel: Cypress.env('ORG_LABEL'), - // projectLabel: this.projectLabel, - // }); - // }); + after(function() { + cy.task('project:teardown', { + nexusApiUrl: Cypress.env('NEXUS_API_URL'), + authToken: this.nexusToken, + orgLabel: Cypress.env('ORG_LABEL'), + projectLabel: this.projectLabel, + }); + }); it('user can add a report with name, description and files, categories, types', function() { cy.visit( diff --git a/cypress/e2e/ResourceContainer.cy.ts b/cypress/e2e/ResourceContainer.cy.ts index 6d336f39a..a10032901 100644 --- a/cypress/e2e/ResourceContainer.cy.ts +++ b/cypress/e2e/ResourceContainer.cy.ts @@ -1,5 +1,3 @@ -import { Resource } from '@bbp/nexus-sdk'; - describe('Resource with id that contains URL encoded characters', () => { const resourceIdWithEncodedCharacters = 'https://hello.lol/https%3A%2F%2Fencoded.url%2Fwow'; @@ -41,8 +39,6 @@ describe('Resource with id that contains URL encoded characters', () => { orgLabel, projectLabel, resourcePayload, - }).then((resource: Resource) => { - cy.wrap(resource['@id']).as('fullResourceId'); }); } ); @@ -53,7 +49,7 @@ describe('Resource with id that contains URL encoded characters', () => { beforeEach(() => { cy.login( - `${Cypress.env('users').morty.username}-report-plugin`, + `${Cypress.env('users').morty.username}-studio`, Cypress.env('users').morty.realm, Cypress.env('users').morty.username, Cypress.env('users').morty.password @@ -78,8 +74,9 @@ describe('Resource with id that contains URL encoded characters', () => { cy.contains('[]'); } - it('resource opens when user clicks on resource row in MyData table', function() { + it.only('resource opens when user clicks on resource row in MyData table', function() { cy.visit(`/`); + cy.findByText('Neuron Morphology'); cy.findAllByText(new RegExp(displayName)) .first() @@ -90,8 +87,9 @@ describe('Resource with id that contains URL encoded characters', () => { }); }); - it('resource with any id opens when user clicks on resource row in Search table', function() { - cy.visit(`/search?layout=Neuron%20Morphology`); + it.only('resource with any id opens when user clicks on resource row in Search table', function() { + cy.visit(`/`); + cy.findByText('Neuron Morphology').click(); cy.findAllByTestId('search-table-row') .first() @@ -114,6 +112,7 @@ describe('Resource with id that contains URL encoded characters', () => { }); it('resource opens with id resolution page', function() { + cy.visit('/'); const resolvePage = `/resolve/${encodeURIComponent( resourceIdWithEncodedCharacters )}`; @@ -130,9 +129,13 @@ describe('Resource with id that contains URL encoded characters', () => { // If many e2e tests ran together there may be many resources with same id. // In this case the id resolution page will look different. Test accordingly. cy.wait('@idResolution').then(interception => { + // expect(interception.response.body).to.equal(200); + // expect(interception.response.statusMessage).to.equal(200); + expect(interception.response.statusCode).to.equal(200); const resolvedResources = interception.response.body._results; - - if (resolvedResources.length === 1) { + cy.log(`Resolved resources delta response`, interception.response.body); + console.log('Resolved resources delta', interception.response.body); + if (resolvedResources?.length === 1) { testResourceDataInJsonViewer(); } else { // Multiple resources with same id found. diff --git a/docs/development.md b/docs/development.md index d598d54e3..d8dbc6b41 100644 --- a/docs/development.md +++ b/docs/development.md @@ -291,6 +291,11 @@ yarn run cy:ci 6. You can also navigate to in your browser to see the same instance of fusion that cypress is testing. +NOTE: + +- Depending on the scenario you want to test, you might want to remove/rename the `cypress.env.json` (or set `use_existing_delta_instance` key to `false`) +- If there are issues with logging into http://fusion.test:8000, make sure your chrome browser has the `--unsafely-treat-insecure-origin-as-secure` flag set to `http://keycloak.test:8080` + 7. Remember to stop the services once done: ```sh diff --git a/package.json b/package.json index e17dd413c..09668482f 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "e2e:open": "cypress open", "e2e:run": "cypress run --config-file cypress.config.ts", "e2e:ci": "echo | sudo docker exec --user=$UID -t cypress cypress run --headless --config-file cypress.config.ts --browser chrome", + "cy:ci": "echo | sudo docker exec --user=$UID -t cypress cypress run --config-file cypress.config.ts --browser chrome", "e2e:ps": "echo | cypress run --config-file cypress-public-studios.config.ts --browser chrome --spec \"cypress/e2e/PublicStudios.cy.ts\"", "e2e:ui": "API_ENDPOINT=http://test start-server-and-test dev http://localhost:8000 cy:run" }, @@ -66,7 +67,7 @@ "deep-object-diff": "^1.1.0", "express": "^4.18.2", "handlebars": "^4.7.7", - "history": "^4.7.2", + "history": "4.5.1", "https-browserify": "^1.0.0", "json2csv": "^5.0.5", "jwt-decode": "^2.2.0", @@ -228,7 +229,8 @@ }, "resolutions": { "d3-interpolate": "2.0.1", - "headers-polyfill": "3.0.10" + "headers-polyfill": "3.0.10", + "history": "4.5.1" }, "overrides": { "d3-interpolate": "2.0.1" diff --git a/src/subapps/studioLegacy/containers/__tests__/WorkSpaceMenuContainer.spec.tsx b/src/subapps/studioLegacy/containers/__tests__/WorkSpaceMenuContainer.spec.tsx index d6ead648a..620d17dc6 100644 --- a/src/subapps/studioLegacy/containers/__tests__/WorkSpaceMenuContainer.spec.tsx +++ b/src/subapps/studioLegacy/containers/__tests__/WorkSpaceMenuContainer.spec.tsx @@ -1,7 +1,7 @@ import '@testing-library/jest-dom'; import { vi, describe } from 'vitest'; import { NexusProvider } from '@bbp/react-nexus'; -import { createBrowserHistory } from 'history'; +import { createMemoryHistory } from 'history'; import { createNexusClient } from '@bbp/nexus-sdk'; import { Provider } from 'react-redux'; import { QueryClient, QueryClientProvider } from 'react-query'; @@ -26,7 +26,7 @@ import { setupServer } from 'msw/node'; describe( 'workSpaceMenu', () => { - const history = createBrowserHistory({ basename: '/' }); + const history = createMemoryHistory({}); const contextValue: StudioContextType = { orgLabel: 'org', projectLabel: 'project', diff --git a/yarn.lock b/yarn.lock index f83753386..4f2c8029b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6789,17 +6789,16 @@ hey-listen@^1.0.8: resolved "https://registry.yarnpkg.com/hey-listen/-/hey-listen-1.0.8.tgz#8e59561ff724908de1aa924ed6ecc84a56a9aa68" integrity sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q== -history@^4.7.2, history@^4.9.0: - version "4.10.1" - resolved "https://registry.yarnpkg.com/history/-/history-4.10.1.tgz#33371a65e3a83b267434e2b3f3b1b4c58aad4cf3" - integrity sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew== +history@4.5.1, history@^4.9.0: + version "4.5.1" + resolved "https://registry.yarnpkg.com/history/-/history-4.5.1.tgz#44935a51021e3b8e67ebac267a35675732aba569" + integrity sha512-gfHeJeYeMzFtos61gdA1AloO0hGXPF2Yum+2FRdJvlylYQOz51OnT1zuwg9UYst1BRrONhcAh3Nmsg9iblgl6g== dependencies: - "@babel/runtime" "^7.1.2" + invariant "^2.2.1" loose-envify "^1.2.0" - resolve-pathname "^3.0.0" - tiny-invariant "^1.0.2" - tiny-warning "^1.0.0" - value-equal "^1.0.1" + resolve-pathname "^2.0.0" + value-equal "^0.2.0" + warning "^3.0.0" hmac-drbg@^1.0.1: version "1.0.1" @@ -7082,6 +7081,13 @@ internal-slot@^1.0.4, internal-slot@^1.0.5: hasown "^2.0.0" side-channel "^1.0.4" +invariant@^2.2.1: + version "2.2.4" + resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" + integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA== + dependencies: + loose-envify "^1.0.0" + inversify-inject-decorators@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/inversify-inject-decorators/-/inversify-inject-decorators-3.1.0.tgz#d9941080bad77cec8a65ee29d905e4d5d73e1e95" @@ -10815,10 +10821,10 @@ resolve-global@1.0.0, resolve-global@^1.0.0: dependencies: global-dirs "^0.1.1" -resolve-pathname@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" - integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng== +resolve-pathname@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-2.2.0.tgz#7e9ae21ed815fd63ab189adeee64dc831eefa879" + integrity sha512-bAFz9ld18RzJfddgrO2e/0S2O81710++chRMUxHjXOYKF6jTAMrUNZrEZ1PvV0zlhfjidm08iRPdTLPno1FuRg== resolve-pkg-maps@^1.0.0: version "1.0.0" @@ -12585,10 +12591,10 @@ validate-npm-package-name@^4.0.0: dependencies: builtins "^5.0.0" -value-equal@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c" - integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw== +value-equal@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-0.2.1.tgz#c220a304361fce6994dbbedaa3c7e1a1b895871d" + integrity sha512-yRL36Xb2K/HmFT5Fe3M86S7mu4+a12/3l7uytUh6eNPPjP77ldPBvsAvmnWff39sXn55naRMZN8LZWRO8PWaeQ== vary@~1.1.2: version "1.1.2" @@ -12787,6 +12793,13 @@ w3c-xmlserializer@^4.0.0: dependencies: xml-name-validator "^4.0.0" +warning@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c" + integrity sha512-jMBt6pUrKn5I+OGgtQ4YZLdhIeJmObddh6CsibPxyQ5yPZm1XExSyzC1LCNX7BzhxWgiHmizBWJTHJIjMjTQYQ== + dependencies: + loose-envify "^1.0.0" + wcwidth@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"