mattermost-mobile/app/utils/theme.test.js
Matheus Cardoso 26b999e885 MM-17759 Add code highlighting (#3072)
* Add code highlighting

* Fix code style

* Add unit tests

* Some layout adjustments and code style fixes

* Fix failing test

* Fix typo

* Fixed import style

* Update snapshot

* Fix test

* Remove comment

* Add react-native-syntax-highlighter to NOTICE.txt

* Remove duplicated key

* Fix color issue on Android

* Remove unnecessary style

* Fix top spacing on Android

* Add missing trailing comma

* Revert highlighting in Android full-screen code

* Fix margins on android full-screen code

* Fix top padding on Android full-screen code

* Fix font size on Android full-screen code

* Improve top spacing on iOS full-screen code

* Update package-lock.json

* Update package-lock.json

* Update react-native-syntax-highlighter

* Revert away code highlighting on Android code block
2019-09-30 22:52:45 +08:00

73 lines
2.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getHighlightStyleFromTheme, getKeyboardAppearanceFromTheme} from 'app/utils/theme';
import * as HighlightStyles from 'react-syntax-highlighter/styles/hljs';
describe('getHighlightStyleFromTheme', () => {
const themes = [{
codeTheme: 'github',
}, {
codeTheme: 'atom-one-light',
}, {
codeTheme: 'androidstudio',
}, {
codeTheme: 'invalid_theme',
}];
it('should return github style for codeTheme="github"', () => {
const theme = getHighlightStyleFromTheme(themes[0]);
expect(theme).toBeTruthy();
expect(theme).toBe(HighlightStyles.github);
});
it('should return atomOneLight style for codeTheme="atom-one-light" (snake-case to camelCase)', () => {
const theme = getHighlightStyleFromTheme(themes[1]);
expect(theme).toBeTruthy();
expect(theme).toBe(HighlightStyles.atomOneLight);
});
it('should return androidstudio style for codeTheme="androidstudio" (no case conversion)', () => {
const theme = getHighlightStyleFromTheme(themes[2]);
expect(theme).toBeTruthy();
expect(theme).toBe(HighlightStyles.androidstudio);
});
it('should return github style by default for codeTheme="invalid_theme"', () => {
const theme = getHighlightStyleFromTheme(themes[3]);
expect(theme).toBeTruthy();
expect(theme).toBe(HighlightStyles.github);
});
});
describe('getKeyboardAppearanceFromTheme', () => {
const themes = [{
centerChannelBg: '#ffffff', // Mattermost
}, {
centerChannelBg: '#f2f4f8', // Organization
}, {
centerChannelBg: '#2f3e4e', // Mattermost Dark
}, {
centerChannelBg: '#1f1f1f', // Windows Dark
}];
it('should return "light" keyboard appearance for centerChannelBg="#ffffff"', () => {
const keyboardAppearance = getKeyboardAppearanceFromTheme(themes[0]);
expect(keyboardAppearance).toBe('light');
});
it('should return "light" keyboard appearance for centerChannelBg="#f2f4f8"', () => {
const keyboardAppearance = getKeyboardAppearanceFromTheme(themes[1]);
expect(keyboardAppearance).toBe('light');
});
it('should return "dark" keyboard appearance for centerChannelBg="#2f3e4e"', () => {
const keyboardAppearance = getKeyboardAppearanceFromTheme(themes[2]);
expect(keyboardAppearance).toBe('dark');
});
it('should return "dark" keyboard appearance for centerChannelBg="#1f1f1f"', () => {
const keyboardAppearance = getKeyboardAppearanceFromTheme(themes[3]);
expect(keyboardAppearance).toBe('dark');
});
});