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

Commit

Permalink
refactor: translate, fix pr requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 13, 2024
1 parent afdfdda commit 8898158
Show file tree
Hide file tree
Showing 27 changed files with 1,311 additions and 2,177 deletions.
16 changes: 16 additions & 0 deletions cypress/e2e/item/authorization/forbidden.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PackedFolderItemFactory } from '@graasp/sdk';

import { buildItemPath } from '@/config/paths';
import { ITEM_LOGIN_SCREEN_FORBIDDEN_ID } from '@/config/selectors';

it('User is logged out and item is private', () => {
const item = PackedFolderItemFactory({}, { permission: null });
cy.setUpApi({
items: [item],
currentMember: null,
});

cy.visit(buildItemPath(item.id));

cy.get(`#${ITEM_LOGIN_SCREEN_FORBIDDEN_ID}`).should('be.visible');
});
20 changes: 5 additions & 15 deletions cypress/e2e/item/authorization/itemLogin/itemLogin.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { ItemLoginSchemaType, PackedFolderItemFactory } from '@graasp/sdk';
import { SETTINGS_ITEM_LOGIN_DEFAULT } from '../../../../../src/config/constants';
import { buildItemPath } from '../../../../../src/config/paths';
import {
ENROLL_BUTTON_SELECTOR,
ITEM_LOGIN_SIGN_IN_BUTTON_ID,
ITEM_LOGIN_SIGN_IN_PASSWORD_ID,
ITEM_LOGIN_SIGN_IN_USERNAME_ID,
buildDataCyWrapper,
} from '../../../../../src/config/selectors';
import { MEMBERS, SIGNED_OUT_MEMBER } from '../../../../fixtures/members';
import { ITEM_LOGIN_PAUSE } from '../../../../support/constants';
Expand Down Expand Up @@ -53,12 +55,6 @@ describe('User is signed out', () => {
username: 'username',
});
cy.wait('@postItemLogin');

// use username to check no member id is incorrectly sent
fillItemLoginScreenLayout({
username: 'username',
});
cy.wait('@postItemLogin');
});
it('username and password', () => {
const item = addItemLoginSchema(
Expand All @@ -74,13 +70,6 @@ describe('User is signed out', () => {
password: 'password',
});
cy.wait('@postItemLogin');

// use username to check no member id is incorrectly sent
fillItemLoginScreenLayout({
username: 'username',
password: 'password',
});
cy.wait('@postItemLogin');
});
});

Expand Down Expand Up @@ -124,7 +113,8 @@ describe('User is signed in as normal user', () => {
// to remove when requests loading time is properly managed
cy.wait(ITEM_LOGIN_PAUSE);

// show enroll button
cy.click('iojwlmke');
// enroll
cy.get(buildDataCyWrapper(ENROLL_BUTTON_SELECTOR)).click();
cy.wait('ENROLL');
});
});
15 changes: 4 additions & 11 deletions cypress/e2e/item/authorization/itemLogin/itemLoginSetting.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
ItemLoginSchemaType,
PackedFolderItemFactory,
PackedItem,
PermissionLevel,
} from '@graasp/sdk';

import { v4 } from 'uuid';

import { buildItemPath } from '../../../../../src/config/paths';
import {
ITEM_LOGIN_SCREEN_FORBIDDEN_ID,
Expand All @@ -15,23 +12,21 @@ import {
} from '../../../../../src/config/selectors';
import { MEMBERS } from '../../../../fixtures/members';
import { ITEM_LOGIN_PAUSE } from '../../../../support/constants';
import { addItemLoginSchema } from './utils';

const checkItemLoginSetting = ({
isEnabled,
mode,
disabled = false,
}: {
isEnabled: boolean;
mode: string;
disabled?: boolean;
}) => {
if (isEnabled && !disabled) {
if (!disabled) {
cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID} + input`).should(
'have.value',
mode,
);
}
if (disabled) {
} else {
cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID}`).then((el) => {
// test classnames are 'disabled'
expect(el.parent().html()).to.contain('disabled');
Expand All @@ -43,7 +38,7 @@ const editItemLoginSetting = (mode: string) => {
cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID}`).click();
cy.get(`li[data-value="${mode}"]`).click();
cy.wait('@putItemLoginSchema').then(({ request: { body } }) => {
expect(body?.type).to.equal(ItemLoginSchemaType.UsernameAndPassword);
expect(body?.type).to.equal(mode);
});
};

Expand Down Expand Up @@ -76,7 +71,6 @@ describe('Item Login', () => {
cy.get(`#${buildShareButtonId(item.id)}`).click();

checkItemLoginSetting({
isEnabled: true,
mode: ItemLoginSchemaType.Username,
});
editItemLoginSetting(ItemLoginSchemaType.UsernameAndPassword);
Expand All @@ -85,7 +79,6 @@ describe('Item Login', () => {
cy.visit(buildItemPath(child.id));
cy.get(`#${buildShareButtonId(child.id)}`).click();
checkItemLoginSetting({
isEnabled: true,
mode: ItemLoginSchemaType.UsernameAndPassword,
disabled: true,
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/item/authorization/itemLogin/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ItemLoginSchemaType, PackedItem } from '@graasp/sdk';
import { ItemLoginSchema, ItemLoginSchemaType, PackedItem } from '@graasp/sdk';

import { v4 } from 'uuid';

export const addItemLoginSchema = (
item: PackedItem,
itemLoginSchemaType: ItemLoginSchemaType,
) => ({
): PackedItem & { itemLoginSchema: ItemLoginSchema } => ({
...item,
itemLoginSchema: {
item,
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/memberships/membershipRequestTable.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const membershipRequests = [
];

describe('Membership requests table', () => {
it.only('Writers cannot see', () => {
it('Writers cannot see', () => {
const itemWithWrite = PackedFolderItemFactory(
{ creator: CURRENT_USER },
{ permission: PermissionLevel.Write },
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Membership requests table', () => {
expect(body.permission).to.equal(PermissionLevel.Read);
});
});
it('reject membership requests', () => {
it.only('reject membership requests', () => {
const { member } = membershipRequests[0];

cy.get(
Expand Down
13 changes: 8 additions & 5 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
App,
Category,
ChatMention,
CompleteMembershipRequest,
DiscriminatedItem,
HttpMethod,
Invitation,
Expand Down Expand Up @@ -2286,13 +2287,13 @@ export const mockGetLinkMetadata = (): void => {

export const mockGetOwnMembershipRequests = (
currentMember: Member,
membershipRequests,
membershipRequests: CompleteMembershipRequest[],
): void => {
cy.intercept(
{
method: HttpMethod.Get,
url: new RegExp(
`${API_HOST}/items/${ID_FORMAT}/memberships/requests/own`,
`${API_HOST}/items/${ID_FORMAT}/memberships/requests/own$`,
),
},
({ reply, url }) => {
Expand All @@ -2312,17 +2313,19 @@ export const mockRequestMembership = (): void => {
cy.intercept(
{
method: HttpMethod.Post,
url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships/requests`),
url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships/requests$`),
},
({ reply }) => reply({ statusCode: StatusCodes.OK }),
).as('requestMembership');
};

export const mockGetMembershipRequestsForItem = (membershipRequests): void => {
export const mockGetMembershipRequestsForItem = (
membershipRequests: CompleteMembershipRequest[],
): void => {
cy.intercept(
{
method: HttpMethod.Get,
url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships/requests`),
url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships/requests$`),
},
({ reply, url }) => {
const urlParams = url.split('/');
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ChatMention,
ChatMessage,
CompleteMember,
CompleteMembershipRequest,
DiscriminatedItem,
Invitation,
ItemBookmark,
Expand All @@ -20,7 +21,6 @@ import {
ShortLink,
} from '@graasp/sdk';

// TODO: not the best way, to change with mirage?
export type ItemForTest = DiscriminatedItem & {
categories?: ItemCategory[];
thumbnails?: string;
Expand All @@ -35,7 +35,6 @@ export type ItemForTest = DiscriminatedItem & {
public?: ItemTag;
};

// TODO: not ideal, to change?
export type MemberForTest = CompleteMember & { thumbnails?: string };

export type LocalFileItemForTest = LocalFileItemType & {
Expand All @@ -61,6 +60,7 @@ export type ApiConfig = {
recycledItemData?: RecycledItemData[];
itemPublicationStatus?: PublicationStatus;
publishedItemData?: ItemPublished[];
membershipRequests?: CompleteMembershipRequest[];
// statuses = SAMPLE_STATUSES,
itemValidationGroups?: ItemValidationGroup[];
deleteItemsError?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import ImportUsersDialogContent, {
DIALOG_ID_LABEL,
} from './ImportUsersDialogContent';

type ImportUsersWithCSVButtonProps = {
type ImportUsersWithCSVDialogProps = {
item: DiscriminatedItem;
handleCloseModal: () => void;
open: boolean;
};

const ImportUsersWithCSVButton = ({
const ImportUsersWithCSVDialog = ({
item,
handleCloseModal,
open,
}: ImportUsersWithCSVButtonProps): JSX.Element => (
}: ImportUsersWithCSVDialogProps): JSX.Element => (
<Dialog
scroll="paper"
onClose={handleCloseModal}
Expand All @@ -30,4 +30,4 @@ const ImportUsersWithCSVButton = ({
/>
</Dialog>
);
export default ImportUsersWithCSVButton;
export default ImportUsersWithCSVDialog;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { Trans } from 'react-i18next';

import {
Dialog,
Expand All @@ -14,6 +15,7 @@ import { COMMON } from '@graasp/translations';
import { Button, EditButton } from '@graasp/ui';

import useModalStatus from '@/components/hooks/useModalStatus';
import { BUILDER } from '@/langs/constants';

import {
useBuilderTranslation,
Expand Down Expand Up @@ -51,34 +53,43 @@ const EditPermissionButton = ({

return (
<>
<EditButton
id={id}
onClick={() => {
openModal();
}}
/>
<EditButton id={id} onClick={() => openModal()} />
<Dialog onClose={closeModal} open={isOpen}>
<DialogTitle>
Update <strong>{name || email}</strong> s permission
<Trans
t={translateBuilder}
i18nKey={BUILDER.EDIT_PERMISSION_DIALOG_TITLE}
values={{
name: name || email,
}}
components={{ 1: <strong /> }}
/>
</DialogTitle>
<DialogContent>
<Stack spacing={1}>
<Typography variant="body1">
{translateBuilder(
'Cannot downgrade permission if defined above.',
BUILDER.EDIT_PERMISSION_CANNOT_DOWNGRADE_FROM_PARENT,
)}
</Typography>
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
>
{name ?? email}
<div>
<Typography noWrap fontWeight="bold">
{name}
</Typography>
<Typography noWrap variant="subtitle2">
{email}
</Typography>
</div>
<ItemMembershipSelect
value={currentPermission}
onChange={(e) => {
setCurrentPermission(e.target.value as PermissionLevel);
}}
onChange={(e) =>
setCurrentPermission(e.target.value as PermissionLevel)
}
size="medium"
allowDowngrade={allowDowngrade}
/>
Expand All @@ -96,7 +107,7 @@ const EditPermissionButton = ({
closeModal();
}}
>
{translateBuilder('Update')}
{translateBuilder(BUILDER.EDIT_PERMISSION_DIALOG_SUBMIT_BUTTON)}
</Button>
</DialogActions>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { TableCell, TableRow, Typography } from '@mui/material';
import { TableCell, Typography } from '@mui/material';

import { DiscriminatedItem, ItemMembership } from '@graasp/sdk';

import { useEnumsTranslation } from '@/config/i18n';

import { buildItemMembershipRowId } from '../../../../config/selectors';
import DeleteItemMembershipButton from './DeleteItemMembershipButton';
import { StyledTableRow } from './StyledTableRow';

const GuestItemMembershipTableRow = ({
data,
Expand All @@ -17,13 +18,7 @@ const GuestItemMembershipTableRow = ({
const { t: translateEnums } = useEnumsTranslation();

return (
<TableRow
data-cy={buildItemMembershipRowId(data.id)}
key={data.id}
sx={{
'&:last-child td, &:last-child th': { border: 0 },
}}
>
<StyledTableRow data-cy={buildItemMembershipRowId(data.id)} key={data.id}>
<TableCell>
<Typography noWrap fontWeight="bold">
{data.account.name}
Expand All @@ -35,7 +30,7 @@ const GuestItemMembershipTableRow = ({
<TableCell align="right">
<DeleteItemMembershipButton itemId={itemId} data={data} />
</TableCell>
</TableRow>
</StyledTableRow>
);
};

Expand Down
Loading

0 comments on commit 8898158

Please sign in to comment.