Skip to content

Commit

Permalink
fix: typeorm fixes (#86)
Browse files Browse the repository at this point in the history
* fix: typeorm fixes

* fix: types in tests

* fix: tests once more

* fix: message body type

* fix: spread messages and use type from sdk

* fix: use latest immutable version

* chore: fix message type

* chore: bump dependencies

* refactor: fix chatbox

* refactor: fix i18next deps

* refactor: remove useMembers hook

* refactor: update mention type

* refactor: fix issues

* fix: do not send mentions

* fix: test and fixture data

---------

Co-authored-by: pyphilia <[email protected]>
Release-As: v2.0.0-rc.1
  • Loading branch information
spaenleh and pyphilia authored May 31, 2023
1 parent 2c82a72 commit 84f4e38
Show file tree
Hide file tree
Showing 26 changed files with 1,675 additions and 1,644 deletions.
3 changes: 1 addition & 2 deletions cypress/components/mention-button.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
mentionButtonCypress,
} from '../../src/config/selectors';
import { spyMethod } from '../fixtures/chat_messages';
import { mockUseMembers, mockUseMentions } from '../fixtures/mockHooks';
import { mockUseMentions } from '../fixtures/mockHooks';

describe('Mention Button', () => {
it('should show mention button', () => {
Expand All @@ -22,7 +22,6 @@ describe('Mention Button', () => {
deleteMentionFunction={deleteMentionSpy}
patchMentionFunction={patchMentionSpy}
useMentions={mockUseMentions}
useMembers={mockUseMembers}
/>,
).then(() => {
cy.get(dataCyWrapper(mentionButtonCypress)).should('exist').click();
Expand Down
2 changes: 1 addition & 1 deletion cypress/components/mention-parsing.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Mention Highlighting', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs([annaMessage, allMessage])}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
cy.get(dataCyWrapper(messageIdCyWrapper(annaMessage.id))).should(
Expand Down
10 changes: 5 additions & 5 deletions cypress/components/message-actions.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Message actions', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
});
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Delete action', () => {
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
deleteMessageFunction={deleteMessageSpy}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
cy.get(dataCyWrapper(messageActionsButtonCypress))
Expand All @@ -84,7 +84,7 @@ describe('Edit action', () => {
messages={convertJs(CHAT_MESSAGES)}
editMessageFunction={editMessageSpy}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);

Expand Down Expand Up @@ -131,7 +131,7 @@ describe('Edit action', () => {
const secondMessageIndex = 1;
cy.get(dataCyWrapper(editBannerOldTextCypress)).should(
'contain.text',
CHAT_MESSAGES.filter((m) => m.creator === CURRENT_MEMBER.id)[
CHAT_MESSAGES.filter((m) => m.creator?.id === CURRENT_MEMBER.id)[
firstMessageIndex
].body,
);
Expand All @@ -140,7 +140,7 @@ describe('Edit action', () => {
.click();
cy.get(dataCyWrapper(editMenuItemCypress)).click();
const oldTextMessage = CHAT_MESSAGES.filter(
(m) => m.creator === CURRENT_MEMBER.id,
(m) => m.creator?.id === CURRENT_MEMBER.id,
)[secondMessageIndex].body;
cy.get(dataCyWrapper(editBannerOldTextCypress)).should(
'contain.text',
Expand Down
12 changes: 6 additions & 6 deletions cypress/components/render-ui.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// <reference types="../support/cypress" />
import { v4 } from 'uuid';

import React from 'react';

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

import { v4 } from 'uuid';

import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
dataCyWrapper,
Expand All @@ -29,7 +29,7 @@ describe('Render Avatar', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
});
Expand All @@ -42,7 +42,7 @@ describe('Render Avatar', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
cy.get(`@${fakeHookName}`).should('have.been.called');
Expand All @@ -58,7 +58,7 @@ describe('Autofocus input field', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={convertJs(Object.values(MEMBERS))}
messages={convertJs(CHAT_MESSAGES)}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
).then(() =>
cy.get(`#${inputTextFieldTextAreaCypress}`).should('be.focused'),
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Messages container', () => {
id: lastId,
},
])}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
).then(() => {
cy.get(dataCyWrapper(messageIdCyWrapper(lastId))).should('be.visible');
Expand Down
12 changes: 6 additions & 6 deletions cypress/components/send-message.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// <reference types="../support/cypress"/>
import { List } from 'immutable';

import React from 'react';

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

import { List } from 'immutable';

import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
charCounterCypress,
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('Enter text', () => {
currentMember={convertJs(MEMBERS.ANNA)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
});
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('Send message', () => {
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
cy.get(dataCyWrapper(inputTextFieldCypress)).type(inputText);
Expand All @@ -86,7 +86,7 @@ describe('Send message', () => {
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
cy.get(dataCyWrapper(inputTextFieldCypress))
Expand All @@ -108,7 +108,7 @@ describe('Message Length', () => {
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
useAvatarUrl={fakeHook}
/>,
);
});
Expand Down
62 changes: 40 additions & 22 deletions cypress/fixtures/chat_messages.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
import {
ChatMessage,
FolderItemType,
ItemType,
buildPathFromIds,
} from '@graasp/sdk';

import { v4 } from 'uuid';

import { getMentionMarkupFromMember } from '../../src';
import { ChatMessage } from '../../src/types';
import { CURRENT_MEMBER, MEMBERS } from './members';

export const CHAT_ID = v4();
export const ITEM_CHAT: FolderItemType = {
id: CHAT_ID,
name: 'Item chat',
description: 'A description',
path: buildPathFromIds(CHAT_ID),
type: ItemType.FOLDER,
extra: { [ItemType.FOLDER]: { childrenOrder: [] } },
settings: {},
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
};
export const MOCK_MESSAGE_BODY = 'This is a message';

export const getMockMessage = ({
member = CURRENT_MEMBER,
message = MOCK_MESSAGE_BODY,
}): ChatMessage => ({
id: v4(),
chatId: CHAT_ID,
creator: member.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
item: ITEM_CHAT,
creator: member,
createdAt: new Date(),
updatedAt: new Date(),
body: message,
});

export const CHAT_MESSAGES = [
export const CHAT_MESSAGES: ChatMessage[] = [
{
id: v4(),
chatId: CHAT_ID,
creator: CURRENT_MEMBER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
item: ITEM_CHAT,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
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(),
chatId: CHAT_ID,
creator: MEMBERS.BOB.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
item: ITEM_CHAT,
creator: MEMBERS.BOB,
createdAt: new Date(),
updatedAt: new Date(),
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(),
chatId: CHAT_ID,
creator: MEMBERS.BOB.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
item: ITEM_CHAT,
creator: MEMBERS.BOB,
createdAt: new Date(),
updatedAt: new Date(),
body: 'And here a text with 2\n\nLine breaks',
},
{
id: v4(),
chatId: CHAT_ID,
creator: CURRENT_MEMBER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
item: ITEM_CHAT,
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
body: 'Message',
},
];
Expand Down
16 changes: 16 additions & 0 deletions cypress/fixtures/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Item, ItemType } from '@graasp/sdk';

import { CURRENT_MEMBER } from './members';

export const MOCK_ITEM: Item = {
id: 'some-id',
name: 'my mock item',
description: 'a description',
path: 'some-id',
settings: {},
creator: CURRENT_MEMBER,
createdAt: new Date(),
updatedAt: new Date(),
type: ItemType.FOLDER,
extra: {},
};
Loading

0 comments on commit 84f4e38

Please sign in to comment.