-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add tests for html caption
- Loading branch information
Showing
5 changed files
with
311 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/script/components/MessagesList/Message/MemberMessage/MessageContent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2021 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {render} from '@testing-library/react'; | ||
|
||
import en from 'I18n/en-US.json'; | ||
import {MemberMessage as MemberMessageEntity} from 'src/script/entity/message/MemberMessage'; | ||
import {User} from 'src/script/entity/User'; | ||
import {SystemMessageType} from 'src/script/message/SystemMessageType'; | ||
import {generateUser} from 'test/helper/UserGenerator'; | ||
import {setStrings} from 'Util/LocalizerUtil'; | ||
|
||
import {config, MessageContent} from './MessageContent'; | ||
|
||
setStrings({en}); | ||
|
||
function createMemberMessage(type: SystemMessageType, users: User[]) { | ||
const message = new MemberMessageEntity(); | ||
message.memberMessageType = type; | ||
message.userIds(users.map(user => user.qualifiedId)); | ||
message.userEntities(users); | ||
message.name('message'); | ||
|
||
return message; | ||
} | ||
|
||
describe('MessageContent', () => { | ||
describe('CONVERSATION_CREATE', () => { | ||
it('displays participants of a newly created conversation', () => { | ||
const nbUsers = Math.floor(Math.random() * 10); | ||
const users = Array.from({length: nbUsers}, () => generateUser()); | ||
const message = createMemberMessage(SystemMessageType.CONVERSATION_CREATE, users); | ||
|
||
const {getByText} = render(<MessageContent message={message} />); | ||
users.forEach(user => { | ||
expect(getByText(user.name())).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
it('displays a showMore when there are more than 17 users', () => { | ||
const nbExtraUsers = Math.floor(Math.random() * 10); | ||
const nbUsers = config.MAX_USERS_VISIBLE + nbExtraUsers; | ||
|
||
const users = Array.from({length: nbUsers}, () => generateUser()); | ||
const message = createMemberMessage(SystemMessageType.CONVERSATION_CREATE, users); | ||
|
||
const {getByText} = render(<MessageContent message={message} />); | ||
expect(getByText(`${nbUsers - config.REDUCED_USERS_COUNT} more`)).not.toBeNull(); | ||
}); | ||
|
||
it('displays all team members', () => { | ||
const nbExtraUsers = Math.floor(Math.random() * 10); | ||
const nbTeamUsers = config.MAX_WHOLE_TEAM_USERS_VISIBLE + nbExtraUsers; | ||
|
||
const teamUsers = Array.from({length: nbTeamUsers}, () => generateUser()); | ||
const message = createMemberMessage(SystemMessageType.CONVERSATION_CREATE, teamUsers); | ||
message.allTeamMembers = teamUsers; | ||
|
||
const {getByText} = render(<MessageContent message={message} />); | ||
expect(getByText(`all team members`)).not.toBeNull(); | ||
}); | ||
|
||
it('displays all team members and one guest message', () => { | ||
const nbExtraUsers = Math.floor(Math.random() * 10); | ||
const nbTeamUsers = config.MAX_WHOLE_TEAM_USERS_VISIBLE + nbExtraUsers; | ||
|
||
const teamUsers = Array.from({length: nbTeamUsers}, () => generateUser()); | ||
const guest = generateUser(); | ||
guest.isGuest(true); | ||
const message = createMemberMessage(SystemMessageType.CONVERSATION_CREATE, [...teamUsers, guest]); | ||
message.allTeamMembers = teamUsers; | ||
|
||
const {getByText} = render(<MessageContent message={message} />); | ||
expect(getByText(`all team members and one guest`)).not.toBeNull(); | ||
}); | ||
|
||
it('displays all team members and multiple guests message', () => { | ||
const nbGuests = 2 + Math.floor(Math.random() * 10); | ||
const nbTeamUsers = config.MAX_WHOLE_TEAM_USERS_VISIBLE; | ||
|
||
const teamUsers = Array.from({length: nbTeamUsers}, () => generateUser()); | ||
const guests = Array.from({length: nbGuests}, () => { | ||
const guest = generateUser(); | ||
guest.isGuest(true); | ||
return guest; | ||
}); | ||
const message = createMemberMessage(SystemMessageType.CONVERSATION_CREATE, [...teamUsers, ...guests]); | ||
message.allTeamMembers = teamUsers; | ||
|
||
const {getByText} = render(<MessageContent message={message} />); | ||
expect(getByText(`all team members and ${nbGuests} guests`)).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.