Voice notes mini-player
This commit is contained in:
parent
b5849f872a
commit
0e655ceeed
45 changed files with 1599 additions and 487 deletions
|
@ -3,8 +3,6 @@
|
|||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import type { SetMessageAudioAction } from '../../../state/ducks/audioPlayer';
|
||||
import type { SelectedConversationChangedActionType } from '../../../state/ducks/conversations';
|
||||
import {
|
||||
SELECTED_CONVERSATION_CHANGED,
|
||||
actions as conversationsActions,
|
||||
|
@ -13,24 +11,35 @@ import { noopAction } from '../../../state/ducks/noop';
|
|||
|
||||
import type { StateType } from '../../../state/reducer';
|
||||
import { reducer as rootReducer } from '../../../state/reducer';
|
||||
import type { SelectedConversationChangedActionType } from '../../../state/ducks/conversations';
|
||||
import { actions } from '../../../state/ducks/audioPlayer';
|
||||
import type { VoiceNoteAndConsecutiveForPlayback } from '../../../state/selectors/audioPlayer';
|
||||
|
||||
const { messageDeleted, messageChanged } = conversationsActions;
|
||||
|
||||
const MESSAGE_ID = 'message-id';
|
||||
|
||||
// can't use the actual action since it's a ThunkAction
|
||||
const setMessageAudio = (
|
||||
id: string,
|
||||
context: string
|
||||
): SetMessageAudioAction => ({
|
||||
type: 'audioPlayer/SET_MESSAGE_AUDIO',
|
||||
payload: {
|
||||
id,
|
||||
context,
|
||||
function voiceNoteDataForMessage(
|
||||
messageId: string
|
||||
): VoiceNoteAndConsecutiveForPlayback {
|
||||
return {
|
||||
conversationId: 'convo',
|
||||
voiceNote: {
|
||||
id: messageId,
|
||||
type: 'outgoing',
|
||||
timestamp: 0,
|
||||
url: undefined,
|
||||
source: undefined,
|
||||
sourceUuid: undefined,
|
||||
messageIdForLogging: messageId,
|
||||
isPlayed: false,
|
||||
},
|
||||
consecutiveVoiceNotes: [],
|
||||
previousMessageId: undefined,
|
||||
nextMessageTimestamp: undefined,
|
||||
playbackRate: 1,
|
||||
duration: 100,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
describe('both/state/ducks/audioPlayer', () => {
|
||||
const getEmptyRootState = (): StateType => {
|
||||
|
@ -39,26 +48,51 @@ describe('both/state/ducks/audioPlayer', () => {
|
|||
|
||||
const getInitializedState = (): StateType => {
|
||||
const state = getEmptyRootState();
|
||||
const updated = rootReducer(state, setMessageAudio(MESSAGE_ID, 'context'));
|
||||
const updated = rootReducer(
|
||||
state,
|
||||
actions.loadMessageAudio({
|
||||
voiceNoteData: voiceNoteDataForMessage(MESSAGE_ID),
|
||||
position: 0,
|
||||
context: 'context',
|
||||
ourConversationId: 'convo',
|
||||
})
|
||||
);
|
||||
|
||||
assert.strictEqual(updated.audioPlayer.active?.id, MESSAGE_ID);
|
||||
assert.strictEqual(updated.audioPlayer.active?.context, 'context');
|
||||
assert.strictEqual(
|
||||
updated.audioPlayer.active?.content?.current.id,
|
||||
MESSAGE_ID
|
||||
);
|
||||
assert.strictEqual(updated.audioPlayer.active?.content?.context, 'context');
|
||||
|
||||
return updated;
|
||||
};
|
||||
|
||||
describe('setActiveAudioID', () => {
|
||||
it("updates `activeAudioID` in the audioPlayer's state", () => {
|
||||
describe('loadMessageAudio', () => {
|
||||
it("updates `active` in the audioPlayer's state", () => {
|
||||
const state = getEmptyRootState();
|
||||
assert.strictEqual(state.audioPlayer.active, undefined);
|
||||
|
||||
const updated = rootReducer(state, setMessageAudio('test', 'context'));
|
||||
assert.strictEqual(updated.audioPlayer.active?.id, 'test');
|
||||
assert.strictEqual(updated.audioPlayer.active?.context, 'context');
|
||||
const updated = rootReducer(
|
||||
state,
|
||||
actions.loadMessageAudio({
|
||||
voiceNoteData: voiceNoteDataForMessage('test'),
|
||||
position: 0,
|
||||
context: 'context',
|
||||
ourConversationId: 'convo',
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
updated.audioPlayer.active?.content?.current.id,
|
||||
'test'
|
||||
);
|
||||
assert.strictEqual(
|
||||
updated.audioPlayer.active?.content?.context,
|
||||
'context'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('resets activeAudioID when changing the conversation', () => {
|
||||
it('active is not changed when changing the conversation', () => {
|
||||
const state = getInitializedState();
|
||||
|
||||
const updated = rootReducer(state, <SelectedConversationChangedActionType>{
|
||||
|
@ -66,10 +100,13 @@ describe('both/state/ducks/audioPlayer', () => {
|
|||
payload: { id: 'any' },
|
||||
});
|
||||
|
||||
assert.strictEqual(updated.audioPlayer.active, undefined);
|
||||
assert.strictEqual(
|
||||
updated.audioPlayer.active?.content?.current.id,
|
||||
MESSAGE_ID
|
||||
);
|
||||
});
|
||||
|
||||
it('resets activeAudioID when message was deleted', () => {
|
||||
it('resets active.content when message was deleted', () => {
|
||||
const state = getInitializedState();
|
||||
|
||||
const updated = rootReducer(
|
||||
|
@ -77,10 +114,10 @@ describe('both/state/ducks/audioPlayer', () => {
|
|||
messageDeleted(MESSAGE_ID, 'conversation-id')
|
||||
);
|
||||
|
||||
assert.strictEqual(updated.audioPlayer.active, undefined);
|
||||
assert.strictEqual(updated.audioPlayer.active?.content, undefined);
|
||||
});
|
||||
|
||||
it('resets activeAudioID when message was erased', () => {
|
||||
it('resets active.content when message is DOE', () => {
|
||||
const state = getInitializedState();
|
||||
|
||||
const updated = rootReducer(
|
||||
|
@ -97,6 +134,6 @@ describe('both/state/ducks/audioPlayer', () => {
|
|||
})
|
||||
);
|
||||
|
||||
assert.strictEqual(updated.audioPlayer.active, undefined);
|
||||
assert.strictEqual(updated.audioPlayer.active?.content, undefined);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue