Skip to content

Commit

Permalink
test: add tests for share item modal
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Jul 28, 2021
1 parent 8ba07b1 commit 3294ff1
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export const SAMPLE_ITEMS = {
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.READ,
memberId: MEMBERS.BOB.id,
},
],
},
{
Expand Down
69 changes: 69 additions & 0 deletions cypress/integration/item/share/shareItemModal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
ACCESS_INDICATION_ID,
buildShareButtonId,
ITEM_MEMBERSHIPS_CONTENT_ID,
SHARE_ITEM_DIALOG_LINK_ID,
SHARE_ITEM_DIALOG_LINK_SELECT_ID,
} from '../../../../src/config/selectors';
import {
buildGraaspComposeView,
buildGraaspPerformView,
buildItemPath,
} from '../../../../src/config/paths';
import {
ITEM_LOGIN_ITEMS,
SAMPLE_ITEMS,
SAMPLE_PUBLIC_ITEMS,
} from '../../../fixtures/items';
import { PERFORM_VIEW_SELECTION } from '../../../../src/config/constants';

const openShareItemModal = (id) => {
cy.get(`#${buildShareButtonId(id)}`).click();
};

describe('Share Item Modal', () => {
it('Display Perform or Compose Link', () => {
cy.setUpApi(SAMPLE_ITEMS);
const item = SAMPLE_ITEMS.items[0];
cy.visit(buildItemPath(item.id));
openShareItemModal(item.id);
cy.get(`#${SHARE_ITEM_DIALOG_LINK_ID}`).should(
'contain',
`${buildGraaspComposeView(item.id)}`,
);
cy.get(`#${SHARE_ITEM_DIALOG_LINK_SELECT_ID}`).click();
cy.get(`li[data-value="${PERFORM_VIEW_SELECTION}"]`).click();
cy.get(`#${SHARE_ITEM_DIALOG_LINK_ID}`).should(
'have.text',
`${buildGraaspPerformView(item.id)}`,
);
});

it('Display Public Information for public item', () => {
cy.setUpApi(SAMPLE_PUBLIC_ITEMS);
const item = SAMPLE_PUBLIC_ITEMS.items[0];
cy.visit(buildItemPath(item.id));
openShareItemModal(item.id);
cy.get(`#${ACCESS_INDICATION_ID}`)
.should('exist')
.should('contain.text', 'Public');
});

it('Display Item Login Information for item with item login', () => {
cy.setUpApi(ITEM_LOGIN_ITEMS);
const item = ITEM_LOGIN_ITEMS.items[0];
cy.visit(buildItemPath(item.id));
openShareItemModal(item.id);
cy.get(`#${ACCESS_INDICATION_ID}`)
.should('exist')
.should('contain.text', 'authenticated with the link');
});

it('Display Item Memberships for item', () => {
cy.setUpApi(SAMPLE_ITEMS);
const item = SAMPLE_ITEMS.items[1];
cy.visit(buildItemPath(item.id));
openShareItemModal(item.id);
cy.get(`#${ITEM_MEMBERSHIPS_CONTENT_ID}`).should('exist');
});
});
8 changes: 7 additions & 1 deletion src/components/context/AccessIndication.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { hooks } from '../../config/queryClient';
import ItemMemberships from '../item/ItemMemberships';
import { hasItemLoginEnabled, isItemPublic } from '../../utils/itemTag';
import { SHARE_MODAL_AVATAR_GROUP_MAX_AVATAR } from '../../config/constants';
import { ACCESS_INDICATION_ID } from '../../config/selectors';

const AccessIndication = ({ itemId, onClick }) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -48,7 +49,12 @@ const AccessIndication = ({ itemId, onClick }) => {

if (accessText && tooltipText) {
return (
<Grid container justify="space-between" alignItems="center">
<Grid
container
justify="space-between"
alignItems="center"
id={ACCESS_INDICATION_ID}
>
<Grid item>
<Typography variant="body1">
{`${t('Access')}: ${accessText}`}
Expand Down
20 changes: 18 additions & 2 deletions src/components/context/ShareItemModalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import { copyToClipboard } from '../../utils/clipboard';
import notifier from '../../middlewares/notifier';
import { COPY_ITEM_LINK_TO_CLIPBOARD } from '../../types/clipboard';
import AccessIndication from './AccessIndication';
import {
SHARE_ITEM_DIALOG_ID,
SHARE_ITEM_DIALOG_LINK_ID,
SHARE_ITEM_DIALOG_LINK_SELECT_ID,
} from '../../config/selectors';

const ShareItemModalContext = React.createContext();

Expand Down Expand Up @@ -135,20 +140,31 @@ const ShareItemModalProvider = ({ children }) => {

return (
<ShareItemModalContext.Provider value={{ openModal }}>
<Dialog open={open} onClose={onClose} maxWidth="md">
<Dialog
open={open}
onClose={onClose}
maxWidth="md"
id={SHARE_ITEM_DIALOG_ID}
>
<DialogTitle>{t('Share Item')}</DialogTitle>
<DialogContent className={classes.dialogContent}>
{itemId ? (
<>
<div className={classes.shareLinkContainer}>
<Link className={classes.shareLink} href={link} target="_blank">
<Link
className={classes.shareLink}
href={link}
target="_blank"
id={SHARE_ITEM_DIALOG_LINK_ID}
>
{link}
</Link>
<div>
<Select
className={classes.selector}
value={linkType}
onChange={handleLinkTypeChange}
id={SHARE_ITEM_DIALOG_LINK_SELECT_ID}
>
<MenuItem value={COMPOSE_VIEW_SELECTION}>
{t('Compose')}
Expand Down
2 changes: 1 addition & 1 deletion src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const AUTHENTICATION_HOST =
export const GRAASP_PERFORM_HOST =
ENV_GRAASP_PERFORM_HOST ||
process.env.REACT_APP_GRAASP_PERFORM_HOST ||
'http://localhost:3113';
'http://localhost:3112';

export const DESCRIPTION_MAX_LENGTH = 30;

Expand Down
4 changes: 4 additions & 0 deletions src/config/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ export const buildPerformButtonId = (id) => `performButton-${id}`;
export const buildEditButtonId = (id) => `editButton-${id}`;
export const buildSettingsButtonId = (id) => `settingsButton-${id}`;
export const PUBLIC_SETTING_SWITCH_ID = 'publicSettingSwitch';
export const SHARE_ITEM_DIALOG_ID = 'shareItemDialog';
export const SHARE_ITEM_DIALOG_LINK_ID = 'shareItemDialogLink';
export const SHARE_ITEM_DIALOG_LINK_SELECT_ID = 'shareItemDialogLinkSelect';
export const ACCESS_INDICATION_ID = 'accessIndication';
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@

"@graasp/query-client@git://github.com/graasp/graasp-query-client.git#main":
version "0.1.0"
resolved "git://github.com/graasp/graasp-query-client.git#65837f1098a01e930a0d8e5cd3243e53936f9dc6"
resolved "git://github.com/graasp/graasp-query-client.git#914eff7d6d5449893590c3208ec3af4fe9675be1"
dependencies:
http-status-codes "2.1.4"
immutable "4.0.0-rc.12"
Expand Down

0 comments on commit 3294ff1

Please sign in to comment.