-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 1480 from develop
Develop 1480
- Loading branch information
Showing
24 changed files
with
712 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"recommendations": [ | ||
"editorconfig.editorconfig", | ||
"christian-kohler.npm-intellisense" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "chrome", | ||
"request": "launch", | ||
"name": "Attach SPA debugging (frontend-only)", | ||
"url": "http://localhost:8000", | ||
"webRoot": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "SRR debugging (full-stack)", | ||
"runtimeExecutable": "node", | ||
"runtimeArgs": ["--inspect-brk", "${workspaceFolder}/dist/server.js"], | ||
"env": { | ||
"NODE_ENV": "development", | ||
"DEBUG": "*" | ||
}, | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "openOnSessionStart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"files.eol": "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
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'; | ||
const displayName = 'https%3A%2F%2Fencoded.url%2Fwow'; | ||
|
||
before(() => { | ||
if ( | ||
!Cypress.env('use_existing_delta_instance') || | ||
Cypress.env('use_existing_delta_instance') === false | ||
) { | ||
cy.task('auth:createRealmsAndUsers', Cypress.env('users')); | ||
} | ||
|
||
cy.login( | ||
`${Cypress.env('users').morty.username}-studio`, | ||
Cypress.env('users').morty.realm, | ||
Cypress.env('users').morty.username, | ||
Cypress.env('users').morty.password | ||
).then(() => { | ||
cy.window().then(win => { | ||
const authToken = win.localStorage.getItem('nexus__token'); | ||
cy.wrap(authToken).as('nexusToken'); | ||
|
||
const orgLabel = Cypress.env('ORG_LABEL'); | ||
const projectLabelBase = Cypress.env('PROJECT_LABEL_BASE'); | ||
|
||
cy.task('project:setup', { | ||
nexusApiUrl: Cypress.env('NEXUS_API_URL'), | ||
authToken, | ||
orgLabel, | ||
projectLabelBase, | ||
}).then(({ projectLabel }: { projectLabel: string }) => { | ||
cy.wrap(projectLabel).as('projectLabel'); | ||
cy.fixture('ResourceWithEncodedCharactersId.json').then( | ||
resourcePayload => { | ||
cy.task('resource:create', { | ||
nexusApiUrl: Cypress.env('NEXUS_API_URL'), | ||
authToken, | ||
orgLabel, | ||
projectLabel, | ||
resourcePayload, | ||
}).then((resource: Resource) => { | ||
cy.wrap(resource['@id']).as('fullResourceId'); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.login( | ||
`${Cypress.env('users').morty.username}-report-plugin`, | ||
Cypress.env('users').morty.realm, | ||
Cypress.env('users').morty.username, | ||
Cypress.env('users').morty.password | ||
); | ||
}); | ||
|
||
after(function() { | ||
cy.task('project:teardown', { | ||
nexusApiUrl: Cypress.env('NEXUS_API_URL'), | ||
authToken: this.nexusToken, | ||
orgLabel: Cypress.env('ORG_LABEL'), | ||
projectLabel: this.projectLabel, | ||
}); | ||
}); | ||
|
||
function testResourceDataInJsonViewer() { | ||
cy.findByText('Advanced View').click(); | ||
|
||
cy.contains(`"@id"`); | ||
cy.contains(resourceIdWithEncodedCharacters); | ||
cy.contains('type'); | ||
cy.contains('[]'); | ||
} | ||
|
||
it('resource opens when user clicks on resource row in MyData table', function() { | ||
cy.visit(`/`); | ||
|
||
cy.findAllByText(new RegExp(displayName)) | ||
.first() | ||
.click(); | ||
|
||
cy.findByTestId('resource-details').within(() => { | ||
testResourceDataInJsonViewer(); | ||
}); | ||
}); | ||
|
||
it('resource opens when user directly navigates to resource page', function() { | ||
const resourcePage = `/${Cypress.env('ORG_LABEL')}/${ | ||
this.projectLabel | ||
}/resources/${encodeURIComponent(resourceIdWithEncodedCharacters)}`; | ||
|
||
cy.visit(`${resourcePage}`); | ||
|
||
cy.findByTestId('resource-details').within(() => { | ||
testResourceDataInJsonViewer(); | ||
}); | ||
}); | ||
|
||
it('resource opens with id resolution page', function() { | ||
const resolvePage = `/resolve/${encodeURIComponent( | ||
resourceIdWithEncodedCharacters | ||
)}`; | ||
const resourcePage = `/${Cypress.env('ORG_LABEL')}/${ | ||
this.projectLabel | ||
}/resources/${encodeURIComponent(resourceIdWithEncodedCharacters)}`; | ||
|
||
cy.visit(resolvePage); | ||
|
||
cy.intercept(`${Cypress.env('NEXUS_API_URL')}/${resolvePage}`).as( | ||
'idResolution' | ||
); | ||
|
||
// 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 => { | ||
const resolvedResources = interception.response.body._results; | ||
|
||
if (resolvedResources.length === 1) { | ||
testResourceDataInJsonViewer(); | ||
} else { | ||
// Multiple resources with same id found. | ||
cy.findByText('Open Resource', { | ||
selector: `a[href="${resourcePage}"]`, | ||
}).click(); | ||
testResourceDataInJsonViewer(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"@id": "https://hello.lol/https%3A%2F%2Fencoded.url%2Fwow", | ||
"@type": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/__mocks__/handlers/ResourceListContainerHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { rest } from 'msw'; | ||
import { deltaPath } from '__mocks__/handlers/handlers'; | ||
import { Resource } from '@bbp/nexus-sdk'; | ||
|
||
export const resourcesHandler = rest.get( | ||
deltaPath(`resources/bbp/agents`), | ||
(_, res, ctx) => { | ||
const mockResponse = { | ||
'@context': ['https://bluebrain.github.io/nexus/contexts/metadata.json'], | ||
_total: 3, | ||
_results: [ | ||
getMockResource('1'), | ||
getMockResource('2'), | ||
getMockResource('3'), | ||
], | ||
}; | ||
|
||
return res(ctx.status(200), ctx.json(mockResponse)); | ||
} | ||
); | ||
|
||
export const searchHitsHandler = rest.post( | ||
deltaPath( | ||
'/views/bbp/agents/https%3A%2F%2Fbluebrain.github.io%2Fnexus%2Fvocabulary%2FdefaultElasticSearchIndex/_search' | ||
), | ||
(_, res, ctx) => { | ||
const filteredByDeprecation = { | ||
buckets: [getMockBucket('1'), getMockBucket('2'), getMockBucket('3')], | ||
doc_count_error_upper_bound: 0, | ||
sum_other_doc_count: 0, | ||
}; | ||
const mockResponse = { | ||
aggregations: { | ||
schemas: { | ||
doc_count: 3, | ||
filteredByDeprecation: { ...filteredByDeprecation }, | ||
}, | ||
types: { | ||
doc_count: 8, | ||
filteredByDeprecation: { ...filteredByDeprecation }, | ||
}, | ||
}, | ||
hits: { | ||
hits: [ | ||
getMockSearchHit('1'), | ||
getMockSearchHit('2'), | ||
getMockSearchHit('3'), | ||
], | ||
max_score: 123, | ||
total: { relation: 'eq', value: 11 }, | ||
}, | ||
timed_out: false, | ||
took: 0, | ||
_shards: { failed: 0, skipped: 0, successful: 1, total: 1 }, | ||
}; | ||
|
||
return res( | ||
// Respond with a 200 status code | ||
ctx.status(200), | ||
ctx.json(mockResponse) | ||
); | ||
} | ||
); | ||
|
||
const getMockResource = (id: string, extra?: Partial<Resource>) => ({ | ||
'@id': id, | ||
'@type': ['View'], | ||
description: 'Test description', | ||
name: 'Test name', | ||
_constrainedBy: 'https://bluebrain.github.io/nexus/schemas/views.json', | ||
_createdAt: '2024-01-19T11:40:24.804553Z', | ||
_createdBy: 'https://bbp.epfl.ch/nexus/v1/realms/bbp/users/mockuser', | ||
_deprecated: false, | ||
_incoming: 'test', | ||
_outgoing: 'test', | ||
_project: 'https://dev.nise.bbp.epfl.ch/nexus/v1/projects/bbp/agents', | ||
_rev: 1, | ||
_self: id, | ||
_updatedAt: '2024-01-19T11:40:24.804553Z', | ||
_updatedBy: 'https://bbp.epfl.ch/nexus/v1/realms/bbp/users/mockuser', | ||
_uuid: id, | ||
...extra, | ||
}); | ||
|
||
const getMockSearchHit = (id: string, extra?: Partial<Resource>) => { | ||
const resource = getMockResource(id, extra); | ||
return { | ||
_id: id, | ||
_index: `delta_${id}`, | ||
_score: 123, | ||
_source: { | ||
...resource, | ||
_original_source: JSON.stringify(resource), | ||
}, | ||
_type: '_doc', | ||
}; | ||
}; | ||
|
||
const getMockBucket = (key: string, docCount: number = 1) => ({ | ||
key, | ||
doc_count: docCount, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.