Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Commit

Permalink
Moving to cleaner stubs and move to using sw-testing-helpers for in b…
Browse files Browse the repository at this point in the history
…rowser methods
  • Loading branch information
Matt Gaunt committed Apr 1, 2016
1 parent 49875fd commit 22544bc
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 194 deletions.
13 changes: 8 additions & 5 deletions test/browser-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
<script src="/node_modules/chai/chai.js"></script>
<script src="/node_modules/mocha/mocha.js"></script>
<script src="/node_modules/sinon/pkg/sinon.js"></script>
<script src="/node_modules/sw-testing-helpers/src/in-browser-helpers/sw-utils.js"></script>

<!-- Helper functions will be under window.testHelper -->
<script src="/test/libs/helper-functions.js"></script>
<script src="/test/libs/state-stub.js"></script>
<script src="/test/libs/is-supported.js"></script>
<script src="/test/libs/stubs/base-stub.js"></script>
<script src="/test/libs/stubs/firefox-stub.js"></script>
<script src="/test/libs/stubs/full-stub.js"></script>
<script src="/test/libs/state-stub-singleton.js"></script>

<script>mocha.setup({
ui: 'bdd'
Expand Down Expand Up @@ -91,12 +94,12 @@
// We unregister all service workers, clear all caches and remove
// All registered iframes
beforeEach(function() {
return testHelper.cleanState();
return window.goog.SWHelper.cleanState();
});

// Clean up after the final test has finished
after(function() {
return testHelper.cleanState();
return window.goog.SWHelper.cleanState();
});

mocha.checkLeaks();
Expand Down
6 changes: 3 additions & 3 deletions test/browser-tests/push-client/get-permission-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Test getPermissionState()', function() {
});

it('should return permission status of granted', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');

return window.goog.propel.PropelClient.getPermissionState()
Expand All @@ -52,7 +52,7 @@ describe('Test getPermissionState()', function() {
});

it('should return permission status of default', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');

return window.goog.propel.PropelClient.getPermissionState()
Expand All @@ -62,7 +62,7 @@ describe('Test getPermissionState()', function() {
});

it('should return permission status of denied', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');

return window.goog.propel.PropelClient.getPermissionState()
Expand Down
4 changes: 2 additions & 2 deletions test/browser-tests/push-client/get-registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Test getRegistration()', function() {
});

it('should reject due to a bad registration', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();

const pushClient = new window.goog.propel.PropelClient('/non-existant/sw.js');
pushClient.getRegistration()
Expand All @@ -57,7 +57,7 @@ describe('Test getRegistration()', function() {
});

it('should resolve with a registration', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setUpRegistration(null);

const pushClient = new window.goog.propel.PropelClient(EMPTY_SW_PATH);
Expand Down
8 changes: 3 additions & 5 deletions test/browser-tests/push-client/get-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Test getSubscription()', function() {
});

it('should return null when the user isn\'t subscribed', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setUpRegistration(null);

const pushClient = new window.goog.propel.PropelClient(EMPTY_SW_PATH);
Expand All @@ -58,7 +58,7 @@ describe('Test getSubscription()', function() {
});

it('should return a subscription when the user is subscribed', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand All @@ -77,9 +77,7 @@ describe('Test getSubscription()', function() {
});

it('should manage a failing pushManager.getSubscription() call', function(done) {
stateStub = new window.StateStub({
forceStub: true
});
stateStub = window.StateStub.getStub(true);
// Empty function will caused an error to be throw
stateStub.setUpRegistration();

Expand Down
18 changes: 7 additions & 11 deletions test/browser-tests/push-client/request-permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ describe('Test requestPermission()', function() {

// We can't surpress a dialog after requesting it so force stub
it('should dispatch a \'requestingpermission\' event when the permission state is default', function(done) {
stateStub = new window.StateStub({
forceStub: true
});
stateStub = window.StateStub.getStub(true);
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand All @@ -59,9 +57,7 @@ describe('Test requestPermission()', function() {

// We can't surpress a dialog after requesting it so force stub
it('should resolve to default', function() {
stateStub = new window.StateStub({
forceStub: true
});
stateStub = window.StateStub.getStub(true);
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand All @@ -73,7 +69,7 @@ describe('Test requestPermission()', function() {
});

it('should not dispatch a \'requestingpermission\' event because permission is granted', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(null);

Expand All @@ -86,7 +82,7 @@ describe('Test requestPermission()', function() {
});

it('should resolve to permission state of granted', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(null);

Expand All @@ -98,7 +94,7 @@ describe('Test requestPermission()', function() {
});

it('should not dispatch a \'requestingpermission\' event because permission is blocked', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');
stateStub.setUpRegistration(null);

Expand All @@ -111,7 +107,7 @@ describe('Test requestPermission()', function() {
});

it('should resolve to blocked', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');
stateStub.setUpRegistration(null);

Expand All @@ -123,7 +119,7 @@ describe('Test requestPermission()', function() {
});

it('should dispatch a \'statuschange\' event when called directly', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(null);

Expand Down
8 changes: 4 additions & 4 deletions test/browser-tests/push-client/status-change-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Test \'statuschange\' event', function() {
});

it('should dispatch a \'statuschange\' event when the constructor is created (permission: default, subscription: null)', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand All @@ -63,7 +63,7 @@ describe('Test \'statuschange\' event', function() {
});

it('should dispatch a \'statuschange\' event when the constructor is created (permission: blocked, subscription: null)', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');
stateStub.setUpRegistration(null);

Expand All @@ -79,7 +79,7 @@ describe('Test \'statuschange\' event', function() {
});

it('should dispatch a \'statuschange\' event when the constructor is created (permission: granted, subscription: null)', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(null);

Expand All @@ -95,7 +95,7 @@ describe('Test \'statuschange\' event', function() {
});

it('should dispatch a \'statuschange\' event when the constructor is created (permission: granted, subscription: {STUBBED})', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand Down
16 changes: 6 additions & 10 deletions test/browser-tests/push-client/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ describe('Test subscribe()', function() {
});

it('should return an error that the user dismissed the notification', function(done) {
stateStub = new window.StateStub({
forceStub: true
});
stateStub = window.StateStub.getStub(true);
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand All @@ -65,7 +63,7 @@ describe('Test subscribe()', function() {
});

it('should dispatch a status event if the notification permission is blocked', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');
stateStub.setUpRegistration(null);

Expand All @@ -90,7 +88,7 @@ describe('Test subscribe()', function() {
});

it('should reject the promise with an error that the user has blocked notifications', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('denied');
stateStub.setUpRegistration(null);

Expand All @@ -106,7 +104,7 @@ describe('Test subscribe()', function() {
});

it('should dispatch a status event with the subscription when the permission is granted', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand All @@ -131,7 +129,7 @@ describe('Test subscribe()', function() {
});

it('should resolve the promise with a subscription when notifications are granted', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand All @@ -148,9 +146,7 @@ describe('Test subscribe()', function() {
});

it('should dispath events in order, requestingpermission, requestingsubscription and statuschange', function(done) {
stateStub = new window.StateStub({
forceStub: false
});
stateStub = window.StateStub.getStub(true);
stateStub.setPermissionState('default');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand Down
12 changes: 6 additions & 6 deletions test/browser-tests/push-client/unsubscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Test unsubscribe()', function() {
});

it('should unsubscribe the current subscription', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand All @@ -65,7 +65,7 @@ describe('Test unsubscribe()', function() {
});

it('should unsubscribe the current subscription and dispatch a statuschange event', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('granted');
stateStub.setUpRegistration(EXAMPLE_SUBSCRIPTION);

Expand Down Expand Up @@ -97,15 +97,15 @@ describe('Test unsubscribe()', function() {
});

it('should resolve promise when no registration is available', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');

const pushClient = new window.goog.propel.PropelClient(EMPTY_SW_PATH);
return pushClient.unsubscribe();
});

it('should dispatch a status event when no registration is available', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');

let statuschangeCounter = 0;
Expand All @@ -127,7 +127,7 @@ describe('Test unsubscribe()', function() {
});

it('should resolve promise when no subscription is available', function() {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand All @@ -136,7 +136,7 @@ describe('Test unsubscribe()', function() {
});

it('should dispatch a status event when no subscription is available', function(done) {
stateStub = new window.StateStub();
stateStub = window.StateStub.getStub();
stateStub.setPermissionState('default');
stateStub.setUpRegistration(null);

Expand Down
53 changes: 0 additions & 53 deletions test/libs/helper-functions.js

This file was deleted.

Loading

0 comments on commit 22544bc

Please sign in to comment.