* feat: ai rewrite * feat: allow crating content apart from editing it * feat: feature parity with webapp * feat: feature parity with webapp * chore: fixed padding * map ux to webapp * refactored ai rewrite logic to separate package * chore: tests and lint * Update app/products/ai/rewrite/screens/options/options.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rewrite post editor animation * i18n * ui feedback, centered icon and less top padding * chore: lint * Consolidate @ai product into @agents Move all rewrite functionality from app/products/ai/ into app/products/agents/ to unify under a single namespace. - Add rewrite types, store, hooks, components, and screens to agents - Merge AI client methods into agents client - Update screen constants (AI_* -> AGENTS_*) - Update all consumer imports - Remove AI state from EphemeralStore - Remove @ai path alias from config - Delete app/products/ai/ directory * refactor: load screens from product package * refactor: move detection logic to the agents pacakge * refactor: remove "backwards compatibility" * refactor: move hooks to proper package * refactor: styles * refactor: remove unneedd position attribute * refactor: remove unneeded cancel animation calls * refactor: "backwards compat" * refactor: optimize renderContent with useCallback for performance * refactor: rename variable to avoid confusion * refactor: update handleRewrite to use async/await for better error handling * refactor: simplify handleRewrite by always dismissing keyboard * refactor: use hook, always all keyboard.dismiss * chore: enhance AgentSelector component with FlatList support * feat: add rewriteMessage function for AI message rewriting and integrate it into useRewrite hook * refactor: simplify message length calculation in useHandleSendMessage hook * refactor: consolidate agent screen constants and integrate with existing screens * fix: update dependency array in useMemo for isUnrevealedPost to include post expiration metadata * refactor: remove unused variable to clean up Typing component * refactor: simplify logic for atDisabled and slashDisabled flags in QuickActions component * feat: add AIRewriteAction component for AI message rewriting functionality * revert: thread.ts changes manually * refactor: integrate useSafeAreaInsets * refactor: cleanup unused methods * chore: add comment to clarify casting * refactor: use_agents * chore: lint and test * fix: trim --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Alert} from 'react-native';
|
|
import Exception from 'react-native-exception-handler';
|
|
|
|
import {dismissAllModals, dismissAllOverlays} from '@screens/navigation';
|
|
import testHelper from '@test/test_helper';
|
|
import * as Sentry from '@utils/sentry';
|
|
|
|
import errorHandling from './error_handling';
|
|
import * as Log from './log';
|
|
|
|
jest.mock('react-native-exception-handler', () => ({
|
|
setJSExceptionHandler: jest.fn((callback: () => void, allowInDevMode: boolean) => {
|
|
if (!allowInDevMode) {
|
|
callback();
|
|
}
|
|
}),
|
|
}));
|
|
|
|
jest.mock('@utils/log', () => ({
|
|
logError: jest.fn(),
|
|
logWarning: jest.fn(() => ''),
|
|
logDebug: jest.fn(),
|
|
logInfo: jest.fn(),
|
|
}));
|
|
|
|
describe('JavascriptAndNativeErrorHandler', () => {
|
|
const warning = jest.spyOn(Log, 'logWarning');
|
|
const error = 'some error';
|
|
|
|
test('Initialization', () => {
|
|
const setJSExceptionHandler = jest.spyOn(Exception, 'setJSExceptionHandler');
|
|
const initializeSentry = jest.spyOn(Sentry, 'initializeSentry');
|
|
errorHandling.initializeErrorHandling();
|
|
expect(setJSExceptionHandler).toHaveBeenCalledTimes(1);
|
|
expect(initializeSentry).toHaveBeenCalledTimes(1);
|
|
expect(setJSExceptionHandler).toHaveBeenCalledWith(errorHandling.errorHandler, false);
|
|
});
|
|
|
|
test('nativeErrorHander', () => {
|
|
const captureException = jest.spyOn(Sentry, 'captureException');
|
|
errorHandling.nativeErrorHandler(error);
|
|
expect(warning).toHaveBeenCalledTimes(1);
|
|
expect(warning).toHaveBeenCalledWith(`Handling native error ${error}`);
|
|
expect(captureException).toHaveBeenCalledTimes(1);
|
|
expect(captureException).toHaveBeenCalledWith(error);
|
|
});
|
|
|
|
test('errorHandler', async () => {
|
|
const captureJSException = jest.spyOn(Sentry, 'captureJSException');
|
|
|
|
errorHandling.errorHandler(null, false);
|
|
expect(warning).toHaveBeenCalledTimes(0);
|
|
|
|
errorHandling.errorHandler(error, true);
|
|
expect(warning).toHaveBeenCalledTimes(1);
|
|
expect(warning).toHaveBeenCalledWith('Handling Javascript error', error, true);
|
|
expect(captureJSException).toHaveBeenCalledTimes(1);
|
|
expect(captureJSException).toHaveBeenCalledWith(error, true);
|
|
|
|
const throwError = new Error(error);
|
|
const alert = jest.spyOn(Alert, 'alert');
|
|
errorHandling.errorHandler(throwError, true);
|
|
expect(alert?.mock?.calls?.[0]?.length).toBe(4);
|
|
alert?.mock.calls?.[0]?.[2]?.[0]?.onPress?.();
|
|
expect(dismissAllModals).toHaveBeenCalledTimes(1);
|
|
await testHelper.wait(20);
|
|
expect(dismissAllOverlays).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|