Skip to content

Commit

Permalink
feat: add, edit and delete memberships from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Jun 29, 2021
1 parent 82069ed commit bf9d1fc
Show file tree
Hide file tree
Showing 42 changed files with 1,073 additions and 533 deletions.
28 changes: 28 additions & 0 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export const SAMPLE_ITEMS = {
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -41,6 +48,13 @@ export const SAMPLE_ITEMS = {
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a-5688-11eb-ae93-0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -51,6 +65,13 @@ export const SAMPLE_ITEMS = {
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a-5688-11eb-ae93-0242ac130003',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
Expand All @@ -61,6 +82,13 @@ export const SAMPLE_ITEMS = {
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a-5688-11eb-ae93-0242ac130004',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
],
memberships: [],
Expand Down
4 changes: 4 additions & 0 deletions cypress/fixtures/memberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ export const ITEMS_WITH_MEMBERSHIPS = {
},
memberships: [
{
id: 'ecafbd2a-5688-11eb-be93-0242ac130002',
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
{
id: 'ecafbd2a-5688-11eb-be92-0242ac130002',
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.WRITE,
memberId: MEMBERS.BOB.id,
},
{
id: 'ecafbd1a-5688-11eb-be93-0242ac130002',
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.WRITE,
memberId: MEMBERS.CEDRIC.id,
},
{
id: 'ecbfbd2a-5688-11eb-be93-0242ac130002',
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.READ,
memberId: MEMBERS.DAVID.id,
Expand Down
7 changes: 6 additions & 1 deletion cypress/integration/item/itemLogin/itemLogin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ITEM_LOGIN_SIGN_IN_MODE_ID,
ITEM_LOGIN_SIGN_IN_PASSWORD_ID,
ITEM_LOGIN_SIGN_IN_USERNAME_ID,
ITEM_SETTINGS_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { getItemLoginExtra } from '../../../../src/utils/itemExtra';
import { ITEM_LOGIN_ITEMS } from '../../../fixtures/items';
Expand Down Expand Up @@ -166,19 +167,22 @@ describe('Item Login', () => {
});
});

describe('Display Item Login Setting', () => {
describe.only('Display Item Login Setting', () => {
it('edit item login setting', () => {
cy.setUpApi(ITEM_LOGIN_ITEMS);

// check item with item login enabled
cy.visit(buildItemPath(ITEM_LOGIN_ITEMS.items[0].id));
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();

checkItemLoginSetting({
isEnabled: true,
mode: SETTINGS.ITEM_LOGIN.OPTIONS.USERNAME,
});

// allow item login
cy.visit(buildItemPath(ITEM_LOGIN_ITEMS.items[1].id));
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();
checkItemLoginSetting({
isEnabled: false,
mode: SETTINGS.ITEM_LOGIN.OPTIONS.USERNAME,
Expand All @@ -190,6 +194,7 @@ describe('Item Login', () => {

// disabled at child level
cy.visit(buildItemPath(ITEM_LOGIN_ITEMS.items[5].id));
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();
checkItemLoginSetting({
isEnabled: true,
mode: SETTINGS.ITEM_LOGIN.OPTIONS.USERNAME_AND_PASSWORD,
Expand Down
10 changes: 9 additions & 1 deletion cypress/integration/item/view/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
buildFileItemId,
buildS3FileItemId,
DOCUMENT_ITEM_TEXT_EDITOR_SELECTOR,
ITEM_INFORMATION_BUTTON_ID,
ITEM_INFORMATION_ICON_IS_OPEN_CLASS,
ITEM_PANEL_ID,
ITEM_PANEL_NAME_ID,
ITEM_PANEL_TABLE_ID,
Expand All @@ -18,6 +20,12 @@ import { getMemberById } from '../../../../src/utils/member';
import { MEMBERS } from '../../../fixtures/members';

const expectPanelLayout = ({ name, extra, creator, mimetype }) => {
cy.get(`#${ITEM_PANEL_ID}`).then(($itemPanel) => {
if (!$itemPanel.hasClass(ITEM_INFORMATION_ICON_IS_OPEN_CLASS)) {
cy.get(`#${ITEM_INFORMATION_BUTTON_ID}`).click();
}
});

const panel = cy.get(`#${ITEM_PANEL_ID}`);
panel.get(`#${ITEM_PANEL_NAME_ID}`).contains(name);

Expand Down Expand Up @@ -97,7 +105,7 @@ export const expectLinkViewScreenLayout = ({
}

// table
expectPanelLayout({ name, extra, creator});
expectPanelLayout({ name, extra, creator });
};

export const expectFolderViewScreenLayout = ({ name, creator }) => {
Expand Down
50 changes: 0 additions & 50 deletions cypress/integration/memberships/create/gridShareItem.spec.js

This file was deleted.

57 changes: 0 additions & 57 deletions cypress/integration/memberships/create/listShareItem.spec.js

This file was deleted.

32 changes: 32 additions & 0 deletions cypress/integration/memberships/createItemMembership.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PERMISSION_LEVELS } from '../../../src/enums';
import { buildItemPath } from '../../../src/config/paths';
import { ITEM_SETTINGS_BUTTON_CLASS } from '../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../fixtures/items';
import { MEMBERS } from '../../fixtures/members';

const shareItem = ({ member, permission }) => {
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();

cy.fillShareForm({ member, permission });
};

describe('Create Membership', () => {
it('share item from settings', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, members: Object.values(MEMBERS) });

// go to children item
const { id } = SAMPLE_ITEMS.items[0];
cy.visit(buildItemPath(id));

// share
const member = MEMBERS.ANNA;
const permission = PERMISSION_LEVELS.READ;
shareItem({ id, member, permission });

cy.wait('@shareItem').then(({ request: { url, body } }) => {
expect(url).to.contain(id);
expect(body?.permission).to.equal(permission);
expect(body?.memberId).to.equal(member.id);
});
});
});
29 changes: 29 additions & 0 deletions cypress/integration/memberships/deleteItemMembership.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { buildItemPath } from '../../../src/config/paths';
import {
buildItemMembershipRowDeleteButtonId,
ITEM_SETTINGS_BUTTON_CLASS,
} from '../../../src/config/selectors';
import { ITEMS_WITH_MEMBERSHIPS } from '../../fixtures/memberships';

const deleteItemMembership = (id) => {
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();
cy.get(`#${buildItemMembershipRowDeleteButtonId(id)}`).click();
};

describe('Delete Membership', () => {
it('delete item membership', () => {
cy.setUpApi({ ...ITEMS_WITH_MEMBERSHIPS });

// go to children item
const { id, memberships } = ITEMS_WITH_MEMBERSHIPS.items[0];
cy.visit(buildItemPath(id));

// share
const { id: mId } = memberships[1];
deleteItemMembership(mId);

cy.wait('@deleteItemMembership').then(({ request: { url } }) => {
expect(url).to.contain(mId);
});
});
});
40 changes: 40 additions & 0 deletions cypress/integration/memberships/editItemMembership.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { PERMISSION_LEVELS } from '../../../src/enums';
import { buildItemPath } from '../../../src/config/paths';
import {
buildItemMembershipRowId,
buildPermissionOptionId,
ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS,
ITEM_SETTINGS_BUTTON_CLASS,
} from '../../../src/config/selectors';
import { ITEMS_WITH_MEMBERSHIPS } from '../../fixtures/memberships';

const editItemMembership = ({ id, permission }) => {
cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click();
const select = cy.get(
`#${buildItemMembershipRowId(
id,
)} .${ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS}`,
);
select.click();
select.get(`#${buildPermissionOptionId(permission)}`).click();
};

describe('Edit Membership', () => {
it('edit item membership', () => {
cy.setUpApi({ ...ITEMS_WITH_MEMBERSHIPS });

// go to children item
const { id, memberships } = ITEMS_WITH_MEMBERSHIPS.items[0];
cy.visit(buildItemPath(id));

// update membership
const permission = PERMISSION_LEVELS.READ;
const { id: mId } = memberships[1];
editItemMembership({ id: mId, permission });

cy.wait('@editItemMembership').then(({ request: { url, body } }) => {
expect(url).to.contain(mId);
expect(body?.permission).to.equal(permission);
});
});
});
Loading

0 comments on commit bf9d1fc

Please sign in to comment.