mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-07 19:30:14 +00:00
* Expo-Router partial migration * Full migration to ExpoRouter * i18n * add tests * Merge branch 'main' into expo-router * align package-lock.json * i18n * feedback review * feedback review * android 16kb patch * Refactored emoji picker keyboard using a state machine * set android launch_screen in drawables instead of layout * no conditional hooks * remove duplicate call in test * address feedback * fix tests and address more feedback * small corrections * small corrections * small corrections * fix draft test * fix draft test 2 * remove navigateToScreen in draff test * fix nit in draft test * remove doc file * Feedback review * fix snapshots * improve test coverage * fix i18n * Upgrade t o RN 0.83, other dependencies and new architecture (#9737) * library hardware-keyboard android new arch support fix * library rnshare android new arch support fix * library rnutils android new arch support fix * library secure-pdf-viewer add new arch support * Enable new arch on iOS and Android * update emm and network client with new-arch * update intune to use new-arch * performance improvements * fix tests * fixes post input on new-arch * fix android emoji picker * remove doc * run tests in parallel * upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture Bumps core dependencies to their latest versions: - React Native 0.77.3 → 0.83.9 (New Architecture enabled) - React 18.3.1 → 19.2.5 - Expo SDK 52 → 55 - TypeScript 5.8.3 → 6.0.3 - Node.js 22.16.0 → 24.15.0 - react-native-reanimated 3.17.3 → 4.3.0 - Various other dependency upgrades Migrates iOS AppDelegate from Objective-C to Swift, updates Android build tooling and Gradle wrapper, refreshes all patches and font assets, and adapts app code, tests, and CI workflows throughout for API changes introduced by these upgrades. * remove unecessary dismissKeyboard in notifications * feedback review * update intune to use new-arch * update @mattermost deps * missing i18n string * additional fixes * update fastlane
336 lines
11 KiB
TypeScript
336 lines
11 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {checkDialogElementForError, checkIfErrorsMatchElements, selectKeyboardType} from './integrations';
|
|
|
|
import type {IntlShape, MessageDescriptor} from 'react-intl';
|
|
|
|
function makeIntl(): IntlShape {
|
|
return {
|
|
formatMessage: jest.fn((descriptor: MessageDescriptor, values?: Record<string, unknown>) => {
|
|
if (values && Object.keys(values).length > 0) {
|
|
let msg = descriptor.defaultMessage as string;
|
|
for (const [k, v] of Object.entries(values)) {
|
|
msg = msg.replace(`{${k}}`, String(v));
|
|
}
|
|
return msg;
|
|
}
|
|
return descriptor.defaultMessage as string;
|
|
}),
|
|
} as unknown as IntlShape;
|
|
}
|
|
|
|
describe('checkDialogElementForError', () => {
|
|
it('should return required error for empty required field', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
optional: false,
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
expect(checkDialogElementForError(elem, '', makeIntl())).toBe('This field is required.');
|
|
});
|
|
|
|
it('should return too short error for text shorter than min_length', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
min_length: 5,
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
expect(checkDialogElementForError(elem, '123', makeIntl())).toBe('Minimum input length is 5.');
|
|
});
|
|
|
|
it('should return bad email error for invalid email', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
subtype: 'email',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
expect(checkDialogElementForError(elem, 'invalidemail', makeIntl())).toBe('Must be a valid email address.');
|
|
});
|
|
|
|
it('should return bad number error for invalid number', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
subtype: 'number',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
expect(checkDialogElementForError(elem, 'notanumber', makeIntl())).toBe('Must be a number.');
|
|
});
|
|
|
|
it('should return bad URL error for invalid URL', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
subtype: 'url',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
expect(checkDialogElementForError(elem, 'invalidurl', makeIntl())).toBe('URL must include http:// or https://.');
|
|
});
|
|
|
|
it('should return invalid option error for invalid radio option', () => {
|
|
const elem: DialogElement = {
|
|
name: 'field1',
|
|
type: 'radio',
|
|
options: [{value: 'option1', text: ''}, {value: 'option2', text: ''}],
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
};
|
|
expect(checkDialogElementForError(elem, 'invalidoption', makeIntl())).toBe('Must be a valid option');
|
|
});
|
|
|
|
it('should return null for valid inputs', () => {
|
|
const elemText: DialogElement = {
|
|
name: 'field1',
|
|
type: 'text',
|
|
min_length: 3,
|
|
display_name: '',
|
|
subtype: 'password',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
const elemEmail: DialogElement = {
|
|
name: 'field2',
|
|
type: 'text',
|
|
subtype: 'email',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
const elemNumber: DialogElement = {
|
|
name: 'field3',
|
|
type: 'text',
|
|
subtype: 'number',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
const elemURL: DialogElement = {
|
|
name: 'field4',
|
|
type: 'text',
|
|
subtype: 'url',
|
|
display_name: '',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
};
|
|
const elemRadio: DialogElement = {
|
|
name: 'field5',
|
|
type: 'radio',
|
|
options: [{value: 'option1', text: ''}, {value: 'option2', text: ''}],
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
};
|
|
const intl = makeIntl();
|
|
expect(checkDialogElementForError(elemText, 'valid', intl)).toBeNull();
|
|
expect(checkDialogElementForError(elemEmail, 'email@example.com', intl)).toBeNull();
|
|
expect(checkDialogElementForError(elemNumber, '123', intl)).toBeNull();
|
|
expect(checkDialogElementForError(elemURL, 'http://example.com', intl)).toBeNull();
|
|
expect(checkDialogElementForError(elemRadio, 'option1', intl)).toBeNull();
|
|
});
|
|
|
|
describe('multiselect SELECT validation', () => {
|
|
const multiselectElement: DialogElement = {
|
|
name: 'multiselect_field',
|
|
type: 'select',
|
|
multiselect: true,
|
|
optional: false,
|
|
options: [
|
|
{text: 'Option A', value: 'optA'},
|
|
{text: 'Option B', value: 'optB'},
|
|
{text: 'Option C', value: 'optC'},
|
|
],
|
|
display_name: 'Multi Select Field',
|
|
placeholder: '',
|
|
help_text: '',
|
|
default: '',
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
};
|
|
|
|
it('should validate multiselect values correctly', () => {
|
|
expect(checkDialogElementForError(multiselectElement, ['optA', 'optC'], makeIntl())).toBeNull();
|
|
});
|
|
|
|
it('should require at least one selection for required multiselect', () => {
|
|
expect(checkDialogElementForError(multiselectElement, [], makeIntl())).toBe('This field is required.');
|
|
});
|
|
|
|
it('should reject invalid options in multiselect array', () => {
|
|
expect(checkDialogElementForError(multiselectElement, ['optA', 'invalidOption'], makeIntl())).toBe('Must be a valid option');
|
|
});
|
|
|
|
it('should allow empty arrays for optional multiselect', () => {
|
|
const optionalElement = {...multiselectElement, optional: true};
|
|
expect(checkDialogElementForError(optionalElement, [], makeIntl())).toBeNull();
|
|
});
|
|
|
|
it('should handle single valid option in multiselect', () => {
|
|
expect(checkDialogElementForError(multiselectElement, ['optB'], makeIntl())).toBeNull();
|
|
});
|
|
|
|
it('should handle all options selected', () => {
|
|
expect(checkDialogElementForError(multiselectElement, ['optA', 'optB', 'optC'], makeIntl())).toBeNull();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('checkIfErrorsMatchElements', () => {
|
|
it('should return false if no dialog elements', () => {
|
|
const errors = {field1: 'error'};
|
|
expect(checkIfErrorsMatchElements(errors)).toBe(false);
|
|
});
|
|
|
|
it('should return false if no dialog errors', () => {
|
|
expect(checkIfErrorsMatchElements()).toBe(false);
|
|
});
|
|
|
|
it('should return true if errors match elements', () => {
|
|
const elements: DialogElement[] = [{
|
|
name: 'field1',
|
|
type: 'text',
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
}];
|
|
const errors = {field1: 'error'};
|
|
expect(checkIfErrorsMatchElements(errors, elements)).toBe(true);
|
|
});
|
|
|
|
it('should return false if errors do not match elements', () => {
|
|
const elements: DialogElement[] = [{
|
|
name: 'field1',
|
|
type: 'text',
|
|
display_name: '',
|
|
subtype: 'number',
|
|
default: '',
|
|
placeholder: '',
|
|
help_text: '',
|
|
optional: false,
|
|
min_length: 0,
|
|
max_length: 0,
|
|
data_source: '',
|
|
options: [],
|
|
}];
|
|
const errors = {field2: 'error'};
|
|
expect(checkIfErrorsMatchElements(errors, elements)).toBe(false);
|
|
});
|
|
|
|
it('should return false if errors and elements are empty', () => {
|
|
expect(checkIfErrorsMatchElements({}, [])).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('selectKeyboardType', () => {
|
|
it('should return email-address for email subtype', () => {
|
|
expect(selectKeyboardType('email')).toBe('email-address');
|
|
});
|
|
|
|
it('should return numeric for number subtype', () => {
|
|
expect(selectKeyboardType('number')).toBe('numeric');
|
|
});
|
|
|
|
it('should return phone-pad for tel subtype', () => {
|
|
expect(selectKeyboardType('tel')).toBe('phone-pad');
|
|
});
|
|
|
|
it('should return url for url subtype', () => {
|
|
expect(selectKeyboardType('url')).toBe('url');
|
|
});
|
|
|
|
it('should return default for undefined subtype', () => {
|
|
expect(selectKeyboardType()).toBe('default');
|
|
});
|
|
|
|
it('should return default for unrecognized subtype', () => {
|
|
expect(selectKeyboardType('unrecognized')).toBe('default');
|
|
});
|
|
});
|