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

Commit

Permalink
Adapt tests. #214
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrommen committed Jun 9, 2016
1 parent 89e8671 commit 704e3d8
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 16 deletions.
99 changes: 83 additions & 16 deletions tests/js/unit/admin/post-translation/CopyPostTest.js
Expand Up @@ -19,7 +19,7 @@ test( 'constructor ...', ( assert ) => {
const testee = createTestee();

assert.equal(
testee.listenTo.calledWith( testee.model, 'change', testee.updatePostData ),
testee.listenTo.calledWith( testee.model, 'change:data', testee.updatePostData ),
true,
'... SHOULD attach the expected event listener.'
);
Expand Down Expand Up @@ -176,6 +176,62 @@ test( 'slug (element present) ...', ( assert ) => {
assert.end();
} );

test( 'tinyMCEContent (TinyMCE undefined) ...', ( assert ) => {
const testee = createTestee();

assert.equal(
testee.tinyMCEContent,
'',
'... SHOULD be empty.'
);

assert.end();
} );

test( 'tinyMCEContent (TinyMCE missing) ...', ( assert ) => {
// Prepare tinyMCE.
window.tinyMCE = {
get: F.returnNull
};

const testee = createTestee();

assert.equal(
testee.tinyMCEContent,
'',
'... SHOULD be empty.'
);

// Restore window.
delete window.tinyMCE;

assert.end();
} );

test( 'tinyMCEContent (TinyMCE present) ...', ( assert ) => {
const tinyMCEContent = F.getRandomString();

// Prepare tinyMCE.
window.tinyMCE = {
get: sinon.stub().withArgs( 'content' ).returns( {
getContent: () => tinyMCEContent
} )
};

const testee = createTestee();

assert.equal(
testee.tinyMCEContent,
tinyMCEContent,
'... SHOULD have the expected value.'
);

// Restore window.
delete window.tinyMCE;

assert.end();
} );

test( 'title (element missing) ...', ( assert ) => {
const testee = createTestee();

Expand Down Expand Up @@ -210,7 +266,16 @@ test( 'title (element present) ...', ( assert ) => {
assert.end();
} );

test( 'copyPostData ...', ( assert ) => {
test.only( 'copyPostData ...', ( assert ) => {
const tinyMCEContent = F.getRandomString();

// Prepare tinyMCE.
window.tinyMCE = {
get: sinon.stub().withArgs( 'content' ).returns( {
getContent: () => tinyMCEContent
} )
};

Backbone.Events.trigger.reset();

const EventManager = Backbone.Events;
Expand Down Expand Up @@ -294,27 +359,28 @@ test( 'copyPostData ...', ( assert ) => {
);

const data = {
data: {
action: options.settings.action,
current_post_id: 0,
remote_site_id: remoteSiteID,
title,
slug,
content,
excerpt
},
processData: true
};
action: options.settings.action,
current_post_id: 0,
remote_site_id: remoteSiteID,
title,
slug,
tinyMCEContent,
content,
excerpt
};

assert.equal(
model.fetch.calledWith( data ),
assert.deepEqual(
model.save.calledWith( data, { data, processData: true } ),
true,
'... SHOULD fetch new data.'
);

// Restore lodash.
global._ = sinon.stub();

// Restore window.
delete window.tinyMCE;

// Restore global scope.
globalStub.restore();

Expand Down Expand Up @@ -437,6 +503,7 @@ test( 'updatePostData (successful AJAX request) ...', ( assert ) => {
excerpt: F.getRandomString(),
siteID: F.getRandomInteger( 1 ),
slug: F.getRandomString(),
tinyMCEContent: F.getRandomString(),
title: F.getRandomString()
};

Expand Down Expand Up @@ -493,7 +560,7 @@ test( 'updatePostData (successful AJAX request) ...', ( assert ) => {
);

assert.equal(
testee.setTinyMCEContent.calledWith( prefix + 'content', data.content ),
testee.setTinyMCEContent.calledWith( prefix + 'content', data.tinyMCEContent ),
true,
'... SHOULD set the tinyMCE content to the expected value.'
);
Expand Down
1 change: 1 addition & 0 deletions tests/js/unit/stubs/Backbone.js
Expand Up @@ -30,6 +30,7 @@ Backbone._restore = () => {
};

Backbone.Model.prototype.fetch = sinon.spy();
Backbone.Model.prototype.save = sinon.spy();
Backbone.Model.prototype.get = sinon.stub();

Backbone.Router.prototype.route = sinon.spy();
Expand Down

0 comments on commit 704e3d8

Please sign in to comment.