From 2b40b724025ad2f8b58a965ac151127d57386667 Mon Sep 17 00:00:00 2001 From: Kim Lan Phan Hoang Date: Fri, 28 Jul 2023 16:23:15 +0200 Subject: [PATCH] fix: hide publish tab for reader and public (#721) * fix: hide publish tab for reader and public * refactor: fix tests --- .../e2e/item/publish/coEditorSettings.cy.ts | 3 +- cypress/e2e/item/publish/publishedItem.cy.ts | 32 +++++++++++++++++++ cypress/e2e/item/publish/tags.cy.ts | 3 +- cypress/support/server.ts | 1 + .../item/header/ItemHeaderActions.tsx | 4 +-- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/item/publish/coEditorSettings.cy.ts b/cypress/e2e/item/publish/coEditorSettings.cy.ts index 2d298d0bc..b6d1f0b0b 100644 --- a/cypress/e2e/item/publish/coEditorSettings.cy.ts +++ b/cypress/e2e/item/publish/coEditorSettings.cy.ts @@ -83,7 +83,6 @@ describe('Co-editor setting permissions', () => { cy.visit(buildItemPath(item.id)); cy.get(`#${ITEM_HEADER_ID}`).should('be.visible'); - openPublishItemTab(item.id); - cy.get(`#${CO_EDITOR_SETTINGS_RADIO_GROUP_ID}`).should('not.exist'); + cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist'); }); }); diff --git a/cypress/e2e/item/publish/publishedItem.cy.ts b/cypress/e2e/item/publish/publishedItem.cy.ts index be8dd29be..b3c0701fe 100644 --- a/cypress/e2e/item/publish/publishedItem.cy.ts +++ b/cypress/e2e/item/publish/publishedItem.cy.ts @@ -11,6 +11,8 @@ import { SAMPLE_ITEMS, SAMPLE_PUBLIC_ITEMS, } from '../../../fixtures/items'; +import { MEMBERS } from '../../../fixtures/members'; +import { PAGE_LOAD_WAITING_PAUSE } from '../../../support/constants'; const openPublishItemTab = (id) => { cy.get(`#${buildPublishButtonId(id)}`).click(); @@ -21,6 +23,36 @@ export const publishItem = (): void => { cy.get(`#${ITEM_PUBLISH_BUTTON_ID}`).click(); }; +describe('Public', ()=> { + it('Should not view publish tab', () => { + const item = SAMPLE_PUBLIC_ITEMS.items[0]; + cy.setUpApi({ + items: [item], + currentMember:null + }); + cy.visit(buildItemPath(item.id)); + + // wait for page to fully load + cy.wait(PAGE_LOAD_WAITING_PAUSE) + cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist'); + }); +}) + +describe('Read', ()=> { + it('Should not view publish tab', () => { + const item = SAMPLE_ITEMS.items[1]; + cy.setUpApi({ + items: [item], + currentMember: MEMBERS.BOB + }); + cy.visit(buildItemPath(item.id)); + + // wait for page to fully load + cy.wait(PAGE_LOAD_WAITING_PAUSE) + cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist'); + }); +}) + describe('Public Item', () => { it('Validate item', () => { cy.setUpApi(SAMPLE_PUBLIC_ITEMS); diff --git a/cypress/e2e/item/publish/tags.cy.ts b/cypress/e2e/item/publish/tags.cy.ts index 55609556a..bc9191317 100644 --- a/cypress/e2e/item/publish/tags.cy.ts +++ b/cypress/e2e/item/publish/tags.cy.ts @@ -88,7 +88,6 @@ describe('Tags permissions', () => { cy.visit(buildItemPath(item.id)); cy.get(`#${ITEM_HEADER_ID}`).should('be.visible'); - openPublishItemTab(item.id); - cy.get(`#${ITEM_TAGS_EDIT_INPUT_ID}`).should('not.exist'); + cy.get(`#${buildPublishButtonId(item.id)}`).should('not.exist'); }); }); diff --git a/cypress/support/server.ts b/cypress/support/server.ts index 402c0274a..f8976e01a 100644 --- a/cypress/support/server.ts +++ b/cypress/support/server.ts @@ -137,6 +137,7 @@ export const mockGetCurrentMember = ( url: `${API_HOST}/${GET_CURRENT_MEMBER_ROUTE}`, }, ({ reply }) => { + if (shouldThrowError) { return reply({ statusCode: StatusCodes.INTERNAL_SERVER_ERROR, diff --git a/src/components/item/header/ItemHeaderActions.tsx b/src/components/item/header/ItemHeaderActions.tsx index 33fa702bc..80fac2c65 100644 --- a/src/components/item/header/ItemHeaderActions.tsx +++ b/src/components/item/header/ItemHeaderActions.tsx @@ -1,6 +1,6 @@ import { Stack } from '@mui/material'; -import { ItemType } from '@graasp/sdk'; +import { ItemType, PermissionLevel } from '@graasp/sdk'; import { ItemRecord } from '@graasp/sdk/frontend'; import { BUILDER } from '@graasp/translations'; import { ChatboxButton } from '@graasp/ui'; @@ -51,7 +51,7 @@ const ItemHeaderActions = ({ item }: Props): JSX.Element => { ? getHighestPermissionForMemberFromMemberships({ memberships, memberId: member?.id, - }) + })?.permission === PermissionLevel.Admin : false; const onClickChatbox = () => {