Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

feat: allow press enter to share item #1550

Merged
merged 3 commits into from
Oct 31, 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
95 changes: 93 additions & 2 deletions cypress/e2e/memberships/createItemMembership.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import {
PermissionLevel,
} from '@graasp/sdk';

import { buildItemPath } from '../../../src/config/paths';
import { buildItemPath, buildItemSharePath } from '../../../src/config/paths';
import {
CREATE_MEMBERSHIP_FORM_ID,
ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS,
SHARE_BUTTON_SELECTOR,
SHARE_ITEM_CANCEL_BUTTON_CY,
SHARE_ITEM_EMAIL_INPUT_ID,
SHARE_ITEM_SHARE_BUTTON_ID,
buildDataCyWrapper,
buildShareButtonId,
} from '../../../src/config/selectors';
import { MEMBERS } from '../../fixtures/members';
Expand Down Expand Up @@ -69,7 +73,71 @@ describe('Create Membership', () => {
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
});

it('cannot share item twice', () => {
it('open share modal, cancel and sharing reset content', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });

// go to children item
const { id } = FOLDER;
cy.visit(buildItemSharePath(id));

// open modal and cancel
cy.get(buildDataCyWrapper(SHARE_BUTTON_SELECTOR)).click();
cy.get(buildDataCyWrapper(SHARE_ITEM_CANCEL_BUTTON_CY)).click();
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('not.exist');

// share
const member = MEMBERS.FANNY;
const permission = PermissionLevel.Admin;
cy.fillShareForm({
email: member.email,
permission,
selector: `#${CREATE_MEMBERSHIP_FORM_ID}`,
});

// check that fields are reset if reopen modal
cy.get(buildDataCyWrapper(SHARE_BUTTON_SELECTOR)).click();
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
cy.get(`.${ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS} input`).should(
'have.value',
PermissionLevel.Read,
);
});

it('share item with new admin by pressing enter', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });

// go to children item
const { id } = FOLDER;
cy.visit(buildItemPath(id));

// share
const member = MEMBERS.FANNY;
const permission = PermissionLevel.Admin;
shareItem({
id,
email: `${member.email}{Enter}`,
permission,
submit: false,
});

cy.wait('@postInvitations').then(
({
request: {
url,
body: { invitations },
},
}) => {
expect(url).to.contain(id);
expect(invitations[0].permission).to.equal(permission);
expect(invitations[0].email).to.equal(member.email);
},
);

// check that the email field is emptied after sharing completes
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
});

it('cannot add membership item twice', () => {
const ITEM = PackedFolderItemFactory();
const account = MEMBERS.ANNA;
cy.setUpApi({
Expand Down Expand Up @@ -99,6 +167,29 @@ describe('Create Membership', () => {
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('be.disabled');
});

it('cannot invite user twice', () => {
const ITEM = PackedFolderItemFactory();
const { email } = MEMBERS.CEDRIC;
cy.setUpApi({
items: [
{
...ITEM,
invitations: [{ email }],
},
],
members: Object.values(MEMBERS),
});

const { id } = ITEM;
cy.visit(buildItemPath(id));

// fill
const permission = PermissionLevel.Read;
shareItem({ id, email, permission });

cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('be.disabled');
});

it('cannot share item with invalid data', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });

Expand Down
4 changes: 1 addition & 3 deletions cypress/support/commands/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ Cypress.Commands.add(
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).type(email);

if (submit) {
// wait for email to be validated and enable the button
cy.wait(1000);
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).click('left');
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).click();
}
},
);
Expand Down
Loading