Skip to content

Commit

Permalink
Move message selector tests to the right place
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Jun 30, 2021
1 parent 92cbfc4 commit 65ad608
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 53 deletions.
16 changes: 12 additions & 4 deletions ts/state/selectors/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
50 changes: 1 addition & 49 deletions ts/test-electron/models/messages_test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down
52 changes: 52 additions & 0 deletions ts/test-electron/state/selectors/messages_test.ts
Original file line number Diff line number Diff line change
@@ -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' }));
});
});
});

0 comments on commit 65ad608

Please sign in to comment.