mattermost-mobile/test/setup.js
Miguel Alatzar 5c654364c1 [MM-15401] Fix setting of extension when caching files (#2762)
* Get extension from Content-Disposition first

* User ImageCacheManager.cache over getCacheFile

* Add unit tests for ImageCacheManager.getCacheFile

* Add unit tests for ImageCacheManager.cache

* Use exports and require to be able to mock isDownloading

* Chain mockReturnValueOnce calls

* Fix getExtensionFromContentDisposition and its unit tests
2019-05-03 09:28:29 -07:00

107 lines
2.4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {configure} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({adapter: new Adapter()});
/* eslint-disable no-console */
jest.mock('NativeModules', () => {
return {
UIManager: {
RCTView: {
directEventTypes: {},
},
},
BlurAppScreen: () => true,
MattermostManaged: {
getConfig: jest.fn(),
},
PlatformConstants: {
forceTouchAvailable: false,
},
RNGestureHandlerModule: {
State: {
BEGAN: 'BEGAN',
FAILED: 'FAILED',
ACTIVE: 'ACTIVE',
END: 'END',
},
},
};
});
jest.mock('NativeEventEmitter');
jest.mock('react-native-device-info', () => {
return {
getVersion: () => '0.0.0',
getBuildNumber: () => '0',
getModel: () => 'iPhone X',
};
});
let logs;
let warns;
let errors;
beforeAll(() => {
console.originalLog = console.log;
console.log = jest.fn((...params) => {
console.originalLog(...params);
logs.push(params);
});
console.originalWarn = console.warn;
console.warn = jest.fn((...params) => {
console.originalWarn(...params);
warns.push(params);
});
console.originalError = console.error;
console.error = jest.fn((...params) => {
console.originalError(...params);
errors.push(params);
});
});
beforeEach(() => {
logs = [];
warns = [];
errors = [];
});
afterEach(() => {
if (logs.length > 0 || warns.length > 0 || errors.length > 0) {
throw new Error('Unexpected console logs' + logs + warns + errors);
}
});
jest.mock('rn-fetch-blob', () => ({
fs: {
dirs: {
DocumentDir: () => jest.fn(),
CacheDir: () => jest.fn(),
},
exists: jest.fn(),
existsWithDiffExt: jest.fn(),
unlink: jest.fn(),
mv: jest.fn(),
},
fetch: jest.fn(),
config: jest.fn(),
}));
jest.mock('rn-fetch-blob/fs', () => ({
dirs: {
DocumentDir: () => jest.fn(),
CacheDir: () => jest.fn(),
},
exists: jest.fn(),
existsWithDiffExt: jest.fn(),
unlink: jest.fn(),
mv: jest.fn(),
}));
global.requestAnimationFrame = (callback) => {
setTimeout(callback, 0);
};