Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
liliakai committed Apr 13, 2017
1 parent dcfc470 commit d0448ec
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions test/_test.js
Expand Up @@ -45,6 +45,7 @@ window.assert = chai.assert;
window.Whisper = window.Whisper || {};
window.Whisper.Database = window.Whisper.Database || {};
Whisper.Database.id = 'test';
Whisper.events = _.clone(Backbone.Events);

/*
* global helpers for tests
Expand Down
14 changes: 10 additions & 4 deletions test/index.html
Expand Up @@ -487,23 +487,30 @@ <h3>{{ sync }}</h3>


<script type='text/x-tmpl-mustache' id='networkStatus'>
<div class='network-status-message' style='{{^instructions}}margin-top:3px;{{/instructions}}{{#instructions}}margin-top:-6px{{/instructions}}'>
<h3 style='{{^instructions}}font-size:17px;{{/instructions}}'>{{ message }}</h3>
<div class='network-status-message'>
<h3>{{ message }}</h3>
<span>{{ instructions }}</span>
</div>
{{ #reconnectDurationAsSeconds }}
<div class="network-status-message">
{{ attemptingReconnectionMessage }}
</div>
{{/reconnectDurationAsSeconds }}
{{ #action }}
<div class="action">
<button class='small blue {{ buttonClass }}'>{{ action }}</button>
</div>
{{/action }}
</script>


<script type="text/javascript" src="../js/components.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="blanket_mocha.js"></script>

<script type='text/javascript' src='../js/registration.js'></script>
<script type="text/javascript" src="../js/expire.js"></script>
<script type="text/javascript" src="../js/chromium.js"></script>
<script type="text/javascript" src="../js/components.js"></script>
<script type="text/javascript" src="../js/database.js"></script>
<script type="text/javascript" src="../js/storage.js"></script>
<script type="text/javascript" src="../js/signal_protocol_store.js"></script>
Expand Down Expand Up @@ -542,7 +549,6 @@ <h3 style='{{^instructions}}font-size:17px;{{/instructions}}'>{{ message }}</h3>
<script type='text/javascript' src='../js/views/conversation_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/conversation_search_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/hint_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/network_status_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/inbox_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/network_status_view.js'></script>
<script type='text/javascript' src='../js/views/confirmation_dialog_view.js' data-cover></script>
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Expand Up @@ -12257,6 +12257,7 @@ window.assert = chai.assert;
window.Whisper = window.Whisper || {};
window.Whisper.Database = window.Whisper.Database || {};
Whisper.Database.id = 'test';
Whisper.events = _.clone(Backbone.Events);

/*
* global helpers for tests
Expand Down
49 changes: 43 additions & 6 deletions test/views/network_status_view_test.js
Expand Up @@ -11,6 +11,7 @@ describe('NetworkStatusView', function() {
before(function() {
oldGetSocketStatus = window.getSocketStatus;
/* chrome i18n support is missing in 'regular' webpages */
window.chrome = window.chrome || {};
window.chrome.i18n = { getMessage: function(message, args) {
// translationMessageName-arg1-arg2
return _([message, args]).chain().flatten().compact().value().join('-');
Expand Down Expand Up @@ -41,13 +42,13 @@ describe('NetworkStatusView', function() {
networkStatusView.navigatorOnLine = function() { return false; };
});
it('should be interrupted', function() {
networkStatusView.render();
networkStatusView.update();
var status = networkStatusView.getNetworkStatus();
assert(status.hasInterruption);
assert.equal(status.instructions, "checkNetworkConnection");
});
it('should display an offline message', function() {
networkStatusView.render();
networkStatusView.update();
assert.match(networkStatusView.$el.text(), /offline/);
});
it('should override socket status', function() {
Expand All @@ -56,15 +57,51 @@ describe('NetworkStatusView', function() {
WebSocket.CLOSING,
WebSocket.CLOSED]).map(function(socketStatusVal) {
socketStatus = socketStatusVal;
networkStatusView.render();
networkStatusView.update();
assert.match(networkStatusView.$el.text(), /offline/);
});
});
it('should override registration status', function() {
Whisper.Registration.remove();
networkStatusView.update();
assert.match(networkStatusView.$el.text(), /offline/);
});
});
describe('network status when registration is not done', function() {
beforeEach(function() {
Whisper.Registration.remove();
});
it('should display an unlinked message', function() {
networkStatusView.update();
assert.match(networkStatusView.$el.text(), /unlinked/);
});
it('should override socket status', function() {
_([WebSocket.CONNECTING,
WebSocket.OPEN,
WebSocket.CLOSING,
WebSocket.CLOSED]).map(function(socketStatusVal) {
socketStatus = socketStatusVal;
networkStatusView.update();
assert.match(networkStatusView.$el.text(), /unlinked/);
});
});
});
describe('network status when registration is done', function() {
beforeEach(function() {
networkStatusView.navigatorOnLine = function() { return true; };
Whisper.Registration.markDone();
networkStatusView.update();
});
it('should not display an unlinked message', function() {
networkStatusView.update();
assert.notMatch(networkStatusView.$el.text(), /unlinked/);
});
});
describe('network status when socket is connecting', function() {
beforeEach(function() {
Whisper.Registration.markDone();
socketStatus = WebSocket.CONNECTING;
networkStatusView.render();
networkStatusView.update();
});
it('it should display a connecting string if connecting and not in the connecting grace period', function() {
networkStatusView.withinConnectingGracePeriod = false;
Expand Down Expand Up @@ -100,7 +137,7 @@ describe('NetworkStatusView', function() {
_([WebSocket.CLOSED, WebSocket.CLOSING]).map(function(socketStatusVal) {
it('should be interrupted', function() {
socketStatus = socketStatusVal;
networkStatusView.render();
networkStatusView.update();
var status = networkStatusView.getNetworkStatus();
assert(status.hasInterruption);
});
Expand All @@ -111,7 +148,7 @@ describe('NetworkStatusView', function() {
beforeEach(function() {
socketStatus = WebSocket.CLOSED;
networkStatusView.setSocketReconnectInterval(61000);
networkStatusView.render();
networkStatusView.update();
});
it('should format the message based on the socketReconnectWaitDuration property', function() {
assert.equal(networkStatusView.socketReconnectWaitDuration.asSeconds(), 61);
Expand Down

0 comments on commit d0448ec

Please sign in to comment.