From 94a31ced48a7f3685f2bcc18b8a754bfd9e2e011 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 +++ cypress.config.ts | 7 ++- ...lysisPlugin.cy.ts => AnalysisPlugni.cy.ts} | 16 +++---- cypress/e2e/ResourceContainer.cy.ts | 20 ++++---- package.json | 5 +- .../__tests__/WorkSpaceMenuContainer.spec.tsx | 4 +- yarn.lock | 47 ++++++++++++------- 7 files changed, 66 insertions(+), 39 deletions(-) rename cypress/e2e/{AnalysisPlugin.cy.ts => AnalysisPlugni.cy.ts} (96%) 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/cypress.config.ts b/cypress.config.ts index 27c990f6a..d489287d6 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -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/AnalysisPlugni.cy.ts similarity index 96% rename from cypress/e2e/AnalysisPlugin.cy.ts rename to cypress/e2e/AnalysisPlugni.cy.ts index c045a467d..493bbf5c9 100644 --- a/cypress/e2e/AnalysisPlugin.cy.ts +++ b/cypress/e2e/AnalysisPlugni.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..c2d07b922 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 @@ -90,8 +86,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 +111,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 +128,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/package.json b/package.json index e17dd413c..7b460f2cd 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,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 +228,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"