signal-desktop/ts/components/conversation/conversation-details/GroupLinkManagement.stories.tsx

98 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-05-07 22:21:10 +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';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../../../util/setupI18n';
import enMessages from '../../../../_locales/en/messages.json';
import type { PropsType } from './GroupLinkManagement';
import { GroupLinkManagement } from './GroupLinkManagement';
2021-07-09 19:36:10 +00:00
import { SignalService as Proto } from '../../../protobuf';
import type { ConversationType } from '../../../state/ducks/conversations';
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
const i18n = setupI18n('en', enMessages);
const story = storiesOf(
'Components/Conversation/ConversationDetails/GroupLinkManagement',
module
);
2021-07-09 19:36:10 +00:00
const AccessControlEnum = Proto.AccessControl.AccessRequired;
function getConversation(
groupLink?: string,
accessControlAddFromInviteLink?: number
): ConversationType {
2021-05-07 22:21:10 +00:00
return getDefaultConversation({
id: '',
lastUpdated: 0,
memberships: Array(32).fill({ member: getDefaultConversation({}) }),
pendingMemberships: Array(16).fill({ member: getDefaultConversation({}) }),
title: 'Some Conversation',
type: 'group',
2021-05-07 22:21:10 +00:00
sharedGroupNames: [],
groupLink,
accessControlAddFromInviteLink:
accessControlAddFromInviteLink !== undefined
? accessControlAddFromInviteLink
2021-07-09 19:36:10 +00:00
: AccessControlEnum.UNSATISFIABLE,
2021-05-07 22:21:10 +00:00
});
}
2021-03-02 16:27:11 +00:00
const createProps = (
conversation?: ConversationType,
isAdmin = false
): PropsType => ({
changeHasGroupLink: action('changeHasGroupLink'),
conversation: conversation || getConversation(),
copyGroupLink: action('copyGroupLink'),
generateNewGroupLink: action('generateNewGroupLink'),
i18n,
2021-03-02 16:27:11 +00:00
isAdmin,
setAccessControlAddFromInviteLinkSetting: action(
'setAccessControlAddFromInviteLinkSetting'
),
});
2021-03-02 16:27:11 +00:00
story.add('Off (Admin)', () => {
const props = createProps(undefined, true);
return <GroupLinkManagement {...props} />;
});
2021-03-02 16:27:11 +00:00
story.add('On (Admin)', () => {
const props = createProps(
2021-07-09 19:36:10 +00:00
getConversation('https://signal.group/1', AccessControlEnum.ANY),
2021-03-02 16:27:11 +00:00
true
);
return <GroupLinkManagement {...props} />;
});
story.add('On (Admin + Admin Approval Needed)', () => {
const props = createProps(
2021-07-09 19:36:10 +00:00
getConversation('https://signal.group/1', AccessControlEnum.ADMINISTRATOR),
2021-03-02 16:27:11 +00:00
true
);
return <GroupLinkManagement {...props} />;
});
2021-03-02 16:27:11 +00:00
story.add('On (Non-admin)', () => {
const props = createProps(
2021-07-09 19:36:10 +00:00
getConversation('https://signal.group/1', AccessControlEnum.ANY)
);
return <GroupLinkManagement {...props} />;
});
story.add('Off (Non-admin) - user cannot get here', () => {
const props = createProps(undefined, false);
return <GroupLinkManagement {...props} />;
});