Skip to content

Commit

Permalink
feat: allow press enter to share item (#1550)
Browse files Browse the repository at this point in the history
* feat: allow press enter to share item

* test: add press enter test

* refactor: apply PR requested changes
  • Loading branch information
pyphilia authored Oct 31, 2024
1 parent 9840305 commit bbe3270
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 109 deletions.
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

0 comments on commit bbe3270

Please sign in to comment.