Testing and types updates (#39657)
This commit is contained in:
29 files changed
+263
-191
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
|
||||
import type { StatusVisibility } from '@/mastodon/api_types/statuses';
|
||||
import { statusFactoryState } from '@/testing/factories';
|
||||
import { statusFactoryImmutable } from '@/testing/factories';
|
||||
|
||||
import { BoostButton } from './boost_button';
|
||||
|
||||
@@ -50,7 +50,7 @@ function argsToStatus({
|
||||
quoteAllowed,
|
||||
alreadyBoosted,
|
||||
}: StoryProps) {
|
||||
return statusFactoryState({
|
||||
return statusFactoryImmutable({
|
||||
reblogs_count: reblogCount,
|
||||
visibility,
|
||||
reblogged: alreadyBoosted,
|
||||
|
||||
@@ -5,6 +5,8 @@ import { useIntl } from 'react-intl';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import type { SetRequired } from 'type-fest';
|
||||
|
||||
import { quoteComposeById } from '@/mastodon/actions/compose_typed';
|
||||
import { toggleReblog } from '@/mastodon/actions/interactions';
|
||||
import { openModal } from '@/mastodon/actions/modal';
|
||||
@@ -13,7 +15,6 @@ import { quickBoosting } from '@/mastodon/initial_state';
|
||||
import type { ActionMenuItem } from '@/mastodon/models/dropdown_menu';
|
||||
import type { Status } from '@/mastodon/models/status';
|
||||
import { useAppDispatch, useAppSelector } from '@/mastodon/store';
|
||||
import type { SomeRequired } from '@/mastodon/utils/types';
|
||||
|
||||
import type { RenderItemFn } from '../dropdown_menu';
|
||||
import { Dropdown, DropdownMenuItemContent } from '../dropdown_menu';
|
||||
@@ -91,7 +92,7 @@ interface ReblogButtonProps {
|
||||
counters?: boolean;
|
||||
}
|
||||
|
||||
type ActionMenuItemWithIcon = SomeRequired<ActionMenuItem, 'icon'>;
|
||||
type ActionMenuItemWithIcon = SetRequired<ActionMenuItem, 'icon'>;
|
||||
|
||||
const BoostOrQuoteMenu: FC<ReblogButtonProps> = ({ status, counters }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { fn } from 'storybook/test';
|
||||
|
||||
import type { StatusTranslation } from '@/mastodon/models/status';
|
||||
import { statusFactoryState } from '@/testing/factories';
|
||||
import { statusFactoryImmutable } from '@/testing/factories';
|
||||
|
||||
import { StatusContent } from './content';
|
||||
|
||||
@@ -57,7 +57,7 @@ const meta = {
|
||||
},
|
||||
},
|
||||
stateFn(args: StatusContentProps) {
|
||||
let status = statusFactoryState();
|
||||
let status = statusFactoryImmutable();
|
||||
if (args.translatedTo) {
|
||||
status = status.set('translation', {
|
||||
contentHtml: `${args.text}<p><em>(in ${args.translatedTo})</em></p>`,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
|
||||
import { HashtagMenuController } from '@/mastodon/features/ui/components/hashtag_menu_controller';
|
||||
import { accountFactoryState } from '@/testing/factories';
|
||||
import { accountFactoryImmutable } from '@/testing/factories';
|
||||
|
||||
import { HoverCardController } from '../hover_card_controller';
|
||||
|
||||
@@ -55,7 +55,7 @@ const meta = {
|
||||
parameters: {
|
||||
state: {
|
||||
accounts: {
|
||||
'1': accountFactoryState({ id: '1', acct: 'hashtaguser' }),
|
||||
'1': accountFactoryImmutable({ id: '1', acct: 'hashtaguser' }),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -9,11 +9,11 @@ import { fn } from 'storybook/test';
|
||||
import type { ApiMediaAttachmentJSON } from '@/mastodon/api_types/media_attachments';
|
||||
import type { StatusVisibility } from '@/mastodon/api_types/statuses';
|
||||
import {
|
||||
accountFactoryState,
|
||||
mediaAttachmentFactory,
|
||||
pollFactory,
|
||||
statusFactory,
|
||||
statusFactoryState,
|
||||
accountFactoryImmutable,
|
||||
mediaAttachmentFactoryAPI,
|
||||
pollFactoryImmutable,
|
||||
statusFactoryAPI,
|
||||
statusFactoryImmutable,
|
||||
} from '@/testing/factories';
|
||||
|
||||
import { TypedStatus } from './types';
|
||||
@@ -71,7 +71,7 @@ interface StatusStoryProps {
|
||||
showPrepend?: boolean;
|
||||
}
|
||||
|
||||
const otherAccount = accountFactoryState({
|
||||
const otherAccount = accountFactoryImmutable({
|
||||
id: '2',
|
||||
display_name: 'Another user',
|
||||
});
|
||||
@@ -106,14 +106,14 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
showPrepend = true,
|
||||
} = props;
|
||||
const { account, status } = useMemo(() => {
|
||||
const account = accountFactoryState();
|
||||
const account = accountFactoryImmutable();
|
||||
|
||||
const media_attachments: ApiMediaAttachmentJSON[] = [];
|
||||
switch (attachments) {
|
||||
// Use fall through add attachments depending on count.
|
||||
case 'image-3':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
id: '2',
|
||||
url: 'https://cataas.com/cat/EbVq9zMc4Xxv7s73',
|
||||
meta: {
|
||||
@@ -129,7 +129,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case 'image-2':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
id: '3',
|
||||
url: 'https://cataas.com/cat/YFaQ4xWYoWURSz37',
|
||||
meta: {
|
||||
@@ -145,7 +145,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
// eslint-disable-next-line no-fallthrough
|
||||
case 'image-1':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
id: '4',
|
||||
url: 'https://cataas.com/cat/bYBTjiFUqjUPIBUD',
|
||||
meta: {
|
||||
@@ -161,7 +161,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
break;
|
||||
case 'video':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
type: 'video',
|
||||
url: 'https://www.pexels.com/download/video/11760787/',
|
||||
meta: {
|
||||
@@ -175,7 +175,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
break;
|
||||
case 'audio':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
type: 'audio',
|
||||
url: 'https://upload.wikimedia.org/wikipedia/commons/4/40/Elephant_voice_-_trumpeting.ogg',
|
||||
}),
|
||||
@@ -183,7 +183,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
break;
|
||||
case 'gifv':
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactory({
|
||||
mediaAttachmentFactoryAPI({
|
||||
type: 'gifv',
|
||||
url: 'https://www.pexels.com/download/video/11760787/',
|
||||
meta: {
|
||||
@@ -196,13 +196,15 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
);
|
||||
break;
|
||||
case 'unknown':
|
||||
media_attachments.push(mediaAttachmentFactory({ type: attachments }));
|
||||
media_attachments.push(
|
||||
mediaAttachmentFactoryAPI({ type: attachments }),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
account,
|
||||
status: statusFactoryState({
|
||||
status: statusFactoryImmutable({
|
||||
text,
|
||||
spoiler_text: contentWarning,
|
||||
visibility,
|
||||
@@ -215,7 +217,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
quote: isQuote
|
||||
? {
|
||||
state: 'accepted',
|
||||
quoted_status: { ...statusFactory(), quote: undefined },
|
||||
quoted_status: { ...statusFactoryAPI(), quote: undefined },
|
||||
}
|
||||
: undefined,
|
||||
favourites_count: favouriteCount,
|
||||
@@ -236,7 +238,7 @@ const StatusStoryComponent: FC<StatusStoryProps> = (props) => {
|
||||
if (isReblog) {
|
||||
status.set(
|
||||
'reblog',
|
||||
statusFactoryState({ id: '2' }).set('account', otherAccount),
|
||||
statusFactoryImmutable({ id: '2' }).set('account', otherAccount),
|
||||
);
|
||||
}
|
||||
if (isPoll) {
|
||||
@@ -469,8 +471,8 @@ const meta = {
|
||||
'2': otherAccount,
|
||||
},
|
||||
polls: {
|
||||
'1': pollFactory(),
|
||||
'2': pollFactory({
|
||||
'1': pollFactoryImmutable(),
|
||||
'2': pollFactoryImmutable({
|
||||
voted: true,
|
||||
voters_count: 1,
|
||||
votes_count: 1,
|
||||
|
||||
Reference in new issue
Block a user