Skip to content

Commit

Permalink
feat!: remove immutable (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia authored Nov 3, 2023
1 parent 7134250 commit cb0eb86
Show file tree
Hide file tree
Showing 23 changed files with 2,837 additions and 577 deletions.
8 changes: 3 additions & 5 deletions cypress/components/mention-parsing.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference types="../support/cypress"/>
import React from 'react';

import { convertJs } from '@graasp/sdk';

import { LEGACY_MENTION_MARKUP, getMentionMarkupFromMember } from '../../src';
import Chatbox from '../../src/components/Chatbox/Chatbox';
import { dataCyWrapper, messageIdCyWrapper } from '../../src/config/selectors';
Expand All @@ -28,9 +26,9 @@ describe('Mention Highlighting', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs([annaMessage, allMessage])}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={[annaMessage, allMessage]}
useAvatarUrl={fakeHook}
/>,
);
Expand Down
20 changes: 9 additions & 11 deletions cypress/components/message-actions.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference types="../support/cypress" />
import React from 'react';

import { convertJs } from '@graasp/sdk';

import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
dataCyWrapper,
Expand All @@ -25,9 +23,9 @@ describe('Message actions', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
useAvatarUrl={fakeHook}
/>,
);
Expand All @@ -53,9 +51,9 @@ describe('Delete action', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
deleteMessageFunction={deleteMessageSpy}
useAvatarUrl={fakeHook}
/>,
Expand All @@ -79,9 +77,9 @@ describe('Edit action', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
editMessageFunction={editMessageSpy}
sendMessageFunction={sendMessageSpy}
useAvatarUrl={fakeHook}
Expand Down
28 changes: 13 additions & 15 deletions cypress/components/render-ui.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/// <reference types="../support/cypress" />
import React from 'react';

import { convertJs } from '@graasp/sdk';

import { v4 } from 'uuid';

import Chatbox from '../../src/components/Chatbox/Chatbox';
Expand All @@ -26,9 +24,9 @@ describe('Render Avatar', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
useAvatarUrl={fakeHook}
/>,
);
Expand All @@ -39,9 +37,9 @@ describe('Render Avatar', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
useAvatarUrl={fakeHook}
/>,
);
Expand All @@ -55,9 +53,9 @@ describe('Autofocus input field', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
useAvatarUrl={fakeHook}
/>,
).then(() =>
Expand All @@ -74,9 +72,9 @@ describe('Messages container', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs([
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={[
{
...CHAT_MESSAGES[0],
id: firstId,
Expand All @@ -93,7 +91,7 @@ describe('Messages container', () => {
...CHAT_MESSAGES[0],
id: lastId,
},
])}
]}
useAvatarUrl={fakeHook}
/>,
).then(() => {
Expand Down
28 changes: 12 additions & 16 deletions cypress/components/send-message.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/// <reference types="../support/cypress"/>
import React from 'react';

import { convertJs } from '@graasp/sdk';

import { List } from 'immutable';

import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
charCounterCypress,
Expand All @@ -30,9 +26,9 @@ describe('Enter text', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
useAvatarUrl={fakeHook}
/>,
);
Expand Down Expand Up @@ -63,9 +59,9 @@ describe('Send message', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
sendMessageFunction={sendMessageSpy}
useAvatarUrl={fakeHook}
/>,
Expand All @@ -82,9 +78,9 @@ describe('Send message', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
sendMessageFunction={sendMessageSpy}
useAvatarUrl={fakeHook}
/>,
Expand All @@ -104,9 +100,9 @@ describe('Message Length', () => {
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={convertJs(MEMBERS.ANNA)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
currentMember={MEMBERS.ANNA}
members={Object.values(MEMBERS)}
messages={CHAT_MESSAGES}
sendMessageFunction={sendMessageSpy}
useAvatarUrl={fakeHook}
/>,
Expand Down
24 changes: 12 additions & 12 deletions cypress/fixtures/chat_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const ITEM_CHAT: FolderItemType = {
extra: { [ItemType.FOLDER]: { childrenOrder: [] } },
settings: {},
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
export const MOCK_MESSAGE_BODY = 'This is a message';

Expand All @@ -32,8 +32,8 @@ export const getMockMessage = ({
id: v4(),
item: ITEM_CHAT,
creator: member,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
body: message,
});

Expand All @@ -42,32 +42,32 @@ export const CHAT_MESSAGES: ChatMessage[] = [
id: v4(),
item: ITEM_CHAT,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
body: 'Some really long text that is going to be wrapped to the next line i think, we need to test.\nOn multiple lines',
},
{
id: v4(),
item: ITEM_CHAT,
creator: MEMBERS.BOB,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
body: 'A lengthy response to the previous message that i think a lot of people will like to read, since it really goes in deep into the topic.\nAnd here also a preview of the next topic.\n\nSigned Bob',
},
{
id: v4(),
item: ITEM_CHAT,
creator: MEMBERS.BOB,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
body: 'And here a text with 2\n\nLine breaks',
},
{
id: v4(),
item: ITEM_CHAT,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
body: 'Message',
},
];
Expand Down
12 changes: 7 additions & 5 deletions cypress/fixtures/item.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Item, ItemType } from '@graasp/sdk';
import { DiscriminatedItem, ItemType } from '@graasp/sdk';

import { CURRENT_MEMBER } from './members';

export const MOCK_ITEM: Item = {
export const MOCK_ITEM: DiscriminatedItem = {
id: 'some-id',
name: 'my mock item',
description: 'a description',
path: 'some-id',
settings: {},
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
type: ItemType.FOLDER,
extra: {},
extra: {
folder: { childrenOrder: [] },
},
};
11 changes: 1 addition & 10 deletions cypress/fixtures/members.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { Member, MemberType } from '@graasp/sdk';
import { Member } from '@graasp/sdk';

const dateNow = new Date().toISOString();
export const MEMBERS: { [key: string]: Member } = {
ANNA: {
id: '0f0a2774-a965-4b97-afb4-bccc3796e060',
name: 'anna',
email: '[email protected]',
type: MemberType.Individual,
extra: {},
createdAt: dateNow,
updatedAt: dateNow,
},
BOB: {
id: '1f0a2774-a965-4b97-afb4-bccc3796e060',
name: 'bob',
email: '[email protected]',
type: MemberType.Individual,
extra: {},
createdAt: dateNow,
updatedAt: dateNow,
},
};

Expand Down
25 changes: 9 additions & 16 deletions cypress/fixtures/mockHooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/// <reference types="../cypress"/>
import { QueryObserverResult } from 'react-query';

import { ChatMention, MentionStatus, convertJs } from '@graasp/sdk';
import { ChatMentionRecord } from '@graasp/sdk/frontend';
import { ChatMention, ChatMessage, MentionStatus } from '@graasp/sdk';

import { List } from 'immutable';
import { v4 } from 'uuid';

import { CHAT_MESSAGES } from './chat_messages';
Expand All @@ -31,23 +29,21 @@ export const mockUseAvatar = (): SpyHookType => ({
name: USE_AVATAR_HOOK_NAME,
});

export const mockUseMentions = (): QueryObserverResult<
List<ChatMentionRecord>
> => {
const defaultMessage = {
export const mockUseMentions = (): QueryObserverResult<ChatMention[]> => {
const defaultMessage: ChatMessage = {
id: v4(),
item: MOCK_ITEM,
creator: MEMBERS.BOB,
body: 'some message',
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
const defaultMention: ChatMention = {
id: '',
message: defaultMessage,
member: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
status: MentionStatus.Unread,
};

Expand All @@ -66,11 +62,8 @@ export const mockUseMentions = (): QueryObserverResult<
},
};

const MEMBER_MENTIONS: List<ChatMentionRecord> = convertJs([
CHAT_MENTION_1,
CHAT_MENTION_2,
]);
const MEMBER_MENTIONS: ChatMention[] = [CHAT_MENTION_1, CHAT_MENTION_2];
return {
data: MEMBER_MENTIONS,
} as unknown as QueryObserverResult<List<ChatMentionRecord>>;
} as unknown as QueryObserverResult<ChatMention[]>;
};
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
},
"dependencies": {
"@graasp/chatbox": "link:..",
"@graasp/query-client": "1.1.4",
"@graasp/query-client": "2.0.0",
"@graasp/sdk": "2.0.0",
"@mui/icons-material": "link:../node_modules/@mui/icons-material",
"@mui/material": "link:../node_modules/@mui/material",
"immutable": "link:../node_modules/immutable",
"react-scripts": "5.0.1",
"typescript": "5.1.6"
},
Expand Down
Loading

0 comments on commit cb0eb86

Please sign in to comment.