diff --git a/src/client/__tests__/App-test.js b/src/client/__tests__/App-test.js index a6d5592..abc5ecd 100644 --- a/src/client/__tests__/App-test.js +++ b/src/client/__tests__/App-test.js @@ -2,6 +2,7 @@ jest.mock('../actions/CallActions.js') jest.mock('../callId.js') jest.mock('../iceServers.js') +import * as constants from '../constants.js' import App from '../containers/App.js' import React from 'react' import ReactDOM from 'react-dom' @@ -14,9 +15,11 @@ import { middlewares } from '../store.js' describe('App', () => { + const initAction = { type: 'INIT' } + let state beforeEach(() => { - init.mockReturnValue({ type: 'INIT' }) + init.mockReturnValue(initAction) state = reducers() }) @@ -39,4 +42,56 @@ describe('App', () => { }) }) + describe('state', () => { + let alert + beforeEach(() => { + state.streams = state.streams.setIn(['all'], { + 'test': { + userId: 'test', + url: 'blob://' + } + }) + state.notifications = state.notifications.merge({ + 'notification1': { + id: 'notification1', + message: 'test', + type: 'warning' + } + }) + const alerts = state.alerts.asMutable() + alert = { + dismissable: true, + action: 'Dismiss', + message: 'test alert' + } + alerts.push(alert) + state.alerts = alerts + render() + store.clearActions() + }) + + describe('alerts', () => { + it('can be dismissed', () => { + const dismiss = node.querySelector('.action-alert-dismiss') + TestUtils.Simulate.click(dismiss) + expect(store.getActions()).toEqual([{ + type: constants.ALERT_DISMISS, + payload: alert + }]) + }) + }) + + describe('video', () => { + it('can be activated', () => { + const video = node.querySelector('video') + TestUtils.Simulate.click(video) + expect(store.getActions()).toEqual([{ + type: constants.STREAM_ACTIVATE, + payload: { userId: 'test' } + }]) + }) + }) + + }) + }) diff --git a/src/client/__tests__/store-test.js b/src/client/__tests__/store-test.js new file mode 100644 index 0000000..c7328be --- /dev/null +++ b/src/client/__tests__/store-test.js @@ -0,0 +1,11 @@ +window.localStorage = { debug: true } +import logger from 'redux-logger' +const store = require('../store.js') + +describe('store', () => { + + it('should load logger middleware', () => { + expect(store.middlewares.some(m => m === logger)).toBeTruthy() + }) + +}) diff --git a/src/client/actions/CallActions.js b/src/client/actions/CallActions.js index 4ef22f0..1aa1846 100644 --- a/src/client/actions/CallActions.js +++ b/src/client/actions/CallActions.js @@ -1,3 +1,4 @@ +import * as StreamActions from './StreamActions.js' import * as NotifyActions from './NotifyActions.js' import * as constants from '../constants.js' import Promise from 'bluebird' @@ -34,7 +35,7 @@ export const connect = () => dispatch => { export const getCameraStream = () => dispatch => { return getUserMedia({ video: true, audio: true }) .then(stream => { - dispatch(addStream({ stream, userId: constants.ME })) + dispatch(StreamActions.addStream({ stream, userId: constants.ME })) return stream }) .catch(err => { @@ -42,21 +43,3 @@ export const getCameraStream = () => dispatch => { throw err }) } - -export const addStream = ({ stream, userId }) => ({ - type: constants.STREAM_ADD, - payload: { - userId, - stream - } -}) - -export const removeStream = userId => ({ - type: constants.STREAM_REMOVE, - payload: { userId } -}) - -export const activateStream = userId => ({ - type: constants.STREAM_ACTIVATE, - payload: { userId } -}) diff --git a/src/client/actions/NotifyActions.js b/src/client/actions/NotifyActions.js index 72ff674..43f4095 100644 --- a/src/client/actions/NotifyActions.js +++ b/src/client/actions/NotifyActions.js @@ -1,5 +1,5 @@ import * as constants from '../constants.js' -import Immutable from 'seamless-immutable' +import _ from 'underscore' const TIMEOUT = 5000 @@ -12,7 +12,8 @@ function format (string, args) { const _notify = (type, args) => dispatch => { let string = args[0] || '' let message = format(string, Array.prototype.slice.call(args, 1)) - const payload = Immutable({ type, message }) + const id = _.uniqueId('notification') + const payload = { id, type, message } dispatch({ type: constants.NOTIFY, payload @@ -20,7 +21,7 @@ const _notify = (type, args) => dispatch => { setTimeout(() => { dispatch({ type: constants.NOTIFY_DISMISS, - payload + payload: { id } }) }, TIMEOUT) } diff --git a/src/client/actions/StreamActions.js b/src/client/actions/StreamActions.js new file mode 100644 index 0000000..2499448 --- /dev/null +++ b/src/client/actions/StreamActions.js @@ -0,0 +1,19 @@ +import * as constants from '../constants.js' + +export const addStream = ({ stream, userId }) => ({ + type: constants.STREAM_ADD, + payload: { + userId, + stream + } +}) + +export const removeStream = userId => ({ + type: constants.STREAM_REMOVE, + payload: { userId } +}) + +export const activateStream = userId => ({ + type: constants.STREAM_ACTIVATE, + payload: { userId } +}) diff --git a/src/client/actions/__tests__/CallActions-test.js b/src/client/actions/__tests__/CallActions-test.js index 3e7b865..a10373f 100644 --- a/src/client/actions/__tests__/CallActions-test.js +++ b/src/client/actions/__tests__/CallActions-test.js @@ -38,6 +38,7 @@ describe('reducers/alerts', () => { }, { type: constants.NOTIFY, payload: { + id: jasmine.any(String), message: 'Connected to server socket', type: 'warning' } @@ -62,12 +63,14 @@ describe('reducers/alerts', () => { }, { type: constants.NOTIFY, payload: { + id: jasmine.any(String), message: 'Connected to server socket', type: 'warning' } }, { type: constants.NOTIFY, payload: { + id: jasmine.any(String), message: 'Server socket disconnected', type: 'error' } diff --git a/src/client/components/Alerts.js b/src/client/components/Alerts.js index 685065b..78a6d8a 100644 --- a/src/client/components/Alerts.js +++ b/src/client/components/Alerts.js @@ -18,13 +18,16 @@ export class Alert extends React.Component { dismiss(alert) } render () { - const { alert, dismiss } = this.props + const { alert } = this.props return (
{alert.message} {alert.dismissable && ( - + )}
) diff --git a/src/client/components/App.js b/src/client/components/App.js index 86f14f0..81a2169 100644 --- a/src/client/components/App.js +++ b/src/client/components/App.js @@ -34,6 +34,7 @@ export default class App extends React.Component {