2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
import * as React from 'react';
|
2020-09-12 00:46:52 +00:00
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
import { boolean, text } from '@storybook/addon-knobs';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
|
2020-10-07 00:49:22 +00:00
|
|
|
import { PropsType, SafetyNumberViewer } from './SafetyNumberViewer';
|
2020-06-26 00:08:58 +00:00
|
|
|
import { ConversationType } from '../state/ducks/conversations';
|
|
|
|
import { setup as setupI18n } from '../../js/modules/i18n';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2020-07-24 01:35:32 +00:00
|
|
|
const contactWithAllData = {
|
2020-07-29 23:20:05 +00:00
|
|
|
title: 'Summer Smith',
|
2020-07-24 01:35:32 +00:00
|
|
|
name: 'Summer Smith',
|
|
|
|
phoneNumber: '(305) 123-4567',
|
|
|
|
isVerified: true,
|
|
|
|
} as ConversationType;
|
|
|
|
|
|
|
|
const contactWithJustProfile = {
|
|
|
|
avatarPath: undefined,
|
|
|
|
color: 'signal-blue',
|
2020-07-29 23:20:05 +00:00
|
|
|
title: '-*Smartest Dude*-',
|
2020-07-24 01:35:32 +00:00
|
|
|
profileName: '-*Smartest Dude*-',
|
|
|
|
name: undefined,
|
|
|
|
phoneNumber: '(305) 123-4567',
|
|
|
|
} as ConversationType;
|
|
|
|
|
|
|
|
const contactWithJustNumber = {
|
|
|
|
avatarPath: undefined,
|
|
|
|
color: 'signal-blue',
|
|
|
|
profileName: undefined,
|
|
|
|
name: undefined,
|
2020-07-29 23:20:05 +00:00
|
|
|
title: '(305) 123-4567',
|
2020-07-24 01:35:32 +00:00
|
|
|
phoneNumber: '(305) 123-4567',
|
|
|
|
} as ConversationType;
|
|
|
|
|
|
|
|
const contactWithNothing = {
|
|
|
|
id: 'some-guid',
|
|
|
|
avatarPath: undefined,
|
|
|
|
color: 'signal-blue',
|
|
|
|
profileName: undefined,
|
2020-07-29 23:20:05 +00:00
|
|
|
title: 'Unknown contact',
|
2020-07-24 01:35:32 +00:00
|
|
|
name: undefined,
|
|
|
|
phoneNumber: undefined,
|
|
|
|
} as ConversationType;
|
|
|
|
|
2020-10-07 00:49:22 +00:00
|
|
|
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
|
|
|
contact: overrideProps.contact || contactWithAllData,
|
2020-06-26 00:08:58 +00:00
|
|
|
generateSafetyNumber: action('generate-safety-number'),
|
|
|
|
i18n,
|
2020-10-07 00:49:22 +00:00
|
|
|
safetyNumber: text('safetyNumber', overrideProps.safetyNumber || 'XXX'),
|
|
|
|
safetyNumberChanged: boolean(
|
|
|
|
'safetyNumberChanged',
|
|
|
|
overrideProps.safetyNumberChanged !== undefined
|
|
|
|
? overrideProps.safetyNumberChanged
|
|
|
|
: false
|
|
|
|
),
|
2020-06-26 00:08:58 +00:00
|
|
|
toggleVerified: action('toggle-verified'),
|
2020-10-07 00:49:22 +00:00
|
|
|
verificationDisabled: boolean(
|
|
|
|
'verificationDisabled',
|
|
|
|
overrideProps.verificationDisabled !== undefined
|
|
|
|
? overrideProps.verificationDisabled
|
|
|
|
: false
|
|
|
|
),
|
|
|
|
onClose: overrideProps.onClose,
|
|
|
|
});
|
|
|
|
|
|
|
|
const story = storiesOf('Components/SafetyNumberViewer', module);
|
|
|
|
|
|
|
|
story.add('Safety Number', () => {
|
|
|
|
return <SafetyNumberViewer {...createProps({})} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Safety Number (not verified)', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: {
|
|
|
|
...contactWithAllData,
|
|
|
|
isVerified: false,
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Verification Disabled', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
verificationDisabled: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Safety Number Changed', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
safetyNumberChanged: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Safety Number (dialog close)', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
onClose: action('close'),
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Just Profile and Number', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithJustProfile,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Just Number', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithJustNumber,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('No Phone Number (cannot verify)', () => {
|
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithNothing,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|