mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
506b2a9388
requires https://github.com/TryGhost/Ghost/pull/9277 - added a `koenigEditor` feature flag - modified the feature service to accept a `developer` boolean on the options object passed into the internal `feature` method, if `true` the feature flag won't be enabled unless the `enableDeveloperExperiments` config option is also enabled - added "developer feature testing" section in labs that's only visible if `enableDeveloperExperiments` config flag is enabled - added koenig editor toggle to the developer section in labs - enabled a switch between the markdown and koenig editors - modified the default value of the `mobiledoc` attr in the Post model to be a blank mobiledoc or blank markdown mobiledoc depending on the feature flag - modified the `autofocus` switch in editor controller's `setPost` method so that it is always switched, even for new->edit where the post model isn't swapped - added a compatibility check to the editor controller's `setPost` method that shows an alert and force enables the koenig editor if the koenig flag is not enabled and the opened post is not compatible with the markdown editor - fixed various issues that have appeared due to the old koenig alpha becoming out of sync with master
101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
import EmberObject from '@ember/object';
|
|
import {describe, it} from 'mocha';
|
|
import {run} from '@ember/runloop';
|
|
import {setupModelTest} from 'ember-mocha';
|
|
|
|
describe('Unit: Model: post', function () {
|
|
setupModelTest('post', {
|
|
needs: [
|
|
'model:user',
|
|
'model:tag',
|
|
'model:role',
|
|
'service:ajax',
|
|
'service:clock',
|
|
'service:config',
|
|
'service:feature',
|
|
'service:ghostPaths',
|
|
'service:lazyLoader',
|
|
'service:notifications',
|
|
'service:session',
|
|
'service:settings'
|
|
]
|
|
});
|
|
|
|
it('has a validation type of "post"', function () {
|
|
let model = this.subject();
|
|
|
|
expect(model.validationType).to.equal('post');
|
|
});
|
|
|
|
it('isPublished, isDraft and isScheduled are correct', function () {
|
|
let model = this.subject({
|
|
status: 'published'
|
|
});
|
|
|
|
expect(model.get('isPublished')).to.be.ok;
|
|
expect(model.get('isDraft')).to.not.be.ok;
|
|
expect(model.get('isScheduled')).to.not.be.ok;
|
|
|
|
run(function () {
|
|
model.set('status', 'draft');
|
|
|
|
expect(model.get('isPublished')).to.not.be.ok;
|
|
expect(model.get('isDraft')).to.be.ok;
|
|
expect(model.get('isScheduled')).to.not.be.ok;
|
|
});
|
|
|
|
run(function () {
|
|
model.set('status', 'scheduled');
|
|
|
|
expect(model.get('isScheduled')).to.be.ok;
|
|
expect(model.get('isPublished')).to.not.be.ok;
|
|
expect(model.get('isDraft')).to.not.be.ok;
|
|
});
|
|
});
|
|
|
|
it('isAuthoredByUser is correct', function () {
|
|
let model = this.subject({
|
|
authorId: 'abcd1234'
|
|
});
|
|
let user = EmberObject.create({id: 'abcd1234'});
|
|
|
|
expect(model.isAuthoredByUser(user)).to.be.ok;
|
|
|
|
run(function () {
|
|
model.set('authorId', 'wxyz9876');
|
|
|
|
expect(model.isAuthoredByUser(user)).to.not.be.ok;
|
|
});
|
|
});
|
|
|
|
it('updateTags removes and deletes old tags', function () {
|
|
let model = this.subject();
|
|
|
|
run(this, function () {
|
|
let modelTags = model.get('tags');
|
|
let tag1 = this.store().createRecord('tag', {id: '1'});
|
|
let tag2 = this.store().createRecord('tag', {id: '2'});
|
|
let tag3 = this.store().createRecord('tag');
|
|
|
|
// During testing a record created without an explicit id will get
|
|
// an id of 'fixture-n' instead of null
|
|
tag3.set('id', null);
|
|
|
|
modelTags.pushObject(tag1);
|
|
modelTags.pushObject(tag2);
|
|
modelTags.pushObject(tag3);
|
|
|
|
expect(model.get('tags.length')).to.equal(3);
|
|
|
|
model.updateTags();
|
|
|
|
expect(model.get('tags.length')).to.equal(2);
|
|
expect(model.get('tags.firstObject.id')).to.equal('1');
|
|
expect(model.get('tags').objectAt(1).get('id')).to.equal('2');
|
|
expect(tag1.get('isDeleted')).to.not.be.ok;
|
|
expect(tag2.get('isDeleted')).to.not.be.ok;
|
|
expect(tag3.get('isDeleted')).to.be.ok;
|
|
});
|
|
});
|
|
});
|