mattermost-mobile/app/utils/log.test.ts
Daniel Espino García 5c2153f83b
Add Report a Problem functionality (#8605)
* Add Report a Problem functionality

* update cache pinned SHA version from 4.0.2 to 4.2.0

* Address feedback

* Fix tests

* Fix some issues and update kotlin coroutines version

* Fix delete file for iOS

* Bump 1 more version for coroutines

* Use rxjava instead of kotlin coroutines to avoid security issue

* Move path prefix to avoid test error

* Address feedback

* Address feedback

* Address feedback

* Use mailto on iOS

* Fix tests related to button changes

* Address feedback

* Update icon and fix onboarding buttons

* Fix test

---------

Co-authored-by: Angelos Kyratzakos <angelos.kyratzakos@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-24 11:12:55 +02:00

91 lines
2.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Config from '@assets/config.json';
import keyMirror from '@utils/key_mirror';
import {logError, logWarning, logInfo, logDebug} from './log';
// Mock Sentry
jest.mock('@sentry/react-native', () => ({
addBreadcrumb: jest.fn(),
}));
// We need to get back the original functions
// since we are mocking them in the setup file
jest.mock('./log', () => ({
...jest.requireActual('./log'),
}));
// Mock console methods
const originalConsole = global.console;
// @ts-expect-error global not in TS def
global.console = {
error: jest.fn(),
warn: jest.fn(),
log: jest.fn(),
debug: jest.fn(),
};
describe('Logging functions', () => {
const Sentry = require('@sentry/react-native');
const SentryLevels = keyMirror({debug: null, info: null, warning: null, error: null});
beforeAll(() => {
Config.SentryEnabled = true;
});
afterEach(() => {
jest.clearAllMocks();
});
afterAll(() => {
global.console = originalConsole;
Config.SentryEnabled = false;
});
test('logError logs error and adds breadcrumb', () => {
const args = ['Error message'];
logError(...args);
expect(console.error).toHaveBeenCalledWith(...args);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
level: SentryLevels.error,
message: args.join(','),
type: 'console-log',
});
});
test('logWarning logs warning and adds breadcrumb', () => {
const args = ['Warning message'];
logWarning(...args);
expect(console.warn).toHaveBeenCalledWith(...args);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
level: SentryLevels.warning,
message: args.join(','),
type: 'console-log',
});
});
test('logInfo logs info and adds breadcrumb', () => {
const args = ['Info message'];
logInfo(...args);
expect(console.log).toHaveBeenCalledWith(...args);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
level: SentryLevels.info,
message: args.join(','),
type: 'console-log',
});
});
test('logDebug logs debug and adds breadcrumb', () => {
const args = ['Debug message'];
logDebug(...args);
expect(console.debug).toHaveBeenCalledWith(...args);
expect(Sentry.addBreadcrumb).toHaveBeenCalledWith({
level: SentryLevels.debug,
message: args.join(','),
type: 'console-log',
});
});
});