2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-06-29 19:58:29 +00:00
|
|
|
// 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';
|
2021-06-29 19:58:29 +00:00
|
|
|
import { isPaused } from '../../../state/selectors/audioPlayer';
|
2023-02-24 23:18:57 +00:00
|
|
|
import { actions } from '../../../state/ducks/audioPlayer';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../../../state/reducer';
|
|
|
|
import { reducer as rootReducer } from '../../../state/reducer';
|
2021-06-29 19:58:29 +00:00
|
|
|
|
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,
|
2022-09-15 20:10:46 +00:00
|
|
|
playbackRate: 1,
|
2023-02-24 23:18:57 +00:00
|
|
|
};
|
|
|
|
}
|
2022-09-15 20:10:46 +00:00
|
|
|
|
2021-06-29 19:58:29 +00:00
|
|
|
describe('state/selectors/audioPlayer', () => {
|
|
|
|
const getEmptyRootState = (): StateType => {
|
|
|
|
return rootReducer(undefined, noopAction());
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('isPaused', () => {
|
2022-09-15 20:10:46 +00:00
|
|
|
it('returns true if state.audioPlayer.active is undefined', () => {
|
2021-06-29 19:58:29 +00:00
|
|
|
const state = getEmptyRootState();
|
|
|
|
assert.isTrue(isPaused(state));
|
|
|
|
});
|
|
|
|
|
2022-09-15 20:10:46 +00:00
|
|
|
it('returns false if state.audioPlayer.active is not undefined', () => {
|
2021-06-29 19:58:29 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
);
|
2021-06-29 19:58:29 +00:00
|
|
|
|
|
|
|
assert.isFalse(isPaused(updated));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|