Skip to content

Commit

Permalink
fix: hide publish tab for reader and public (#721)
Browse files Browse the repository at this point in the history
* fix: hide publish tab for reader and public

* refactor: fix tests
  • Loading branch information
pyphilia authored Jul 28, 2023
1 parent a187372 commit 2b40b72
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cypress/e2e/item/publish/coEditorSettings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
32 changes: 32 additions & 0 deletions cypress/e2e/item/publish/publishedItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/item/publish/tags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
1 change: 1 addition & 0 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const mockGetCurrentMember = (
url: `${API_HOST}/${GET_CURRENT_MEMBER_ROUTE}`,
},
({ reply }) => {

if (shouldThrowError) {
return reply({
statusCode: StatusCodes.INTERNAL_SERVER_ERROR,
Expand Down
4 changes: 2 additions & 2 deletions src/components/item/header/ItemHeaderActions.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -51,7 +51,7 @@ const ItemHeaderActions = ({ item }: Props): JSX.Element => {
? getHighestPermissionForMemberFromMemberships({
memberships,
memberId: member?.id,
})
})?.permission === PermissionLevel.Admin
: false;

const onClickChatbox = () => {
Expand Down

0 comments on commit 2b40b72

Please sign in to comment.