signal-desktop/ts/components/ForwardMessageModal.stories.tsx

142 lines
4.4 KiB
TypeScript
Raw Normal View History

2021-04-27 22:35:35 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { text } from '@storybook/addon-knobs';
import enMessages from '../../_locales/en/messages.json';
2021-12-03 01:05:32 +00:00
import type { AttachmentType } from '../types/Attachment';
import type { PropsType } from './ForwardMessageModal';
import { ForwardMessageModal } from './ForwardMessageModal';
2021-08-09 20:06:21 +00:00
import { IMAGE_JPEG, VIDEO_MP4, stringToMIMEType } from '../types/MIME';
2021-04-27 22:35:35 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2021-11-02 23:01:13 +00:00
import { StorybookThemeContext } from '../../.storybook/StorybookThemeContext';
2021-04-27 22:35:35 +00:00
2021-12-03 01:05:32 +00:00
const createAttachment = (
props: Partial<AttachmentType> = {}
): AttachmentType => ({
pending: false,
path: 'fileName.jpg',
2021-08-09 20:06:21 +00:00
contentType: stringToMIMEType(
text('attachment contentType', props.contentType || '')
),
2021-04-27 22:35:35 +00:00
fileName: text('attachment fileName', props.fileName || ''),
screenshotPath: props.pending === false ? props.screenshotPath : undefined,
url: text('attachment url', props.pending === false ? props.url || '' : ''),
size: 3433,
2021-04-27 22:35:35 +00:00
});
const story = storiesOf('Components/ForwardMessageModal', module);
const i18n = setupI18n('en', enMessages);
const LONG_TITLE =
"This is a super-sweet site. And it's got some really amazing content in store for you if you just click that link. Can you click that link for me?";
const LONG_DESCRIPTION =
"You're gonna love this description. Not only does it have a lot of characters, but it will also be truncated in the UI. How cool is that??";
const candidateConversations = Array.from(Array(100), () =>
getDefaultConversation()
);
2021-11-02 23:01:13 +00:00
const useProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
2021-04-27 22:35:35 +00:00
attachments: overrideProps.attachments,
candidateConversations,
doForwardMessage: action('doForwardMessage'),
2021-11-17 18:38:52 +00:00
getPreferredBadge: () => undefined,
2021-04-27 22:35:35 +00:00
i18n,
hasContact: Boolean(overrideProps.hasContact),
2021-04-27 22:35:35 +00:00
isSticker: Boolean(overrideProps.isSticker),
linkPreview: overrideProps.linkPreview,
messageBody: text('messageBody', overrideProps.messageBody || ''),
onClose: action('onClose'),
onEditorStateChange: action('onEditorStateChange'),
onPickEmoji: action('onPickEmoji'),
onTextTooLong: action('onTextTooLong'),
onSetSkinTone: action('onSetSkinTone'),
recentEmojis: [],
removeLinkPreview: action('removeLinkPreview'),
skinTone: 0,
2021-11-02 23:01:13 +00:00
theme: React.useContext(StorybookThemeContext),
regionCode: 'US',
2021-04-27 22:35:35 +00:00
});
story.add('Modal', () => {
2021-11-02 23:01:13 +00:00
return <ForwardMessageModal {...useProps()} />;
2021-04-27 22:35:35 +00:00
});
story.add('with text', () => {
2021-11-02 23:01:13 +00:00
return <ForwardMessageModal {...useProps({ messageBody: 'sup' })} />;
2021-04-27 22:35:35 +00:00
});
story.add('a sticker', () => {
2021-11-02 23:01:13 +00:00
return <ForwardMessageModal {...useProps({ isSticker: true })} />;
2021-04-27 22:35:35 +00:00
});
story.add('with a contact', () => {
return <ForwardMessageModal {...useProps({ hasContact: true })} />;
});
2021-04-27 22:35:35 +00:00
story.add('link preview', () => {
return (
<ForwardMessageModal
2021-11-02 23:01:13 +00:00
{...useProps({
2021-04-27 22:35:35 +00:00
linkPreview: {
description: LONG_DESCRIPTION,
date: Date.now(),
domain: 'https://www.signal.org',
url: 'signal.org',
2021-12-03 01:05:32 +00:00
image: createAttachment({
2021-04-27 22:35:35 +00:00
url: '/fixtures/kitten-4-112-112.jpg',
contentType: IMAGE_JPEG,
}),
isStickerPack: false,
title: LONG_TITLE,
},
messageBody: 'signal.org',
})}
/>
);
});
story.add('media attachments', () => {
return (
<ForwardMessageModal
2021-11-02 23:01:13 +00:00
{...useProps({
2021-04-27 22:35:35 +00:00
attachments: [
2021-12-03 01:05:32 +00:00
createAttachment({
pending: true,
}),
2021-12-03 01:05:32 +00:00
createAttachment({
2021-04-27 22:35:35 +00:00
contentType: IMAGE_JPEG,
fileName: 'tina-rolf-269345-unsplash.jpg',
url: '/fixtures/tina-rolf-269345-unsplash.jpg',
}),
2021-12-03 01:05:32 +00:00
createAttachment({
2021-04-27 22:35:35 +00:00
contentType: VIDEO_MP4,
fileName: 'pixabay-Soap-Bubble-7141.mp4',
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
screenshotPath: '/fixtures/kitten-4-112-112.jpg',
2021-04-27 22:35:35 +00:00
}),
],
messageBody: 'cats',
})}
/>
);
});
2021-07-20 20:18:35 +00:00
story.add('announcement only groups non-admin', () => (
<ForwardMessageModal
2021-11-02 23:01:13 +00:00
{...useProps()}
2021-07-20 20:18:35 +00:00
candidateConversations={[
getDefaultConversation({
announcementsOnly: true,
areWeAdmin: false,
}),
]}
/>
));