Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(refactor): update ShortLink types from SDK #1562

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cypress/e2e/item/share/shareItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
buildShortLinkUrlTextId,
} from '../../../../src/config/selectors';
import { PUBLISHED_ITEM } from '../../../fixtures/items';
import { expectNumberOfShortLinks } from '../../../fixtures/shortLinks';
import {
GRAASP_REDIRECTION_HOST,
buildGraaspBuilderView,
Expand Down Expand Up @@ -129,20 +130,17 @@ describe('Share Item Link', () => {
{
alias: 'test-1',
platform: Context.Builder,
item: { id: item.id },
createdAt: new Date().toISOString(),
itemId: item.id,
},
{
alias: 'test-2',
platform: Context.Player,
item: { id: item.id },
createdAt: new Date().toISOString(),
itemId: item.id,
},
{
alias: 'test-3',
platform: Context.Library,
item: { id: item.id },
createdAt: new Date().toISOString(),
itemId: item.id,
},
];

Expand All @@ -154,7 +152,7 @@ describe('Share Item Link', () => {
cy.visit(buildItemPath(item.id));
cy.get(`#${buildShareButtonId(item.id)}`).click();

cy.wait('@getShortLinksItem').its('response.body.length').should('eq', 3);
expectNumberOfShortLinks(3);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 3);

const context = Context.Builder;
Expand All @@ -166,7 +164,7 @@ describe('Share Item Link', () => {
cy.visit(buildItemPath(item.id));
cy.get(`#${buildShareButtonId(item.id)}`).click();

cy.wait('@getShortLinksItem').its('response.body.length').should('eq', 3);
expectNumberOfShortLinks(3);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 3);

const context = Context.Player;
Expand All @@ -178,7 +176,7 @@ describe('Share Item Link', () => {
cy.visit(buildItemPath(item.id));
cy.get(`#${buildShareButtonId(item.id)}`).click();

cy.wait('@getShortLinksItem').its('response.body.length').should('eq', 3);
expectNumberOfShortLinks(3);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 3);

const context = Context.Library;
Expand All @@ -190,7 +188,7 @@ describe('Share Item Link', () => {
cy.visit(buildItemPath(item.id));
cy.get(`#${buildShareButtonId(item.id)}`).click();

cy.wait('@getShortLinksItem').its('response.body.length').should('eq', 3);
expectNumberOfShortLinks(3);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 3);

cy.get(`#${SHARE_ITEM_QR_BTN_ID}`).click();
Expand Down
99 changes: 30 additions & 69 deletions cypress/e2e/item/share/shortLink.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {
} from '@/config/selectors';

import { PUBLISHED_ITEM } from '../../../fixtures/items';
import {
expectNumberOfShortLinks,
expectShortLinksEquals,
} from '../../../fixtures/shortLinks';

const items = [PackedFolderItemFactory(), PackedFolderItemFactory()];

Expand All @@ -49,9 +53,7 @@ describe('Short links', () => {
cy.get(`#${buildShareButtonId(itemId)}`).click();

// there is no shortlinks for the moment
cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 0);
expectNumberOfShortLinks(0);

// but because the shortlinks "replace" the link,
// there is one link per platform
Expand All @@ -77,9 +79,7 @@ describe('Short links', () => {
},
);

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 1);
expectNumberOfShortLinks(1);
});

it('Add a custom short link', () => {
Expand All @@ -90,9 +90,7 @@ describe('Short links', () => {
cy.get(`#${buildShareButtonId(itemId)}`).click();

// there is no shortlinks for the moment
cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 0);
expectNumberOfShortLinks(0);

// but because the shortlinks "replace" the link,
// there is one link per platform
Expand Down Expand Up @@ -120,9 +118,7 @@ describe('Short links', () => {
expect(postBody.alias).equals(SHORT_LINK_ALIAS);
},
);
cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 1);
expectNumberOfShortLinks(1);
});
});

Expand All @@ -136,14 +132,12 @@ describe('Short links', () => {
{
alias: 'test-1',
platform: Context.Player,
item: { id: itemId },
createdAt: new Date().toISOString(),
itemId,
},
{
alias: 'test-2',
platform: Context.Builder,
item: { id: itemId },
createdAt: new Date().toISOString(),
itemId,
},
];

Expand All @@ -162,9 +156,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(PATCH_ALIAS)}`).click();
cy.get(`#${buildShortLinkEditBtnId(PATCH_ALIAS)}`).click();
Expand All @@ -185,16 +177,11 @@ describe('Short links', () => {
cy.wait('@patchShortLink').then(
({ response: { statusCode: postCode, body: postBody } }) => {
expect(postCode).equals(StatusCodes.OK);
expect(postBody.platform).equals(shortLinks[0].platform);
expect(postBody.alias).equals(NEW_SHORT_LINK);
},
);

cy.wait('@getShortLinksItem').then(({ response: { body } }) => {
expect(body.length).equals(2);
expect(body[0].alias).equals(NEW_SHORT_LINK);
expect(body[1].alias).equals(shortLinks[1].alias);
});
expectShortLinksEquals([NEW_SHORT_LINK, shortLinks[1].alias]);
});

it('Patch short link with random alias', () => {
Expand All @@ -203,9 +190,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(PATCH_ALIAS)}`).click();
cy.get(`#${buildShortLinkEditBtnId(PATCH_ALIAS)}`).click();
Expand All @@ -226,29 +211,24 @@ describe('Short links', () => {
cy.wait('@patchShortLink').then(
({ response: { statusCode: postCode, body: postBody } }) => {
expect(postCode).equals(StatusCodes.OK);
expect(postBody.platform).equals(shortLinks[0].platform);
expect(postBody.alias).not.equals(PATCH_ALIAS);

const randomAlias = postBody.alias;

// We are checking the shortlinks here to have access to the random alias.
expectShortLinksEquals([randomAlias, shortLinks[1].alias]);
},
);

cy.wait('@getShortLinksItem').then(({ response: { body } }) => {
expect(body.length).equals(2);
expect(body[0].alias).not.equals(PATCH_ALIAS);
expect(body[1].alias).equals(shortLinks[1].alias);
});
});

it('Delete short link', () => {
const DELETE_ALIAS = shortLinks[0].alias;
const DELETE_PLATFORM = shortLinks[0].platform;
const KEEP_SHORT_LINK = shortLinks[1];

cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(DELETE_ALIAS)}`).click();
cy.get(`#${buildShortLinkDeleteBtnId(DELETE_ALIAS)}`).click();
Expand All @@ -258,15 +238,11 @@ describe('Short links', () => {
cy.wait('@deleteShortLink').then(
({ response: { statusCode: postCode, body: postBody } }) => {
expect(postCode).equals(StatusCodes.OK);
expect(postBody.platform).equals(DELETE_PLATFORM);
expect(postBody.alias).equals(DELETE_ALIAS);
},
);

cy.wait('@getShortLinksItem').then(({ response: { body } }) => {
expect(body.length).equals(1);
expect(body[0].alias).equals(KEEP_SHORT_LINK.alias);
});
expectShortLinksEquals([KEEP_SHORT_LINK.alias]);
});
});

Expand All @@ -282,14 +258,12 @@ describe('Short links', () => {
{
alias: 'test-1',
platform: Context.Player,
item: { id: itemId },
createdAt: new Date().toISOString(),
itemId,
},
{
alias: 'test-2',
platform: Context.Builder,
item: { id: itemId },
createdAt: new Date().toISOString(),
itemId,
},
];

Expand All @@ -307,9 +281,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(patchAlias)}`).click();
cy.get(`#${buildShortLinkEditBtnId(patchAlias)}`).click();
Expand All @@ -325,9 +297,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(patchAlias)}`).click();
cy.get(`#${buildShortLinkEditBtnId(patchAlias)}`).click();
Expand All @@ -343,9 +313,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(patchAlias)}`).click();
cy.get(`#${buildShortLinkEditBtnId(patchAlias)}`).click();
Expand All @@ -361,9 +329,7 @@ describe('Short links', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 2);
expectNumberOfShortLinks(2);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
cy.get(`#${buildShortLinkMenuBtnId(patchAlias)}`).click();
cy.get(`#${buildShortLinkEditBtnId(patchAlias)}`).click();
Expand Down Expand Up @@ -394,9 +360,7 @@ describe('Short links', () => {
cy.get(`#${buildShareButtonId(itemId)}`).click();

// there is no shortlinks for the moment
cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 0);
expectNumberOfShortLinks(0);

// but because the shortlinks "replace" the link,
// there is one link per platform
Expand All @@ -422,9 +386,7 @@ describe('Short links', () => {
},
);

cy.wait('@getShortLinksItem')
.its('response.body.length')
.should('eq', 1);
expectNumberOfShortLinks(1);
});
});
});
Expand All @@ -445,8 +407,7 @@ describe('Short links', () => {
{
alias: 'test-1',
platform: Context.Player,
item: { id: itemId },
createdAt: new Date().toISOString(),
itemId,
},
];

Expand All @@ -461,7 +422,7 @@ describe('Short links', () => {
it('Short links are read only', () => {
cy.visit(buildItemPath(itemId));
cy.get(`#${buildShareButtonId(itemId)}`).click();
cy.wait('@getShortLinksItem').its('response.body.length').should('eq', 1);
expectNumberOfShortLinks(1);
cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 2);
// This wait is necessary to be sure that the UI render the short links with add and/or menu buttons
cy.wait(1000);
Expand Down
11 changes: 11 additions & 0 deletions cypress/fixtures/shortLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const expectNumberOfShortLinks = (expectedNumber: number): void => {
cy.wait('@getShortLinksItem').then(({ response: { body } }) => {
expect(Object.keys(body).length).equals(expectedNumber);
});
};

export const expectShortLinksEquals = (expectedAlias: string[]): void => {
cy.wait('@getShortLinksItem').then(({ response: { body } }) => {
expectedAlias.forEach((a) => expect(Object.values(body)).includes(a));
});
};
Loading