mattermost-mobile-upstream/app/components/autocomplete_selector/index.test.tsx
Daniel Espino García 84ea188366
Mattermost Blocks (#9764)
* Mattermost Blocks

* Move block renderer to its own components folder

* Sync translation layer

* UX fixes

* Refactor button to use the button component

* Code review

* Fix CI

* Add animations to collapse blocks

* Add unit tests

* Add e2e tests and related fixes

* Address coderabbit comments

* Address UX comments

* Address feedback

* Address coderabbit comments

* Fix snapshots

* Sync with webapp translation

* Add node limit to button markdown node

* Address feedback

* i18n-extract

* Fix test

* Move image utils to the utils folder

* Remove unneeded style

* Revert build script change

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-06-29 18:42:16 +02:00

80 lines
2.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {type ComponentProps} from 'react';
import {Screens} from '@constants';
import DatabaseManager from '@database/manager';
import {renderWithEverything} from '@test/intl-test-helper';
import AutoCompleteSelector from './index';
import type {Database} from '@nozbe/watermelondb';
jest.mock('@screens/navigation', () => ({
navigateToScreen: jest.fn(),
navigateToSettingsScreen: jest.fn(),
}));
jest.mock('@store/settings_store', () => ({
setIntegrationsSelectCallback: jest.fn(),
setIntegrationsDynamicOptionsCallback: jest.fn(),
}));
describe('AutoCompleteSelector', () => {
let database: Database;
const serverUrl = 'https://server-url.com';
beforeEach(async () => {
await DatabaseManager.init([serverUrl]);
database = DatabaseManager.getServerDatabaseAndOperator(serverUrl).database;
});
afterEach(async () => {
await DatabaseManager.destroyServerDatabase(serverUrl);
jest.clearAllMocks();
});
function getBaseProps(): Omit<ComponentProps<typeof AutoCompleteSelector>, 'teammateNameDisplay'> {
return {
testID: 'autocomplete.selector',
location: Screens.CHANNEL,
options: [
{value: 'a', text: 'Option A'},
{value: 'b', text: 'Option B'},
],
};
}
describe('omitMargins', () => {
it('should apply default container margins when omitMargins is false', () => {
const {root} = renderWithEverything(
<AutoCompleteSelector {...getBaseProps()}/>,
{database, serverUrl},
);
expect(root).toHaveStyle({
marginTop: 10,
marginBottom: 2,
marginRight: 8,
});
});
it('should zero out container margins when omitMargins is true', () => {
const {root} = renderWithEverything(
<AutoCompleteSelector
{...getBaseProps()}
omitMargins={true}
/>,
{database, serverUrl},
);
expect(root).toHaveStyle({
marginTop: 0,
marginBottom: 0,
marginRight: 0,
});
});
});
});