Skip to content

Commit

Permalink
feat: update to mui5
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Oct 12, 2022
1 parent a746be1 commit 3a16dbc
Show file tree
Hide file tree
Showing 28 changed files with 1,707 additions and 1,569 deletions.
8 changes: 7 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"importOrder": ["^@(?!graasp|material)(.*)", "^react", "^@?material(.*)", "^@?graasp(.*)", "^[./]"],
"importOrder": [
"^@(?!graasp|mui)(.*)",
"^react",
"^@?mui(.*)",
"^@?graasp(.*)",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
10 changes: 10 additions & 0 deletions cypress/fixtures/chat_messages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { v4 } from 'uuid';

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

export const CHAT_ID = v4();

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

export const CHAT_MESSAGES = [
{
id: v4(),
Expand Down
27 changes: 19 additions & 8 deletions cypress/integration/message-actions.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/// <reference types="./cypress"/>
/// <reference types="../cypress"/>
import { List } from 'immutable';

import { ImmutableMember, Member } from '../../src';
import React from 'react';

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

import { ImmutableMember } from '../../src';
import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
dataCyWrapper,
Expand All @@ -16,15 +20,18 @@ import {
import { SIDE_PANE_HEIGHT, SIDE_PANE_WIDTH } from '../../src/constants';
import { CHAT_ID, CHAT_MESSAGES, spyMethod } from '../fixtures/chat_messages';
import { CURRENT_MEMBER, MEMBERS } from '../fixtures/members';
import { mockUseAvatar } from '../fixtures/mockHooks';

describe('Message actions', () => {
beforeEach(() => {
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
/>,
);
});
Expand All @@ -45,13 +52,15 @@ describe('Message actions', () => {
describe('Delete action', () => {
it('should delete message', () => {
const deleteMessageSpy = spyMethod('spyMethod');
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
deleteMessageFunction={deleteMessageSpy}
useAvatarHook={fakeHook}
/>,
);
cy.get(dataCyWrapper(messageActionsButtonCypress))
Expand All @@ -69,14 +78,16 @@ describe('Edit action', () => {
cy.viewport(SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT);
const editMessageSpy = spyMethod('editSpyMethod');
const sendMessageSpy = spyMethod('sendSpyMethod');
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
editMessageFunction={editMessageSpy}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
/>,
);

Expand Down
66 changes: 43 additions & 23 deletions cypress/integration/render-ui.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@
import { List } from 'immutable';
import { v4 } from 'uuid';

import { ImmutableMember, Member } from '../../src';
import React from 'react';

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

import { ImmutableMember } from '../../src';
import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
dataCyWrapper,
inputTextFieldTextAreaCypress,
messageIdCyWrapper,
messagesContainerCypress,
} from '../../src/config/selectors';
import { CHAT_ID, CHAT_MESSAGES } from '../fixtures/chat_messages';
import {
CHAT_ID,
CHAT_MESSAGES,
getMockMessage,
} from '../fixtures/chat_messages';
import { MEMBERS } from '../fixtures/members';
import { mockUseAvatar } from '../fixtures/mockHooks';

describe('Render Avatar', () => {
beforeEach(() => {
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
/>,
);
});
Expand All @@ -32,8 +42,8 @@ describe('Render Avatar', () => {
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
/>,
);
Expand All @@ -43,12 +53,14 @@ describe('Render Avatar', () => {

describe('Autofocus input field', () => {
it('should autofocus input field on first render', () => {
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
/>,
).then(() =>
cy.get(`#${inputTextFieldTextAreaCypress}`).should('be.focused'),
Expand All @@ -58,27 +70,35 @@ describe('Autofocus input field', () => {

describe('Messages container', () => {
it('should scroll when there are a lot of messages', () => {
const { hook: fakeHook } = mockUseAvatar();
const firstId = v4();
const lastId = v4();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List([
{
...CHAT_MESSAGES[0],
id: firstId,
},
...CHAT_MESSAGES,
...CHAT_MESSAGES,
...CHAT_MESSAGES,
...CHAT_MESSAGES,
{
...CHAT_MESSAGES[0],
id: lastId,
},
])}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(
convertJs([
{
...CHAT_MESSAGES[0],
id: firstId,
},
getMockMessage({ member: MEMBERS.ANNA }),
getMockMessage({ member: MEMBERS.BOB }),
getMockMessage({ member: MEMBERS.ANNA }),
getMockMessage({ member: MEMBERS.ANNA }),
getMockMessage({ member: MEMBERS.BOB }),
getMockMessage({ member: MEMBERS.BOB }),
getMockMessage({ member: MEMBERS.ANNA }),
getMockMessage({ member: MEMBERS.ANNA }),
{
...CHAT_MESSAGES[0],
id: lastId,
},
]),
)}
useAvatarHook={fakeHook}
/>,
).then(() => {
cy.get(dataCyWrapper(messageIdCyWrapper(lastId))).should('be.visible');
Expand Down
33 changes: 23 additions & 10 deletions cypress/integration/send-message.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/// <reference types="./cypress"/>
/// <reference types="../cypress"/>
import { List } from 'immutable';

import { ImmutableMember, Member } from '../../src';
import React from 'react';

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

import { ImmutableMember } from '../../src';
import Chatbox from '../../src/components/Chatbox/Chatbox';
import {
charCounterCypress,
Expand All @@ -19,15 +23,18 @@ import {
spyMethod,
} from '../fixtures/chat_messages';
import { MEMBERS } from '../fixtures/members';
import { mockUseAvatar } from '../fixtures/mockHooks';

describe('Enter text', () => {
beforeEach(() => {
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
useAvatarHook={fakeHook}
/>,
);
});
Expand All @@ -53,13 +60,15 @@ describe('Send message', () => {
it('should send a message with click', () => {
const inputText = 'Hello there';
const sendMessageSpy = spyMethod('spyMethod');
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
/>,
);
cy.get(dataCyWrapper(inputTextFieldCypress)).type(inputText);
Expand All @@ -70,13 +79,15 @@ describe('Send message', () => {
it('should send a message with enter', function () {
const inputText = 'Hello there';
const sendMessageSpy = spyMethod('spyMethod');
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
/>,
);
cy.get(dataCyWrapper(inputTextFieldCypress))
Expand All @@ -90,13 +101,15 @@ describe('Message Length', () => {
let sendMessageSpy;
beforeEach(() => {
sendMessageSpy = spyMethod('spyMethod');
const { hook: fakeHook } = mockUseAvatar();
cy.mount(
<Chatbox
chatId={CHAT_ID}
currentMember={new ImmutableMember(MEMBERS.ANNA)}
members={List(Object.values(MEMBERS) as Member[])}
messages={List(CHAT_MESSAGES)}
members={List(convertJs(Object.values(MEMBERS)))}
messages={List(convertJs(CHAT_MESSAGES))}
sendMessageFunction={sendMessageSpy}
useAvatarHook={fakeHook}
/>,
);
});
Expand Down
16 changes: 15 additions & 1 deletion cypress/support/component.ts → cypress/support/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
// require('./commands')
import { mount } from 'cypress/react';

import React from 'react';

import { CssBaseline } from '@mui/material';
import { ThemeProvider, createTheme } from '@mui/material/styles';

import './commands';

// Augment the Cypress namespace to include type definitions for
Expand All @@ -31,7 +36,16 @@ declare global {
}
}

Cypress.Commands.add('mount', mount);
Cypress.Commands.add('mount', (component) => {
const theme = createTheme();
const wrapped = (
<ThemeProvider theme={theme}>
<CssBaseline />
{component}
</ThemeProvider>
);
return mount(wrapped);
});

// Example use:
// cy.mount(<MyComponent />)
7 changes: 3 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
},
"dependencies": {
"@graasp/chatbox": "link:..",
"@graasp/query-client": "github:graasp/graasp-query-client#202/exportChatHook",
"@material-ui/core": "4.12.4",
"@material-ui/icons": "4.11.2",
"@material-ui/lab": "4.0.0-alpha.60",
"@graasp/query-client": "github:graasp/graasp-query-client",
"@mui/icons-material": "5.10.9",
"@mui/material": "5.10.9",
"@testing-library/jest-dom": "link:../node_modules/@testing-library/jest-dom",
"@testing-library/react": "link:../node_modules/@testing-library/react",
"@testing-library/user-event": "link:../node_modules/@testing-library/user-event",
Expand Down
Loading

0 comments on commit 3a16dbc

Please sign in to comment.