98 lines
2.3 KiB
JavaScript

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'
import TestUtils from 'react-dom/test-utils'
import configureStore from 'redux-mock-store'
import reducers from '../reducers'
import { Provider } from 'react-redux'
import { init } from '../actions/CallActions.js'
import { middlewares } from '../store.js'
describe('App', () => {
const initAction = { type: 'INIT' }
let state
beforeEach(() => {
init.mockReturnValue(initAction)
state = reducers()
})
let component, node, store
function render() {
store = configureStore(middlewares)(state)
component = TestUtils.renderIntoDocument(
<Provider store={store}>
<App />
</Provider>
)
node = ReactDOM.findDOMNode(component)
}
describe('render', () => {
it('renders without issues', () => {
render()
expect(node).toBeTruthy()
expect(init.mock.calls.length).toBe(1)
})
})
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' }
}])
})
})
})
})