mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
6a3cfc2ca8
requires https://github.com/TryGhost/Ghost/pull/9426 - fixed default token component display in {{gh-token-input}} - if no `tokenComponent` is passed to `{{gh-token-input}}` then it should default to the ember-drag-drop `draggable-object` component but instead it didn't output anything - put `draggable-object` in quotes because `{{component}}` needs a component name rather than an object - rename `option` attribute to `content` to match the default `{{draggable-object}}` interface - add embedded `authors` attr to the Post model - ensure authors is populated when starting new post - add validation for empty authors list - swap author dropdown for a token input in PSM - show all post authors in posts list - update tests for `authors` - always provide through an authors array - fix mirage serialisation for paginated responses (embedded records were not being serialised) - unify tags and author inputs design - remove highlight of primary tags - highlight internal tags - remove unnecessary/redundant title attributes on tags - use SVG icon for "remove option" button in token inputs
102 lines
3.1 KiB
JavaScript
102 lines
3.1 KiB
JavaScript
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 user1 = this.store().createRecord('user', {id: 'abcd1234'});
|
|
let user2 = this.store().createRecord('user', {id: 'wxyz9876'});
|
|
|
|
let model = this.subject({
|
|
authors: [user1]
|
|
});
|
|
|
|
expect(model.isAuthoredByUser(user1)).to.be.ok;
|
|
|
|
run(function () {
|
|
model.set('authors', [user2]);
|
|
|
|
expect(model.isAuthoredByUser(user1)).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;
|
|
});
|
|
});
|
|
});
|