-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-60405] Crossteam search #8411
base: main
Are you sure you want to change the base?
Changes from all commits
88f35d6
76a710c
1961251
79c72ad
8fad4b4
199f9a9
7507ceb
b59c05a
9a9e341
fa204a4
de166ad
e650f51
77f5ab0
ba34d8e
7ed6dd8
220a9d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
|
||
import {fireEvent, renderWithEverything} from '@test/intl-test-helper'; | ||
import TestHelper from '@test/test_helper'; | ||
|
||
import TeamList from './index'; | ||
|
||
import type Database from '@nozbe/watermelondb/Database'; | ||
import type TeamModel from '@typings/database/models/servers/team'; | ||
|
||
describe('TeamList', () => { | ||
let database: Database; | ||
beforeAll(async () => { | ||
const server = await TestHelper.setupServerDatabase(); | ||
database = server.database; | ||
}); | ||
const teams = [ | ||
{id: 'team1', displayName: 'Team 1'} as TeamModel, | ||
{id: 'team2', displayName: 'Team 2'} as TeamModel, | ||
]; | ||
|
||
it('should call onPress when a team is pressed', () => { | ||
const onPress = jest.fn(); | ||
const {getByText} = renderWithEverything( | ||
<TeamList | ||
teams={teams} | ||
onPress={onPress} | ||
/>, | ||
{database}, | ||
); | ||
fireEvent.press(getByText('Team 1')); | ||
expect(onPress).toHaveBeenCalledWith('team1'); | ||
}); | ||
|
||
it('should render loading component when loading is true', () => { | ||
const {getByTestId} = renderWithEverything( | ||
<TeamList | ||
teams={teams} | ||
onPress={jest.fn()} | ||
loading={true} | ||
/>, | ||
{database}, | ||
); | ||
expect(getByTestId('team_list.loading')).toBeTruthy(); | ||
}); | ||
|
||
it('should render separator after the first item when separatorAfterFirstItem is true', () => { | ||
const {getByTestId} = renderWithEverything( | ||
<TeamList | ||
teams={teams} | ||
onPress={jest.fn()} | ||
separatorAfterFirstItem={true} | ||
/>, | ||
{database}, | ||
); | ||
expect(getByTestId('team_list.separator')).toBeTruthy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
|
||
import {renderWithIntlAndTheme, fireEvent} from '@test/intl-test-helper'; | ||
|
||
import TeamListItem from './team_list_item'; | ||
|
||
import type TeamModel from '@typings/database/models/servers/team'; | ||
|
||
describe('TeamListItem', () => { | ||
const team = { | ||
id: 'team_id', | ||
displayName: 'Team Display Name', | ||
lastTeamIconUpdatedAt: 0, | ||
} as TeamModel; | ||
const iconTestId = `team_sidebar.team_list.team_list_item.${team.id}.team_icon`; | ||
|
||
it('should call onPress when pressed', () => { | ||
const onPressMock = jest.fn(); | ||
const {getByText} = renderWithIntlAndTheme( | ||
<TeamListItem | ||
team={team} | ||
onPress={onPressMock} | ||
/>, | ||
); | ||
|
||
fireEvent.press(getByText('Team Display Name')); | ||
|
||
expect(onPressMock).toHaveBeenCalledWith('team_id'); | ||
}); | ||
|
||
it('should render TeamIcon when hideIcon is false', () => { | ||
const {getByTestId} = renderWithIntlAndTheme( | ||
<TeamListItem | ||
team={team} | ||
onPress={jest.fn()} | ||
hideIcon={false} | ||
/>, | ||
); | ||
|
||
expect(getByTestId(iconTestId)).toBeTruthy(); | ||
}); | ||
|
||
it('should not render TeamIcon when hideIcon is true', () => { | ||
const {queryByTestId} = renderWithIntlAndTheme( | ||
<TeamListItem | ||
team={team} | ||
onPress={jest.fn()} | ||
hideIcon={true} | ||
/>, | ||
); | ||
|
||
expect(queryByTestId(iconTestId)).toBeNull(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ type Props = { | |
iconBackgroundColor?: string; | ||
selectedTeamId?: string; | ||
onPress: (teamId: string) => void; | ||
hideIcon?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we hiding the icon? I could not find any reference to this in the tickets nor a figma attached There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
export const ITEM_HEIGHT = 56; | ||
|
@@ -50,7 +51,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { | |
}; | ||
}); | ||
|
||
export default function TeamListItem({team, textColor, iconTextColor, iconBackgroundColor, selectedTeamId, onPress}: Props) { | ||
export default function TeamListItem({team, textColor, iconTextColor, iconBackgroundColor, selectedTeamId, onPress, hideIcon}: Props) { | ||
const theme = useTheme(); | ||
const styles = getStyleSheet(theme); | ||
|
||
|
@@ -68,17 +69,19 @@ export default function TeamListItem({team, textColor, iconTextColor, iconBackgr | |
type='opacity' | ||
style={styles.touchable} | ||
> | ||
<View style={styles.icon_container}> | ||
<TeamIcon | ||
id={team.id} | ||
displayName={displayName} | ||
lastIconUpdate={lastTeamIconUpdateAt} | ||
selected={false} | ||
textColor={iconTextColor || theme.centerChannelColor} | ||
backgroundColor={iconBackgroundColor || changeOpacity(theme.centerChannelColor, 0.16)} | ||
testID={`${teamListItemTestId}.team_icon`} | ||
/> | ||
</View> | ||
{!hideIcon && | ||
<View style={styles.icon_container}> | ||
<TeamIcon | ||
id={team.id} | ||
displayName={displayName} | ||
lastIconUpdate={lastTeamIconUpdateAt} | ||
selected={false} | ||
textColor={iconTextColor || theme.centerChannelColor} | ||
backgroundColor={iconBackgroundColor || changeOpacity(theme.centerChannelColor, 0.16)} | ||
testID={`${teamListItemTestId}.team_icon`} | ||
/> | ||
</View> | ||
} | ||
<Text | ||
style={[styles.text, Boolean(textColor) && {color: textColor}]} | ||
numberOfLines={1} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for long names, should we add an ellipsis ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
export const ALL_TEAMS_ID = ''; | ||
|
||
export default { | ||
ALL_TEAMS_ID, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what % of code is being covered with this tests? if 80% or more then OK, if not, let's try and bring it to 80%+ please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be good,
jest --coverage app/components/team_list/index.test.tsx --collectCoverageFrom=app/components/team_list/index.tsx
gave meI had to change the
jest.config.js
which is set to not report coverage on our components or screens.