Fix tests

pull/382/head
Beaudan 6 years ago
parent 7dd155eb16
commit ccfc9046b4

@ -46,7 +46,7 @@
getSocketStatus() { getSocketStatus() {
return window.getSocketStatus(); return window.getSocketStatus();
}, },
getNetworkStatus() { getNetworkStatus(shortCircuit = false) {
let message = ''; let message = '';
let instructions = ''; let instructions = '';
let hasInterruption = false; let hasInterruption = false;
@ -67,26 +67,28 @@
this.connectedTimer = null; this.connectedTimer = null;
break; break;
case WebSocket.CLOSED: case WebSocket.CLOSED:
if (!this.connectedTimer) { // Intentional fallthrough
// Mark offline if disconnected for 30 seconds
this.connectedTimer = window.setTimeout(() => {
message = i18n('disconnected');
instructions = i18n('checkNetworkConnection');
hasInterruption = true;
}, DISCONNECTED_DELAY);
}
break;
case WebSocket.CLOSING: case WebSocket.CLOSING:
default: // Intentional fallthrough
default: {
const markOffline = () => {
message = i18n('disconnected');
instructions = i18n('checkNetworkConnection');
hasInterruption = true;
};
if (shortCircuit) {
// Used to skip the timer for testing
markOffline();
break;
}
if (!this.connectedTimer) { if (!this.connectedTimer) {
// Mark offline if disconnected for 30 seconds // Mark offline if disconnected for 30 seconds
this.connectedTimer = window.setTimeout(() => { this.connectedTimer = window.setTimeout(() => {
message = i18n('disconnected'); markOffline();
instructions = i18n('checkNetworkConnection');
hasInterruption = true;
}, DISCONNECTED_DELAY); }, DISCONNECTED_DELAY);
} }
break; break;
}
} }
if ( if (

@ -153,7 +153,8 @@ describe('NetworkStatusView', () => {
it('should be interrupted', () => { it('should be interrupted', () => {
socketStatus = socketStatusVal; socketStatus = socketStatusVal;
networkStatusView.update(); networkStatusView.update();
const status = networkStatusView.getNetworkStatus(); const shortCircuit = true;
const status = networkStatusView.getNetworkStatus(shortCircuit);
assert(status.hasInterruption); assert(status.hasInterruption);
}); });
}); });

Loading…
Cancel
Save