Skip to content

Commit

Permalink
4641 // Add test to check resource with encoded char id opens correct…
Browse files Browse the repository at this point in the history
…ly in fusion
  • Loading branch information
Dinika committed Jan 22, 2024
1 parent 87ca9a6 commit dbf130d
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
135 changes: 135 additions & 0 deletions cypress/e2e/ResourceContainer.cy.ts
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();
}
});
});
});
4 changes: 4 additions & 0 deletions cypress/fixtures/ResourceWithEncodedCharactersId.json
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": []
}
2 changes: 1 addition & 1 deletion src/shared/containers/ResourceViewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ const ResourceViewContainer: FC<{

return (
<>
<div className="resource-details">
<div className="resource-details" data-testid="resource-details">
<Helmet
title={`${
resource ? getResourceLabel(resource) : resourceId
Expand Down

0 comments on commit dbf130d

Please sign in to comment.