Mailspring/packages/client-app/internal_packages/sync-health-checker/spec/sync-health-checker-spec.es6
Halla Moore 4ad4596e2f [client-app, client-sync] Add specs for detecting stuck sync/worker window
Summary: See title. Part of T7681.

Test Plan: ran the specs

Reviewers: evan, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D4264
2017-03-27 15:45:33 -07:00

45 lines
1.3 KiB
JavaScript

import {ipcRenderer} from 'electron'
import SyncHealthChecker from '../lib/sync-health-checker'
const requestWithErrorResponse = () => {
return {
run: async () => {
throw new Error('ECONNREFUSED');
},
}
}
const activityData = {account1: {time: 1490305104619, activity: ['activity']}}
const requestWithDataResponse = () => {
return {
run: async () => {
return activityData
},
}
}
describe('SyncHealthChecker', () => {
describe('when the worker window is not available', () => {
beforeEach(() => {
spyOn(SyncHealthChecker, '_buildRequest').andCallFake(requestWithErrorResponse)
spyOn(ipcRenderer, 'send')
spyOn(NylasEnv, 'reportError')
})
it('attempts to restart it', async () => {
await SyncHealthChecker._checkSyncHealth();
expect(NylasEnv.reportError.calls.length).toEqual(1)
expect(ipcRenderer.send.calls[0].args[0]).toEqual('ensure-worker-window')
})
})
describe('when data is returned', () => {
beforeEach(() => {
spyOn(SyncHealthChecker, '_buildRequest').andCallFake(requestWithDataResponse)
})
it('stores the data', async () => {
await SyncHealthChecker._checkSyncHealth();
expect(SyncHealthChecker._lastSyncActivity).toEqual(activityData)
})
})
})