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

Commit

Permalink
feat: show hidden setting in visibility section (#1488)
Browse files Browse the repository at this point in the history
* feat: show hidden setting in visibility section

* refactor: apply PR requested changes

* feat: add hidden setting in setting page
  • Loading branch information
pyphilia authored Oct 4, 2024
1 parent db1af00 commit 0e1bed2
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 63 deletions.
74 changes: 73 additions & 1 deletion cypress/e2e/item/hide/hideItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import {
PermissionLevel,
} from '@graasp/sdk';

import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import {
HOME_PATH,
buildItemPath,
buildItemSettingsPath,
buildItemSharePath,
} from '../../../../src/config/paths';
import {
HIDDEN_ITEM_BUTTON_CLASS,
SETTINGS_HIDE_ITEM_ID,
buildHideButtonId,
buildItemsGridMoreButtonSelector,
} from '../../../../src/config/selectors';
Expand Down Expand Up @@ -100,4 +106,70 @@ describe('Hide Item', () => {
expect(classList.some((c) => c.includes('disabled'))).to.be.true;
});
});

describe('Sharing tab', () => {
it('Hide an item', () => {
cy.visit(buildItemSharePath(ITEM.id));

cy.get(`#${SETTINGS_HIDE_ITEM_ID}`).click();

cy.wait(`@postItemTag-${ItemTagType.Hidden}`).then(
({ request: { url } }) => {
expect(url).to.contain(ItemTagType.Hidden);
expect(url).to.contain(ITEM.id);
},
);
});
it('Show an item', () => {
cy.visit(buildItemSharePath(HIDDEN_ITEM.id));

cy.get(`#${SETTINGS_HIDE_ITEM_ID}`).click();

cy.wait(`@deleteItemTag-${ItemTagType.Hidden}`).then(
({ request: { url } }) => {
expect(url).to.contain(ItemTagType.Hidden);
expect(url).to.contain(HIDDEN_ITEM.id);
},
);
});

it('Cannot hide child of hidden item', () => {
cy.visit(buildItemSharePath(CHILD_HIDDEN_ITEM.id));

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

describe('Settings', () => {
it('Hide an item', () => {
cy.visit(buildItemSettingsPath(ITEM.id));

cy.get(`#${SETTINGS_HIDE_ITEM_ID}`).click();

cy.wait(`@postItemTag-${ItemTagType.Hidden}`).then(
({ request: { url } }) => {
expect(url).to.contain(ItemTagType.Hidden);
expect(url).to.contain(ITEM.id);
},
);
});
it('Show an item', () => {
cy.visit(buildItemSettingsPath(HIDDEN_ITEM.id));

cy.get(`#${SETTINGS_HIDE_ITEM_ID}`).click();

cy.wait(`@deleteItemTag-${ItemTagType.Hidden}`).then(
({ request: { url } }) => {
expect(url).to.contain(ItemTagType.Hidden);
expect(url).to.contain(HIDDEN_ITEM.id);
},
);
});

it('Cannot hide child of hidden item', () => {
cy.visit(buildItemSettingsPath(CHILD_HIDDEN_ITEM.id));

cy.get(`#${SETTINGS_HIDE_ITEM_ID}`).should('be.disabled');
});
});
});
19 changes: 19 additions & 0 deletions cypress/e2e/item/share/changeVisibility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID,
SHARE_ITEM_VISIBILITY_SELECT_ID,
UPDATE_VISIBILITY_MODAL_VALIDATE_BUTTON,
VISIBILITY_HIDDEN_ALERT_ID,
buildDataCyWrapper,
buildShareButtonId,
} from '../../../../src/config/selectors';
Expand Down Expand Up @@ -138,6 +139,24 @@ describe('Visibility of an Item', () => {
});
});

it('Show hidden alert', () => {
const item = PackedFolderItemFactory({}, { hiddenTag: {} });
const ITEM_LOGIN_ITEM = {
...item,
itemLoginSchema: {
item,
type: ItemLoginSchemaType.Username,
id: 'efaf3d5a-5688-11eb-ae93-0242ac130002',
createdAt: '2021-08-11T12:56:36.834Z',
updatedAt: '2021-08-11T12:56:36.834Z',
},
};
cy.setUpApi({ items: [ITEM_LOGIN_ITEM] });
cy.visit(buildItemPath(item.id));
cy.get(`#${buildShareButtonId(item.id)}`).click();
cy.get(`#${VISIBILITY_HIDDEN_ALERT_ID}`).should('be.visible');
});

describe('Change visibility of published item', () => {
it('User should validate the change to private', () => {
const item = PublishedItemFactory(
Expand Down
219 changes: 219 additions & 0 deletions cypress/e2e/memberships/viewMemberships.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ const membershipsWithoutAdmin = [
}),
];

const checkItemMembershipRow = ({
id,
name,
permission,
}: {
id: string;
name: string;
permission: 'disabled' | PermissionLevel;
}): void => {
cy.get(buildDataCyWrapper(buildItemMembershipRowId(id)))
.should('contain', name)
.should('contain', i18n.t(permission, { ns: namespaces.enums }));
};

describe('View Memberships - Individual', () => {
beforeEach(() => {
cy.setUpApi({
Expand Down Expand Up @@ -93,6 +107,211 @@ describe('View Memberships - Individual', () => {
});
});

describe('View Memberships - Hidden item', () => {
it('view disabled memberships for hidden item', () => {
const hiddenItem = PackedFolderItemFactory({}, { hiddenTag: {} });
const adminHiddenMembership = buildItemMembership({
item: hiddenItem,
permission: PermissionLevel.Admin,
account: MEMBERS.ANNA,
creator: MEMBERS.ANNA,
});
const writeHiddenMembership = buildItemMembership({
item: hiddenItem,
permission: PermissionLevel.Write,
account: MEMBERS.EVAN,
creator: MEMBERS.ANNA,
});
const readHiddenMembership = buildItemMembership({
item: hiddenItem,
permission: PermissionLevel.Read,
account: MEMBERS.GARRY,
creator: MEMBERS.ANNA,
});
const itemLoginSchema = ItemLoginSchemaFactory({
type: ItemLoginSchemaType.Username,
item: hiddenItem,
});
const guestMemberships = [
buildItemMembership({
item: hiddenItem,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
buildItemMembership({
item: hiddenItem,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
];
const item = hiddenItem;
cy.setUpApi({
items: [
{
...hiddenItem,
itemLoginSchema,
memberships: [
adminHiddenMembership,
writeHiddenMembership,
readHiddenMembership,
...guestMemberships,
],
},
],
});
i18n.changeLanguage(CURRENT_USER.extra.lang);
cy.visit(buildItemSharePath(item.id));

// admin and write are enabled
checkItemMembershipRow({
id: adminHiddenMembership.id,
name: adminHiddenMembership.account.name,
permission: adminHiddenMembership.permission,
});
checkItemMembershipRow({
id: writeHiddenMembership.id,
name: writeHiddenMembership.account.name,
permission: writeHiddenMembership.permission,
});

// read are disabled
checkItemMembershipRow({
id: readHiddenMembership.id,
name: readHiddenMembership.account.name,
permission: ItemLoginSchemaStatus.Disabled,
});

// guests are disabled
for (const { account, id } of guestMemberships) {
const { name } = Object.values(
guestMemberships.map((m) => m.account),
).find(({ id: mId }) => mId === account.id);

// check name and disabled permission
checkItemMembershipRow({
id,
name,
permission: ItemLoginSchemaStatus.Disabled,
});
// check delete button exists
cy.get(`#${buildItemMembershipRowDeleteButtonId(id)}`).should('exist');
}
});
it('view frozen guest membership', () => {
const itemLoginSchema = ItemLoginSchemaFactory({
type: ItemLoginSchemaType.Username,
item: itemWithAdmin,
status: ItemLoginSchemaStatus.Freeze,
});
const guestMemberships = [
buildItemMembership({
item: itemWithAdmin,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
buildItemMembership({
item: itemWithAdmin,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
];
const item = itemWithAdmin;
cy.setUpApi({
items: [
{
...itemWithAdmin,
itemLoginSchema,
memberships: [adminMembership, ...guestMemberships],
},
],
});
i18n.changeLanguage(CURRENT_USER.extra.lang);
cy.visit(buildItemSharePath(item.id));
// editable rows
for (const { permission, account, id } of guestMemberships) {
const { name } = Object.values(
guestMemberships.map((m) => m.account),
).find(({ id: mId }) => mId === account.id);

// check name and disabled permission
cy.get(buildDataCyWrapper(buildItemMembershipRowId(id)))
.should('contain', name)
.should('contain', i18n.t(permission, { ns: namespaces.enums }));

// check delete button exists
cy.get(`#${buildItemMembershipRowDeleteButtonId(id)}`).should('exist');
}
});

it('view disabled guest membership', () => {
const itemLoginSchema = ItemLoginSchemaFactory({
type: ItemLoginSchemaType.Username,
item: itemWithAdmin,
status: ItemLoginSchemaStatus.Disabled,
});
const guestMemberships = [
buildItemMembership({
item: itemWithAdmin,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
buildItemMembership({
item: itemWithAdmin,
permission: PermissionLevel.Read,
account: GuestFactory({
itemLoginSchema,
}),
creator: MEMBERS.ANNA,
}),
];
const item = itemWithAdmin;
cy.setUpApi({
items: [
{
...itemWithAdmin,
itemLoginSchema,
memberships: [adminMembership, ...guestMemberships],
},
],
});
i18n.changeLanguage(CURRENT_USER.extra.lang);
cy.visit(buildItemSharePath(item.id));
// editable rows
for (const { permission, account, id } of guestMemberships) {
const { name } = Object.values(
guestMemberships.map((m) => m.account),
).find(({ id: mId }) => mId === account.id);

// check name and disabled permission
cy.get(buildDataCyWrapper(buildItemMembershipRowId(id)))
.should('contain', name)
.should('not.contain', permission)
.should(
'contain',
i18n.t(ItemLoginSchemaStatus.Disabled, { ns: namespaces.enums }),
);

// check delete button exists
cy.get(`#${buildItemMembershipRowDeleteButtonId(id)}`).should('exist');
}
});
});

describe('View Memberships - Guest', () => {
it('view guest membership', () => {
const itemLoginSchema = ItemLoginSchemaFactory({
Expand Down
Loading

0 comments on commit 0e1bed2

Please sign in to comment.