signal-desktop/ts/test-both/state/ducks/linkPreviews_test.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-27 22:35:35 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import {
actions,
getEmptyState,
reducer,
} from '../../../state/ducks/linkPreviews';
import type { LinkPreviewType } from '../../../types/message/LinkPreviews';
2021-04-27 22:35:35 +00:00
describe('both/state/ducks/linkPreviews', () => {
function getMockLinkPreview(): LinkPreviewType {
return {
title: 'Hello World',
domain: 'signal.org',
url: 'https://www.signal.org',
isStickerPack: false,
};
}
describe('addLinkPreview', () => {
const { addLinkPreview } = actions;
it('updates linkPreview', () => {
const state = getEmptyState();
const linkPreview = getMockLinkPreview();
2022-06-17 00:48:57 +00:00
const nextState = reducer(state, addLinkPreview(linkPreview, 0));
2021-04-27 22:35:35 +00:00
assert.strictEqual(nextState.linkPreview, linkPreview);
});
});
describe('removeLinkPreview', () => {
const { removeLinkPreview } = actions;
it('removes linkPreview', () => {
const state = {
...getEmptyState(),
linkPreview: getMockLinkPreview(),
};
const nextState = reducer(state, removeLinkPreview());
assert.isUndefined(nextState.linkPreview);
});
});
});