Signal-Desktop/ts/test-both/helpers/getFakeStory.tsx

76 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-07-01 00:52:03 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-07-20 21:29:09 +00:00
import casual from 'casual';
2022-07-01 00:52:03 +00:00
import type { AttachmentType } from '../../types/Attachment';
import type { ConversationType } from '../../state/ducks/conversations';
import type {
ConversationStoryType,
MyStoryType,
StoryViewType,
} from '../../types/Stories';
import * as durations from '../../util/durations';
2022-07-20 21:29:09 +00:00
import { UUID } from '../../types/UUID';
2022-07-01 00:52:03 +00:00
import { getDefaultConversation } from './getDefaultConversation';
import { fakeAttachment, fakeThumbnail } from './fakeAttachment';
import { MY_STORIES_ID } from '../../types/Stories';
function getAttachmentWithThumbnail(url: string): AttachmentType {
return fakeAttachment({
url,
thumbnail: fakeThumbnail(url),
});
}
export function getFakeMyStory(id?: string, name?: string): MyStoryType {
2022-07-20 21:29:09 +00:00
const storyCount = casual.integer(2, 6);
2022-07-01 00:52:03 +00:00
return {
2022-07-20 21:29:09 +00:00
distributionId: id || UUID.generate().toString(),
2022-07-01 00:52:03 +00:00
distributionName:
2022-07-20 21:29:09 +00:00
name || id === MY_STORIES_ID ? 'My Stories' : casual.catch_phrase,
2022-07-01 00:52:03 +00:00
stories: Array.from(Array(storyCount), () => ({
...getFakeStoryView(),
sendState: [],
2022-07-20 21:29:09 +00:00
views: casual.integer(1, 20),
2022-07-01 00:52:03 +00:00
})),
};
}
export function getFakeStoryView(
attachmentUrl?: string,
timestamp?: number
): StoryViewType {
const sender = getDefaultConversation();
return {
attachment: getAttachmentWithThumbnail(
attachmentUrl || '/fixtures/tina-rolf-269345-unsplash.jpg'
),
2022-07-20 21:29:09 +00:00
hasReplies: Boolean(casual.coin_flip),
isUnread: Boolean(casual.coin_flip),
messageId: UUID.generate().toString(),
2022-07-01 00:52:03 +00:00
sender,
timestamp: timestamp || Date.now() - 2 * durations.MINUTE,
};
}
export function getFakeStory({
attachmentUrl,
group,
timestamp,
}: {
attachmentUrl?: string;
group?: ConversationType;
timestamp?: number;
}): ConversationStoryType {
const storyView = getFakeStoryView(attachmentUrl, timestamp);
return {
conversationId: storyView.sender.id,
group,
2022-07-06 19:06:20 +00:00
storyView,
2022-07-01 00:52:03 +00:00
};
}