forked from mozilla/fxa-content-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mozilla#2580 from mozilla/issue-2502-subscribe-button
fix(client): Fix the submit button on communcation preferences page.
- Loading branch information
Showing
3 changed files
with
127 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict'; | ||
|
||
define([ | ||
'chai', | ||
'sinon', | ||
'jquery', | ||
'lib/promise', | ||
'views/base', | ||
'views/progress_indicator', | ||
'views/decorators/progress_indicator' | ||
], | ||
function (chai, sinon, $, p, BaseView, ProgressIndicator, showProgressIndicator) { | ||
var assert = chai.assert; | ||
|
||
describe('views/decorators/progress_indicator', function () { | ||
var view; | ||
var progressIndicator; | ||
|
||
var View = BaseView.extend({ | ||
template: function () { | ||
return '<button type="submit">Button</button>'; | ||
}, | ||
longRunningAction: showProgressIndicator(function () { | ||
return p().then(function () { | ||
assert.isTrue(progressIndicator.start.called); | ||
}); | ||
}) | ||
}); | ||
|
||
beforeEach(function () { | ||
// set up a progress indicator to use for testing. | ||
progressIndicator = new ProgressIndicator(); | ||
sinon.spy(progressIndicator, 'start'); | ||
sinon.spy(progressIndicator, 'done'); | ||
|
||
view = new View(); | ||
|
||
return view.render() | ||
.then(function () { | ||
// set up the initial progress indicator to use for testing. | ||
view.$('button[type="submit"]').data('progressIndicator', progressIndicator); | ||
$('#container').html(view.el); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
view.destroy(); | ||
}); | ||
|
||
describe('showProgressIndicator', function () { | ||
it('starts and stops the progress indicator', function () { | ||
return view.longRunningAction() | ||
.then(function () { | ||
assert.equal(progressIndicator.done.callCount, 1); | ||
}); | ||
}); | ||
|
||
it('can be shown multiple times in a row on the same button', function () { | ||
return view.longRunningAction() | ||
.then(function () { | ||
assert.equal(progressIndicator.done.callCount, 1); | ||
|
||
return view.longRunningAction(); | ||
}) | ||
.then(function () { | ||
assert.equal(progressIndicator.done.callCount, 2); | ||
}); | ||
}); | ||
|
||
it('works even if the view re-renders after a button is shown', function () { | ||
return view.longRunningAction() | ||
.then(function () { | ||
assert.equal(progressIndicator.done.callCount, 1); | ||
|
||
// a new progress indicator should be created | ||
// because of this action. | ||
return view.render(); | ||
}) | ||
.then(function () { | ||
return view.longRunningAction(); | ||
}) | ||
.then(function () { | ||
var progressIndicatorAfterReRender = view.$('button[type="submit"]').data('progressIndicator'); | ||
assert.instanceOf(progressIndicatorAfterReRender, ProgressIndicator); | ||
assert.notEqual(progressIndicator, progressIndicatorAfterReRender); | ||
|
||
assert.equal(progressIndicator.done.callCount, 1); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters