Move message selector tests to the right place

This commit is contained in:
Evan Hahn 2021-06-29 19:51:57 -05:00 committed by GitHub
parent 92cbfc4437
commit 65ad608aa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 53 deletions

View file

@ -207,11 +207,15 @@ export function getPropsForBubble(
};
}
export function isIncoming(message: MessageAttributesType): boolean {
export function isIncoming(
message: Pick<MessageAttributesType, 'type'>
): boolean {
return message.type === 'incoming';
}
export function isOutgoing(message: MessageAttributesType): boolean {
export function isOutgoing(
message: Pick<MessageAttributesType, 'type'>
): boolean {
return message.type === 'outgoing';
}
@ -639,7 +643,9 @@ function getPropsForVerificationNotification(
// Group Update (V1)
export function isGroupUpdate(message: MessageAttributesType): boolean {
export function isGroupUpdate(
message: Pick<MessageAttributesType, 'group_update'>
): boolean {
return Boolean(message.group_update);
}
@ -725,7 +731,9 @@ function getPropsForGroupNotification(
// End Session
export function isEndSession(message: MessageAttributesType): boolean {
export function isEndSession(
message: Pick<MessageAttributesType, 'flags'>
): boolean {
const flag = window.textsecure.protobuf.DataMessage.Flags.END_SESSION;
// eslint-disable-next-line no-bitwise
return Boolean(message.flags && message.flags & flag);

View file

@ -1,16 +1,10 @@
// Copyright 2020 Signal Messenger, LLC
// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import { setup as setupI18n } from '../../../js/modules/i18n';
import enMessages from '../../../_locales/en/messages.json';
import {
isEndSession,
isGroupUpdate,
isIncoming,
isOutgoing,
} from '../../state/selectors/message';
describe('Message', () => {
const i18n = setupI18n('en', enMessages);
@ -124,37 +118,6 @@ describe('Message', () => {
});
});
describe('isIncoming', () => {
it('checks if is incoming message', () => {
const messages = new window.Whisper.MessageCollection();
let message = messages.add(attributes);
assert.notOk(isIncoming(message.attributes));
message = messages.add({ type: 'incoming' });
assert.ok(isIncoming(message.attributes));
});
});
describe('isOutgoing', () => {
it('checks if is outgoing message', () => {
const messages = new window.Whisper.MessageCollection();
let message = messages.add(attributes);
assert.ok(isOutgoing(message.attributes));
message = messages.add({ type: 'incoming' });
assert.notOk(isOutgoing(message.attributes));
});
});
describe('isGroupUpdate', () => {
it('checks if is group update', () => {
const messages = new window.Whisper.MessageCollection();
let message = messages.add(attributes);
assert.notOk(isGroupUpdate(message.attributes));
message = messages.add({ group_update: { left: 'You' } });
assert.ok(isGroupUpdate(message.attributes));
});
});
// Note that some of this method's behavior is untested:
// - Call history
// - Contacts
@ -554,17 +517,6 @@ describe('Message', () => {
);
});
});
describe('isEndSession', () => {
it('checks if it is end of the session', () => {
const messages = new window.Whisper.MessageCollection();
let message = messages.add(attributes);
assert.notOk(isEndSession(message.attributes));
message = messages.add({ type: 'incoming', source, flags: true });
assert.ok(isEndSession(message.attributes));
});
});
});
describe('MessageCollection', () => {

View file

@ -0,0 +1,52 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import {
isEndSession,
isGroupUpdate,
isIncoming,
isOutgoing,
} from '../../../state/selectors/message';
describe('state/selectors/messages', () => {
describe('isEndSession', () => {
it('checks if it is end of the session', () => {
assert.isFalse(isEndSession({}));
assert.isFalse(isEndSession({ flags: undefined }));
assert.isFalse(isEndSession({ flags: 0 }));
assert.isFalse(isEndSession({ flags: 2 }));
assert.isFalse(isEndSession({ flags: 4 }));
assert.isTrue(isEndSession({ flags: 1 }));
});
});
describe('isGroupUpdate', () => {
it('checks if is group update', () => {
assert.isFalse(isGroupUpdate({}));
assert.isFalse(isGroupUpdate({ group_update: undefined }));
assert.isTrue(isGroupUpdate({ group_update: { left: 'You' } }));
});
});
describe('isIncoming', () => {
it('checks if is incoming message', () => {
assert.isFalse(isIncoming({ type: 'outgoing' }));
assert.isFalse(isIncoming({ type: 'call-history' }));
assert.isTrue(isIncoming({ type: 'incoming' }));
});
});
describe('isOutgoing', () => {
it('checks if is outgoing message', () => {
assert.isFalse(isOutgoing({ type: 'incoming' }));
assert.isFalse(isOutgoing({ type: 'call-history' }));
assert.isTrue(isOutgoing({ type: 'outgoing' }));
});
});
});