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

169 lines
3.5 KiB
TypeScript
Raw Normal View History

2022-03-29 01:10:08 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { v4 as uuid } from 'uuid';
import { action } from '@storybook/addon-actions';
import type { PropsType } from './StoryImage';
import { StoryImage } from './StoryImage';
import enMessages from '../../_locales/en/messages.json';
import { setupI18n } from '../util/setupI18n';
import {
fakeAttachment,
fakeThumbnail,
} from '../test-both/helpers/fakeAttachment';
2022-04-12 19:29:30 +00:00
import { VIDEO_MP4 } from '../types/MIME';
2022-03-29 01:10:08 +00:00
const i18n = setupI18n('en', enMessages);
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/StoryImage',
};
2022-03-29 01:10:08 +00:00
function getDefaultProps(): PropsType {
return {
attachment: fakeAttachment({
url: '/fixtures/nathan-anderson-316188-unsplash.jpg',
thumbnail: fakeThumbnail('/fixtures/nathan-anderson-316188-unsplash.jpg'),
}),
2022-08-04 00:38:41 +00:00
firstName: 'Charlie',
2022-03-29 01:10:08 +00:00
i18n,
label: 'A story',
queueStoryDownload: action('queueStoryDownload'),
storyId: uuid(),
};
}
2022-06-07 00:48:02 +00:00
export const GoodStory = (): JSX.Element => (
<StoryImage {...getDefaultProps()} />
);
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
GoodStory.story = {
name: 'Good story',
};
export const GoodStoryThumbnail = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage {...getDefaultProps()} isThumbnail />
2022-06-07 00:48:02 +00:00
);
GoodStoryThumbnail.story = {
name: 'Good story (thumbnail)',
};
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
export const NotDownloaded = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage {...getDefaultProps()} attachment={fakeAttachment()} />
2022-06-07 00:48:02 +00:00
);
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
NotDownloaded.story = {
name: 'Not downloaded',
};
export const NotDownloadedThumbnail = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment()}
isThumbnail
/>
2022-06-07 00:48:02 +00:00
);
NotDownloadedThumbnail.story = {
name: 'Not downloaded (thumbnail)',
};
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
export const PendingDownload = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
pending: true,
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
PendingDownload.story = {
name: 'Pending download',
};
export const PendingDownloadThumbnail = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
pending: true,
})}
isThumbnail
/>
2022-06-07 00:48:02 +00:00
);
PendingDownloadThumbnail.story = {
name: 'Pending download (thumbnail)',
};
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
export const BrokenImage = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
url: '/this/path/does/not/exist.jpg',
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-03-29 01:10:08 +00:00
2022-06-07 00:48:02 +00:00
export const BrokenImageThumbnail = (): JSX.Element => (
2022-03-29 01:10:08 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
url: '/this/path/does/not/exist.jpg',
})}
isThumbnail
/>
2022-06-07 00:48:02 +00:00
);
BrokenImageThumbnail.story = {
name: 'Broken Image (thumbnail)',
};
2022-04-12 19:29:30 +00:00
2022-06-07 00:48:02 +00:00
export const Video = (): JSX.Element => (
2022-04-12 19:29:30 +00:00
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
contentType: VIDEO_MP4,
url: '/fixtures/pixabay-Soap-Bubble-7141.mp4',
})}
/>
2022-06-07 00:48:02 +00:00
);
2022-08-04 00:38:41 +00:00
export const ErrorImage = (): JSX.Element => (
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
error: true,
url: '/this/path/does/not/exist.jpg',
})}
/>
);
export const ErrorImageThumbnail = (): JSX.Element => (
<StoryImage
{...getDefaultProps()}
attachment={fakeAttachment({
error: true,
url: '/this/path/does/not/exist.jpg',
})}
isThumbnail
/>
);
ErrorImageThumbnail.story = {
name: 'Error Image (thumbnail)',
};
export const ErrorImageYou = (): JSX.Element => (
<StoryImage
{...getDefaultProps()}
isMe
attachment={fakeAttachment({
error: true,
url: '/this/path/does/not/exist.jpg',
})}
/>
);