mattermost-mobile/app/components/team_list/index.test.tsx
Julien Tant fb9760151c
[MM-60405] Crossteam search (#8411)
* Add new team picker for search

* try fix result header

* fix style

* add test for team picker

* add some tests

* add tests on team list and team list item

* hide All Teams search behind FF

* use style variable for separator

* ALL TEAMS does not have a search history

* Update app/components/team_list/index.test.tsx

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* move ALL_TEAMS_ID to a constant file

* memoize the construction of team list to prevent useless allocation

* combine pushes

* move style to stylesheet

* revert changes to Package.resolved

* improve team list index tests

* add test to ensure team picker does not show for just one team

* add test to ensure the file icon filter only shows when i'm on the file tab

* improve jsx readability by making the if test positive

* add test to make sure team picket does not show if there's only one team

* test: remove snapshot and add expect that separator exists in index 0 but index 1 (#8474)

* Trigger Build

---------

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Rahim Rahman <rahim.rahman@mattermost.com>
2025-02-05 13:46:38 -07:00

69 lines
2.3 KiB
TypeScript

// 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.each([
{loading: true, shouldShow: true, label: 'should render loading component when loading is true'},
{loading: false, shouldShow: false, label: 'should not render loading component when loading is false'},
])('$label', ({loading, shouldShow}) => {
const {queryByTestId} = renderWithEverything(
<TeamList
teams={teams}
onPress={jest.fn()}
loading={loading}
/>,
{database},
);
if (shouldShow) {
expect(queryByTestId('team_list.loading')).toBeTruthy();
} else {
expect(queryByTestId('team_list.loading')).toBeNull();
}
});
it('should render separator after the first item when separatorAfterFirstItem is true', () => {
const {queryByTestId, getByTestId} = renderWithEverything(
<TeamList
teams={teams}
onPress={jest.fn()}
separatorAfterFirstItem={true}
/>,
{database},
);
expect(getByTestId('team_list.separator-0')).toBeTruthy();
expect(queryByTestId('team_list.separator-1')).toBeNull();
});
});