mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Updated Admin editor unit tests to use real model instances
ref https://linear.app/tryghost/issue/PLG-176 - we recently had to revert code because it caused unexpected problems despite the unit tests passing - the setup for the editor unit tests was very basic and did not represent the real world because it tested a simple EmberObject instance rather than an Ember Model instance meaning the tests weren't covering the real code paths - updated the unit test with a more realistic environment ready for re-working the reverted code+tests
This commit is contained in:
parent
26724d8705
commit
64fbf3b9ee
1 changed files with 22 additions and 11 deletions
|
@ -10,6 +10,17 @@ import {task} from 'ember-concurrency';
|
||||||
describe('Unit: Controller: lexical-editor', function () {
|
describe('Unit: Controller: lexical-editor', function () {
|
||||||
setupTest();
|
setupTest();
|
||||||
|
|
||||||
|
let createPost;
|
||||||
|
|
||||||
|
const _createPost = function (attrs) {
|
||||||
|
const store = this.owner.lookup('service:store');
|
||||||
|
return store.createRecord('post', attrs);
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
createPost = _createPost.bind(this);
|
||||||
|
});
|
||||||
|
|
||||||
describe('generateSlug', function () {
|
describe('generateSlug', function () {
|
||||||
it('should generate a slug and set it on the post', async function () {
|
it('should generate a slug and set it on the post', async function () {
|
||||||
let controller = this.owner.lookup('controller:lexical-editor');
|
let controller = this.owner.lookup('controller:lexical-editor');
|
||||||
|
@ -18,7 +29,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
return RSVP.resolve(`${str}-slug`);
|
return RSVP.resolve(`${str}-slug`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
controller.set('post', EmberObject.create({slug: ''}));
|
controller.set('post', createPost({slug: ''}));
|
||||||
|
|
||||||
controller.set('post.titleScratch', 'title');
|
controller.set('post.titleScratch', 'title');
|
||||||
await settled();
|
await settled();
|
||||||
|
@ -37,7 +48,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
return RSVP.resolve(`${str}-slug`);
|
return RSVP.resolve(`${str}-slug`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
controller.set('post', EmberObject.create({slug: 'whatever'}));
|
controller.set('post', createPost({slug: 'whatever'}));
|
||||||
|
|
||||||
expect(controller.get('post.slug')).to.equal('whatever');
|
expect(controller.get('post.slug')).to.equal('whatever');
|
||||||
|
|
||||||
|
@ -54,7 +65,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
return RSVP.resolve(`${str}-slug`);
|
return RSVP.resolve(`${str}-slug`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
slug: '',
|
slug: '',
|
||||||
title: '(Untitled)',
|
title: '(Untitled)',
|
||||||
titleScratch: 'title'
|
titleScratch: 'title'
|
||||||
|
@ -73,7 +84,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
slug: '',
|
slug: '',
|
||||||
title: 'title (Copy)',
|
title: 'title (Copy)',
|
||||||
titleScratch: 'newTitle'
|
titleScratch: 'newTitle'
|
||||||
|
@ -92,7 +103,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
slug: 'custom-slug',
|
slug: 'custom-slug',
|
||||||
title: 'original title',
|
title: 'original title',
|
||||||
titleScratch: 'newTitle'
|
titleScratch: 'newTitle'
|
||||||
|
@ -113,7 +124,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
return RSVP.resolve(`${str}-slug`);
|
return RSVP.resolve(`${str}-slug`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
slug: 'somepost',
|
slug: 'somepost',
|
||||||
title: 'somepost',
|
title: 'somepost',
|
||||||
titleScratch: 'newtitle'
|
titleScratch: 'newtitle'
|
||||||
|
@ -143,7 +154,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
yield RSVP.resolve();
|
yield RSVP.resolve();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
controller.set('post', EmberObject.create({isDraft: true}));
|
controller.set('post', createPost({isDraft: true}));
|
||||||
|
|
||||||
expect(controller.get('post.isDraft')).to.be.true;
|
expect(controller.get('post.isDraft')).to.be.true;
|
||||||
expect(controller.get('post.titleScratch')).to.not.be.ok;
|
expect(controller.get('post.titleScratch')).to.not.be.ok;
|
||||||
|
@ -159,7 +170,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
let {controller} = this;
|
let {controller} = this;
|
||||||
|
|
||||||
controller.set('target', {send() {}});
|
controller.set('target', {send() {}});
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
title: 'a title',
|
title: 'a title',
|
||||||
isPublished: true
|
isPublished: true
|
||||||
}));
|
}));
|
||||||
|
@ -180,7 +191,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
it('should have count 0 for no TK', async function () {
|
it('should have count 0 for no TK', async function () {
|
||||||
let controller = this.owner.lookup('controller:lexical-editor');
|
let controller = this.owner.lookup('controller:lexical-editor');
|
||||||
|
|
||||||
controller.set('post', EmberObject.create({titleScratch: 'this is a title'}));
|
controller.set('post', createPost({titleScratch: 'this is a title'}));
|
||||||
|
|
||||||
expect(controller.get('tkCount')).to.equal(0);
|
expect(controller.get('tkCount')).to.equal(0);
|
||||||
});
|
});
|
||||||
|
@ -188,7 +199,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
it('should count TK reminders in the title', async function () {
|
it('should count TK reminders in the title', async function () {
|
||||||
let controller = this.owner.lookup('controller:lexical-editor');
|
let controller = this.owner.lookup('controller:lexical-editor');
|
||||||
|
|
||||||
controller.set('post', EmberObject.create({titleScratch: 'this is a TK'}));
|
controller.set('post', createPost({titleScratch: 'this is a TK'}));
|
||||||
|
|
||||||
expect(controller.get('tkCount')).to.equal(1);
|
expect(controller.get('tkCount')).to.equal(1);
|
||||||
});
|
});
|
||||||
|
@ -203,7 +214,7 @@ describe('Unit: Controller: lexical-editor', function () {
|
||||||
const lexicalStringUpdatedContent = `{"root":{"children":[{"children": [{"detail": 0,"format": 0,"mode": "normal","style": "","text": "Here's some new text","type": "extended-text","version": 1}],"direction": "ltr","format": "","indent": 0,"type": "paragraph","version": 1}],"direction": "ltr","format": "","indent": 0,"type": "root","version": 1}}`;
|
const lexicalStringUpdatedContent = `{"root":{"children":[{"children": [{"detail": 0,"format": 0,"mode": "normal","style": "","text": "Here's some new text","type": "extended-text","version": 1}],"direction": "ltr","format": "","indent": 0,"type": "paragraph","version": 1}],"direction": "ltr","format": "","indent": 0,"type": "root","version": 1}}`;
|
||||||
|
|
||||||
// we can't seem to call setPost directly, so we have to set the post manually
|
// we can't seem to call setPost directly, so we have to set the post manually
|
||||||
controller.set('post', EmberObject.create({
|
controller.set('post', createPost({
|
||||||
title: 'this is a title',
|
title: 'this is a title',
|
||||||
titleScratch: 'this is a title',
|
titleScratch: 'this is a title',
|
||||||
status: 'published',
|
status: 'published',
|
||||||
|
|
Loading…
Add table
Reference in a new issue