2021-11-02 23:01:13 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { ComponentProps } from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
|
|
|
import { setupI18n } from '../util/setupI18n';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
import { getFakeBadge, getFakeBadges } from '../test-both/helpers/getFakeBadge';
|
|
|
|
import { repeat, zipObject } from '../util/iterables';
|
|
|
|
import { BadgeImageTheme } from '../badges/BadgeImageTheme';
|
|
|
|
import { BadgeDialog } from './BadgeDialog';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/BadgeDialog',
|
|
|
|
};
|
2021-11-02 23:01:13 +00:00
|
|
|
|
|
|
|
const defaultProps: ComponentProps<typeof BadgeDialog> = {
|
2021-11-30 16:29:57 +00:00
|
|
|
areWeASubscriber: false,
|
2021-11-02 23:01:13 +00:00
|
|
|
badges: getFakeBadges(3),
|
|
|
|
firstName: 'Alice',
|
|
|
|
i18n,
|
|
|
|
onClose: action('onClose'),
|
|
|
|
title: 'Alice Levine',
|
|
|
|
};
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const NoBadgesClosedImmediately = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog {...defaultProps} badges={[]} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NoBadgesClosedImmediately.story = {
|
|
|
|
name: 'No badges (closed immediately)',
|
|
|
|
};
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const OneBadge = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog {...defaultProps} badges={getFakeBadges(1)} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
OneBadge.story = {
|
|
|
|
name: 'One badge',
|
|
|
|
};
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const BadgeWithNoImageShouldBeImpossible = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog
|
|
|
|
{...defaultProps}
|
|
|
|
badges={[
|
|
|
|
{
|
|
|
|
...getFakeBadge(),
|
|
|
|
images: [],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
BadgeWithNoImageShouldBeImpossible.story = {
|
|
|
|
name: 'Badge with no image (should be impossible)',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const BadgeWithPendingImage = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog
|
|
|
|
{...defaultProps}
|
|
|
|
badges={[
|
|
|
|
{
|
|
|
|
...getFakeBadge(),
|
|
|
|
images: Array(4).fill(
|
|
|
|
zipObject(
|
|
|
|
Object.values(BadgeImageTheme),
|
|
|
|
repeat({ url: 'https://example.com/ignored.svg' })
|
|
|
|
)
|
|
|
|
),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BadgeWithPendingImage.story = {
|
|
|
|
name: 'Badge with pending image',
|
|
|
|
};
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const BadgeWithOnlyOneLowDetailImage = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog
|
|
|
|
{...defaultProps}
|
|
|
|
badges={[
|
|
|
|
{
|
|
|
|
...getFakeBadge(),
|
|
|
|
images: [
|
|
|
|
zipObject(
|
|
|
|
Object.values(BadgeImageTheme),
|
|
|
|
repeat({
|
|
|
|
localPath: '/fixtures/orange-heart.svg',
|
|
|
|
url: 'https://example.com/ignored.svg',
|
|
|
|
})
|
|
|
|
),
|
|
|
|
...Array(3).fill(
|
|
|
|
zipObject(
|
|
|
|
Object.values(BadgeImageTheme),
|
|
|
|
repeat({ url: 'https://example.com/ignored.svg' })
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
BadgeWithOnlyOneLowDetailImage.story = {
|
|
|
|
name: 'Badge with only one, low-detail image',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const FiveBadges = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog {...defaultProps} badges={getFakeBadges(5)} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FiveBadges.story = {
|
|
|
|
name: 'Five badges',
|
|
|
|
};
|
2021-11-02 23:01:13 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const ManyBadges = (): JSX.Element => (
|
2021-11-02 23:01:13 +00:00
|
|
|
<BadgeDialog {...defaultProps} badges={getFakeBadges(50)} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
2021-11-30 16:29:57 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
ManyBadges.story = {
|
|
|
|
name: 'Many badges',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ManyBadgesUserIsASubscriber = (): JSX.Element => (
|
2021-11-30 16:29:57 +00:00
|
|
|
<BadgeDialog {...defaultProps} areWeASubscriber badges={getFakeBadges(50)} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
ManyBadgesUserIsASubscriber.story = {
|
|
|
|
name: 'Many badges, user is a subscriber',
|
|
|
|
};
|