Skip to content

Commit

Permalink
MM-59373: Respecting name display preference in boards (#22)
Browse files Browse the repository at this point in the history
* MM-59373: Respecting name display preference in boards

* clean up

* removed unwanted code

* refactor: fix this type for global PostUtil

* chore

* type fix

* create mock store for mm

* added the missing flag to focus fetch the missing users

* updated test and snapshots

* mocking messageHtmlToComponent at global level
  • Loading branch information
Rajat-Dabade authored Nov 8, 2024
1 parent 62db52c commit 957a8f2
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 63 deletions.
3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"collectCoverageFrom": [
"src/**/*.{ts,tsx,js,jsx}",
"!src/test/**"
]
],
"setupFiles": ["./tests/setupFile.ts"]
},
"devDependencies": {
"@formatjs/cli": "^4.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ exports[`components/cardDetail/comment return comment 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down Expand Up @@ -246,11 +244,9 @@ exports[`components/cardDetail/comment return comment and delete comment 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down Expand Up @@ -285,11 +281,9 @@ exports[`components/cardDetail/comment return comment readonly 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down Expand Up @@ -422,11 +416,9 @@ exports[`components/cardDetail/comment return guest comment 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down Expand Up @@ -559,11 +551,9 @@ exports[`components/cardDetail/comment return guest comment and delete comment 1
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down Expand Up @@ -607,11 +597,9 @@ exports[`components/cardDetail/comment return guest comment readonly 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Test comment
</p>
Test Comment
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ exports[`components/cardDetail/CommentsList comments show up 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Comment 2
</p>
Test Comment
</div>
</div>
<div
Expand Down Expand Up @@ -111,11 +109,9 @@ exports[`components/cardDetail/CommentsList comments show up 1`] = `
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Comment 1
</p>
Test Comment
</div>
</div>
<hr
Expand Down Expand Up @@ -155,11 +151,9 @@ exports[`components/cardDetail/CommentsList comments show up in readonly mode 1`
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Comment 2
</p>
Test Comment
</div>
</div>
<div
Expand Down Expand Up @@ -187,11 +181,9 @@ exports[`components/cardDetail/CommentsList comments show up in readonly mode 1`
</div>
</div>
<div
class="comment-text"
class="mocked-message-html"
>
<p>
Comment 1
</p>
Test Comment
</div>
</div>
<hr
Expand Down
19 changes: 11 additions & 8 deletions webapp/src/components/cardDetail/cardDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import octoClient from '../../octoClient'

import {createTextBlock} from '../../blocks/textBlock'

import {mockMMStore} from '../../../tests/mock_window'

import CardDetail from './cardDetail'

global.fetch = FetchMock.fn
Expand All @@ -42,6 +44,7 @@ beforeAll(() => {
})

describe('components/cardDetail/CardDetail', () => {
(window as any).store = mockMMStore
const board = TestBlockFactory.createBoard()

const view = TestBlockFactory.createBoardView(board)
Expand Down Expand Up @@ -73,7 +76,7 @@ describe('components/cardDetail/CardDetail', () => {
},
},
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down Expand Up @@ -126,7 +129,7 @@ describe('components/cardDetail/CardDetail', () => {
expect(container).toBeDefined()

// Comments show up
const comments = container!.querySelectorAll('.comment-text')
const comments = container!.querySelectorAll('.mocked-message-html')
expect(comments.length).toBe(2)

// Add comment option visible when readonly mode is off
Expand All @@ -138,7 +141,7 @@ describe('components/cardDetail/CardDetail', () => {
const mockStore = configureStore([])
const store = mockStore({
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down Expand Up @@ -190,7 +193,7 @@ describe('components/cardDetail/CardDetail', () => {
expect(container).toBeDefined()

// comments show up
const comments = container!.querySelectorAll('.comment-text')
const comments = container!.querySelectorAll('.mocked-message-html')
expect(comments.length).toBe(2)

// Add comment option is not shown in readonly mode
Expand Down Expand Up @@ -223,7 +226,7 @@ describe('components/cardDetail/CardDetail', () => {
},
},
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down Expand Up @@ -330,7 +333,7 @@ describe('components/cardDetail/CardDetail', () => {
},
},
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down Expand Up @@ -435,7 +438,7 @@ describe('components/cardDetail/CardDetail', () => {
},
},
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down Expand Up @@ -533,7 +536,7 @@ describe('components/cardDetail/CardDetail', () => {
],
},
teams: {
current: {id: 'team-id'},
current: {id: 'team_id'},
},
boards: {
boards: {
Expand Down
48 changes: 45 additions & 3 deletions webapp/src/components/cardDetail/comment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {TestBlockFactory} from '../../test/testBlockFactory'

import mutator from '../../mutator'

import {mockMMStore} from '../../../tests/mock_window'

import Comment from './comment'

jest.mock('../../mutator')
Expand All @@ -30,10 +32,14 @@ comment.title = 'Test comment'
const userImageUrl = 'data:image/svg+xml'

describe('components/cardDetail/comment', () => {
(window as any).store = mockMMStore
const state = {
users: {
boardUsers: {[comment.modifiedBy]: {username: 'username_1'}},
},
teams: {
current: {id: 'team_id'},
},
}
const store = mockStateStore([], state)

Expand Down Expand Up @@ -101,7 +107,19 @@ describe('components/cardDetail/comment', () => {
})

test('return guest comment', () => {
const localStore = mockStateStore([], {users: {boardUsers: {[comment.modifiedBy]: {username: 'username_1', is_guest: true}}}})
const localStore = mockStateStore([], {
users: {
boardUsers: {
[comment.modifiedBy]: {
username: 'username_1',
is_guest: true
}
}
},
teams: {
current: {id: 'team_id'},
}
})
const {container} = render(wrapIntl(
<ReduxProvider store={localStore}>
<Comment
Expand All @@ -118,7 +136,19 @@ describe('components/cardDetail/comment', () => {
})

test('return guest comment readonly', () => {
const localStore = mockStateStore([], {users: {boardUsers: {[comment.modifiedBy]: {username: 'username_1', is_guest: true}}}})
const localStore = mockStateStore([], {
users: {
boardUsers: {
[comment.modifiedBy]: {
username: 'username_1',
is_guest: true
}
}
},
teams: {
current: {id: 'team_id'},
},
})
const {container} = render(wrapIntl(
<ReduxProvider store={localStore}>
<Comment
Expand All @@ -133,7 +163,19 @@ describe('components/cardDetail/comment', () => {
})

test('return guest comment and delete comment', () => {
const localStore = mockStateStore([], {users: {boardUsers: {[comment.modifiedBy]: {username: 'username_1', is_guest: true}}}})
const localStore = mockStateStore([], {
users: {
boardUsers: {
[comment.modifiedBy]: {
username: 'username_1',
is_guest: true
}
}
},
teams: {
current: {id: 'team_id'},
},
})
const {container} = render(wrapIntl(
<ReduxProvider store={localStore}>
<Comment
Expand Down
29 changes: 24 additions & 5 deletions webapp/src/components/cardDetail/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import React, {FC} from 'react'
import {useIntl} from 'react-intl'

import {getChannelsNameMapInTeam} from 'mattermost-redux/selectors/entities/channels'

import {Provider} from 'react-redux'

import {Block} from '../../blocks/block'
import mutator from '../../mutator'
import {Utils} from '../../utils'
Expand All @@ -17,6 +21,9 @@ import Tooltip from '../../widgets/tooltip'
import GuestBadge from '../../widgets/guestBadge'

import './comment.scss'
import {formatText, messageHtmlToComponent} from '../../webapp_globals'
import {getCurrentTeam} from '../../store/teams'


type Props = {
comment: Block
Expand All @@ -28,10 +35,25 @@ type Props = {
const Comment: FC<Props> = (props: Props) => {
const {comment, userId, userImageUrl} = props
const intl = useIntl()
const html = Utils.htmlFromMarkdown(comment.title)
const user = useAppSelector(getUser(userId))
const date = new Date(comment.createAt)

const selectedTeam = useAppSelector(getCurrentTeam)
const channelNamesMap = getChannelsNameMapInTeam((window as any).store.getState(), selectedTeam!.id)

const formattedText =
<Provider store={(window as any).store}>
{messageHtmlToComponent(formatText(comment.title, {
singleline: false,
atMentions: true,
mentionHighlight: false,
team: selectedTeam,
channelNamesMap,
}), {
fetchMissingUsers: true,
})}
</Provider>

return (
<div
key={comment.id}
Expand Down Expand Up @@ -65,10 +87,7 @@ const Comment: FC<Props> = (props: Props) => {
</MenuWrapper>
)}
</div>
<div
className='comment-text'
dangerouslySetInnerHTML={{__html: html}}
/>
{formattedText}
</div>
)
}
Expand Down
Loading

0 comments on commit 957a8f2

Please sign in to comment.