signal-desktop/ts/test-electron/state/selectors/audioPlayer_test.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { noopAction } from '../../../state/ducks/noop';
2023-02-24 23:18:57 +00:00
import type { VoiceNoteAndConsecutiveForPlayback } from '../../../state/selectors/audioPlayer';
import { isPaused } from '../../../state/selectors/audioPlayer';
2023-02-24 23:18:57 +00:00
import { actions } from '../../../state/ducks/audioPlayer';
import type { StateType } from '../../../state/reducer';
import { reducer as rootReducer } from '../../../state/reducer';
2023-02-24 23:18:57 +00:00
function voiceNoteDataForMessage(
messageId: string
): VoiceNoteAndConsecutiveForPlayback {
return {
conversationId: 'convo',
voiceNote: {
id: messageId,
type: 'outgoing',
timestamp: 0,
url: undefined,
source: undefined,
2023-08-16 20:54:39 +00:00
sourceServiceId: undefined,
2023-02-24 23:18:57 +00:00
messageIdForLogging: messageId,
isPlayed: false,
},
consecutiveVoiceNotes: [],
previousMessageId: undefined,
nextMessageTimestamp: undefined,
playbackRate: 1,
2023-02-24 23:18:57 +00:00
};
}
describe('state/selectors/audioPlayer', () => {
const getEmptyRootState = (): StateType => {
return rootReducer(undefined, noopAction());
};
describe('isPaused', () => {
it('returns true if state.audioPlayer.active is undefined', () => {
const state = getEmptyRootState();
assert.isTrue(isPaused(state));
});
it('returns false if state.audioPlayer.active is not undefined', () => {
const state = getEmptyRootState();
2023-02-24 23:18:57 +00:00
const updated = rootReducer(
state,
2023-03-02 20:55:40 +00:00
actions.loadVoiceNoteAudio({
2023-02-24 23:18:57 +00:00
voiceNoteData: voiceNoteDataForMessage('id'),
position: 0,
context: 'context',
ourConversationId: 'convo',
2023-03-02 20:55:40 +00:00
playbackRate: 1,
2023-02-24 23:18:57 +00:00
})
);
assert.isFalse(isPaused(updated));
});
});
});