Skip to content

Commit

Permalink
Create beforeAction and afterAction callbacks on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrinchaudhary authored and ipeychev committed Jan 16, 2015
1 parent 4152f0d commit 6b7d62b
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/ui/yui/test/toolbar-styles.js
Expand Up @@ -37,46 +37,61 @@ describe('ToolbarStyles', function() {
});

it('should make a text selection bold', function(done) {
testButton.call(this, {
testButtonAction.call(this, {
buttonSelector: '.alloy-editor-button .alloy-editor-icon-bold',
expected: '<p>There should be <strong>selection</strong> made bold.</p>',
html: 'There should be {selection} made bold.'
html: 'There should be {selection} made bold.',
afterAction: function(button) {
assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
}
}, done);
});

it('should make a text selection italic', function(done) {
testButton.call(this, {
testButtonAction.call(this, {
buttonSelector: '.alloy-editor-button .alloy-editor-icon-italic',
expected: '<p>There should be <em>selection</em> made italic.</p>',
html: 'There should be {selection} made italic.'
html: 'There should be {selection} made italic.',
afterAction: function(button) {
assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
}
}, done);
});

it('should make a text selection underline', function(done) {
testButton.call(this, {
testButtonAction.call(this, {
buttonSelector: '.alloy-editor-button .alloy-editor-icon-underline',
expected: '<p>There should be <u>selection</u> made underline.</p>',
html: 'There should be {selection} made underline.'
html: 'There should be {selection} made underline.',
afterAction: function(button) {
assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
}
}, done);
});

it('should make a text selection h1', function(done) {
testButton.call(this, {
testButtonAction.call(this, {
buttonSelector: '.alloy-editor-button .alloy-editor-icon-h1',
expected: '<h1>There should be selection made h1.</h1>',
html: 'There should be {selection} made h1.'
html: 'There should be {selection} made h1.',
afterAction: function(button) {
assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
}
}, done);
});

it('should make a text selection h2', function(done) {
testButton.call(this, {
testButtonAction.call(this, {
buttonSelector: '.alloy-editor-button .alloy-editor-icon-h2',
expected: '<h2>There should be selection made h2.</h2>',
html: 'There should be {selection} made h2.'
html: 'There should be {selection} made h2.',
afterAction: function(button) {
assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
}
}, done);
});

function testButton(config, callback) {
function testButtonAction(config, callback) {
var self = this;

bender.tools.selection.setWithHtml(self.nativeEditor, config.html);
Expand All @@ -86,9 +101,15 @@ describe('ToolbarStyles', function() {
setTimeout(function() {
var button = $(config.buttonSelector);

if (config.beforeAction) {
config.beforeAction.call(self, button);
}

happen.click(button[0]);

assert.strictEqual(button.parent().hasClass('yui3-button-selected'), true);
if (config.afterAction) {
config.afterAction.call(self, button);
}

var data = bender.tools.getData(self.nativeEditor, {
fixHtml: false,
Expand All @@ -97,6 +118,10 @@ describe('ToolbarStyles', function() {

assert.strictEqual(data, config.expected);

if (config.beforeCallback) {
config.beforeCallback.call(self, button);
}

callback();
}, 150);
}
Expand Down

0 comments on commit 6b7d62b

Please sign in to comment.