-
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.
4641 // Add test to check resource with encoded char id opens correct…
…ly in fusion
- Loading branch information
Showing
3 changed files
with
140 additions
and
1 deletion.
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,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