Rename ts/test to ts/styleguide

This commit is contained in:
Daniel Gasienica 2018-04-11 16:31:35 -04:00
parent 96c07c6373
commit 55fc21505e
7 changed files with 5 additions and 5 deletions

View file

@ -1,8 +0,0 @@
The simplest example of using the `<ConversationContext />` component:
```jsx
<util.ConversationContext theme={util.theme}>
<div>Just a plain bit of text</div>
</util.ConversationContext>
```

View file

@ -1,31 +0,0 @@
import React from 'react';
interface Props {
/**
* Corresponds to the theme setting in the app, and the class added to the root element.
*/
theme: 'ios' | 'android' | 'android-dark';
}
/**
* Provides the parent elements necessary to allow the main Signal Desktop stylesheet to
* apply (with no changes) to messages in the Style Guide.
*/
export class ConversationContext extends React.Component<Props, {}> {
public render() {
const { theme } = this.props;
return (
<div className={theme}>
<div className="conversation">
<div className="discussion-container" style={{padding: '0.5em'}}>
<ul className="message-list">
{this.props.children}
</ul>
</div>
</div>
</div>
);
}
}

View file

@ -1,84 +0,0 @@
import moment from 'moment';
import qs from 'qs';
import React from 'react';
import ReactDOM from 'react-dom';
// Helper components used in the Style Guide, exposed at 'util' in the global scope via
// the 'context' option in react-styleguidist.
export { ConversationContext } from './ConversationContext';
export { BackboneWrapper } from '../components/utility/BackboneWrapper';
// Here we can make things inside Webpack available to Backbone views like preload.js.
import { Message } from '../components/conversation/Message';
import { Reply } from '../components/conversation/Reply';
// TypeScript wants two things when you import:
// 1) a normal typescript file
// 2) a javascript file with type definitions
// Anything else will raise an error, that it can't find the module. And so, we ignore...
// @ts-ignore
import gif from '../../fixtures/giphy-GVNvOUpeYmI7e.gif';
// @ts-ignore
import mp3 from '../../fixtures/incompetech-com-Agnus-Dei-X.mp3';
// @ts-ignore
import txt from '../../fixtures/lorem-ipsum.txt';
// @ts-ignore
import mp4 from '../../fixtures/pixabay-Soap-Bubble-7141.mp4';
export {
mp3,
gif,
mp4,
txt,
};
// Required, or TypeScript complains about adding keys to window
const parent = window as any;
const query = window.location.search.replace(/^\?/, '');
const urlOptions = qs.parse(query);
const theme = urlOptions.theme || 'android';
const locale = urlOptions.locale || 'en';
// @ts-ignore
import localeMessages from '../../_locales/en/messages.json';
// @ts-ignore
import { setup } from '../../js/modules/i18n';
const i18n = setup(locale, localeMessages);
export {
theme,
locale,
i18n,
};
parent.i18n = i18n;
parent.moment = moment;
parent.moment.updateLocale(locale, {
relativeTime: {
h: parent.i18n('timestamp_h'),
m: parent.i18n('timestamp_m'),
s: parent.i18n('timestamp_s'),
},
});
parent.moment.locale(locale);
parent.React = React;
parent.ReactDOM = ReactDOM;
parent.Signal.Components = {
Message,
Reply,
};

View file

@ -0,0 +1,96 @@
import 'mocha';
import { assert } from 'chai';
import * as HTML from '../../html';
interface Test {
input: string;
name: string;
output?: string;
outputHref?: string;
outputLabel?: string;
postText?: string;
preText?: string;
skipped?: boolean;
}
describe('HTML', () => {
describe('linkText', () => {
const TESTS: Array<Test> = [
{
name: 'square brackets',
input: 'https://www.example.com/test.html?foo=bar&baz[qux]=quux',
output: 'https://www.example.com/test.html?foo=bar&baz[qux]=quux',
},
{
name: 'Chinese characters',
input: 'https://zh.wikipedia.org/zh-hans/信号',
output: 'https://zh.wikipedia.org/zh-hans/信号',
},
{
name: 'Cyrillic characters',
input: 'https://ru.wikipedia.org/wiki/Сигнал',
output: 'https://ru.wikipedia.org/wiki/Сигнал',
},
{
skipped: true,
name: 'trailing exclamation points',
input: 'https://en.wikipedia.org/wiki/Mother!',
output: 'https://en.wikipedia.org/wiki/Mother!',
},
{
name: 'single quotes',
input: "https://www.example.com/this-couldn't-be-true",
output: "https://www.example.com/this-couldn't-be-true",
},
{
name: 'special characters before URL begins',
preText: 'wink ;)',
input: 'https://www.youtube.com/watch?v=oHg5SJYRHA0',
output: 'https://www.youtube.com/watch?v=oHg5SJYRHA0',
},
{
name: 'URLs without protocols',
input: 'github.com',
outputHref: 'http://github.com',
outputLabel: 'github.com',
},
];
TESTS.forEach((test) => {
(test.skipped ? it.skip : it)(`should handle ${test.name}`, () => {
const preText = test.preText || 'Hello ';
const postText = test.postText || ' World!';
const input: string = `${preText}${test.input}${postText}`;
const expected: string = [
preText,
`<a href="${test.outputHref || test.output}" target="_blank">`,
test.outputLabel || test.output,
'</a>',
postText,
].join('');
const actual = HTML.linkText(input);
assert.equal(actual, expected);
});
});
});
describe('render', () => {
it('should preserve line breaks', () => {
const input: string = 'Hello\n\n\nWorld!';
const expected: string = 'Hello<br><br><br>World!';
const actual = HTML.render(input);
assert.equal(actual, expected);
});
it('should not escape HTML', () => {
const input: string = "Hello\n<script>alert('evil');</script>World!";
const expected: string = "Hello<br><script>alert('evil');</script>World!";
const actual = HTML.render(input);
assert.equal(actual, expected);
});
});
});