89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
|
|
import { jest } from '@jest/globals';
|
||
|
|
|
||
|
|
const { default: store } = await import('../../public/call/store.js');
|
||
|
|
|
||
|
|
function mediaState(overrides = {}) {
|
||
|
|
return {
|
||
|
|
audio: true,
|
||
|
|
video: true,
|
||
|
|
screenShare: false,
|
||
|
|
recording: false,
|
||
|
|
isSpeaking: false,
|
||
|
|
...overrides
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
function resetStore() {
|
||
|
|
store.role = 'host';
|
||
|
|
store.selfParticipantId = 'host';
|
||
|
|
store.renderstreaming = {
|
||
|
|
sendMessage: jest.fn()
|
||
|
|
};
|
||
|
|
store.state = {
|
||
|
|
session: {
|
||
|
|
duration: 0,
|
||
|
|
localUser: {
|
||
|
|
id: 'host-user',
|
||
|
|
name: 'Host',
|
||
|
|
avatar: '/images/p1.png',
|
||
|
|
mediaState: mediaState()
|
||
|
|
},
|
||
|
|
remoteUser: {
|
||
|
|
id: 'remote-user',
|
||
|
|
name: 'Remote',
|
||
|
|
avatar: '/images/p2.png',
|
||
|
|
status: 'online',
|
||
|
|
mediaState: mediaState()
|
||
|
|
}
|
||
|
|
},
|
||
|
|
participants: {
|
||
|
|
'participant-1': {
|
||
|
|
id: 'participant-user',
|
||
|
|
name: 'Participant',
|
||
|
|
avatar: '/images/p2.png',
|
||
|
|
mediaState: mediaState(),
|
||
|
|
status: 'online'
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
store.notify = jest.fn();
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('media-state-changed handling', () => {
|
||
|
|
beforeEach(() => {
|
||
|
|
resetStore();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('skips updates when participant media state is unchanged', () => {
|
||
|
|
store._handleMediaStateChangedMessage({
|
||
|
|
participantId: 'participant-1',
|
||
|
|
data: {
|
||
|
|
userId: 'participant-user',
|
||
|
|
...mediaState()
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(store.notify).not.toHaveBeenCalled();
|
||
|
|
expect(store.renderstreaming.sendMessage).not.toHaveBeenCalled();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('updates and broadcasts when participant media state changes', () => {
|
||
|
|
store._handleMediaStateChangedMessage({
|
||
|
|
participantId: 'participant-1',
|
||
|
|
data: {
|
||
|
|
userId: 'participant-user',
|
||
|
|
...mediaState({ audio: false })
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(store.state.participants['participant-1'].mediaState.audio).toBe(false);
|
||
|
|
expect(store.notify).toHaveBeenCalledWith({
|
||
|
|
type: 'PARTICIPANTS_UPDATE',
|
||
|
|
participants: store.state.participants
|
||
|
|
});
|
||
|
|
expect(store.renderstreaming.sendMessage).toHaveBeenCalledWith(expect.objectContaining({
|
||
|
|
type: 'participants-sync'
|
||
|
|
}));
|
||
|
|
});
|
||
|
|
});
|