2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2016-06-30 13:21:47 +03:00
|
|
|
import run from 'ember-runloop';
|
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import EmberObject from 'ember-object';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-03-10 17:30:01 +03:00
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
|
|
|
|
|
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
function K() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-03-14 12:56:36 +03:00
|
|
|
// TODO: convert to integration tests
|
|
|
|
describe.skip('Unit: Component: post-settings-menu', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
setupComponentTest('gh-post-settings-menu', {
|
2017-03-17 20:16:21 +03:00
|
|
|
needs: ['service:notifications', 'service:slug-generator', 'service:settings']
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('slugValue is one-way bound to model.slug', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'a-slug'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.slug')).to.equal('a-slug');
|
|
|
|
expect(component.get('slugValue')).to.equal('a-slug');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.slug', 'changed-slug');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('slugValue')).to.equal('changed-slug');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'changed-directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.slug')).to.equal('changed-slug');
|
|
|
|
expect(component.get('slugValue')).to.equal('changed-directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
|
|
|
// test that the one-way binding is still in place
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.slug', 'should-update');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('slugValue')).to.equal('should-update');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('metaTitleScratch is one-way bound to model.metaTitle', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
|
|
|
metaTitle: 'a title',
|
|
|
|
metaTitleScratch: boundOneWay('metaTitle')
|
|
|
|
}).create()
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.metaTitle')).to.equal('a title');
|
|
|
|
expect(component.get('metaTitleScratch')).to.equal('a title');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.metaTitle', 'a different title');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('metaTitleScratch')).to.equal('a different title');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('metaTitleScratch', 'changed directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.metaTitle')).to.equal('a different title');
|
|
|
|
expect(component.get('model.metaTitleScratch')).to.equal('changed directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
|
|
|
// test that the one-way binding is still in place
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.metaTitle', 'should update');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('metaTitleScratch')).to.equal('should update');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('metaDescriptionScratch is one-way bound to model.metaDescription', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
|
|
|
metaDescription: 'a description',
|
|
|
|
metaDescriptionScratch: boundOneWay('metaDescription')
|
|
|
|
}).create()
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.metaDescription')).to.equal('a description');
|
|
|
|
expect(component.get('metaDescriptionScratch')).to.equal('a description');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.metaDescription', 'a different description');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('metaDescriptionScratch')).to.equal('a different description');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('metaDescriptionScratch', 'changed directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.metaDescription')).to.equal('a different description');
|
|
|
|
expect(component.get('metaDescriptionScratch')).to.equal('changed directly');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
|
|
|
// test that the one-way binding is still in place
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.metaDescription', 'should update');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('metaDescriptionScratch')).to.equal('should update');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('seoTitle', function () {
|
|
|
|
it('should be the metaTitle if one exists', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
2016-11-24 01:50:57 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2017-03-10 17:30:01 +03:00
|
|
|
metaTitleScratch: boundOneWay('metaTitle'),
|
2016-11-24 01:50:57 +03:00
|
|
|
titleScratch: 'should not be used'
|
2017-03-10 17:30:01 +03:00
|
|
|
}).create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle')).to.equal('a meta-title');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should default to the title if an explicit meta-title does not exist', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
titleScratch: 'should be the meta-title'
|
|
|
|
})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle')).to.equal('should be the meta-title');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should be the metaTitle if both title and metaTitle exist', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
2016-11-24 01:50:57 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2017-03-10 17:30:01 +03:00
|
|
|
metaTitleScratch: boundOneWay('metaTitle'),
|
2016-11-24 01:50:57 +03:00
|
|
|
titleScratch: 'a title'
|
2017-03-10 17:30:01 +03:00
|
|
|
}).create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle')).to.equal('a meta-title');
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should revert to the title if explicit metaTitle is removed', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
2016-11-24 01:50:57 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2017-03-10 17:30:01 +03:00
|
|
|
metaTitleScratch: boundOneWay('metaTitle'),
|
2016-11-24 01:50:57 +03:00
|
|
|
titleScratch: 'a title'
|
2017-03-10 17:30:01 +03:00
|
|
|
}).create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle')).to.equal('a meta-title');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.metaTitle', '');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle')).to.equal('a title');
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should truncate to 70 characters with an appended ellipsis', function () {
|
|
|
|
let longTitle = new Array(100).join('a');
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(longTitle.length).to.equal(99);
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
let expected = `${longTitle.substr(0, 70)}…`;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('metaTitleScratch', longTitle);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoTitle').toString().length).to.equal(78);
|
|
|
|
expect(component.get('seoTitle').toString()).to.equal(expected);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('seoDescription', function () {
|
|
|
|
it('should be the metaDescription if one exists', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
|
|
|
model: EmberObject.extend({
|
|
|
|
metaDescription: 'a description',
|
|
|
|
metaDescriptionScratch: boundOneWay('metaDescription')
|
|
|
|
}).create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoDescription')).to.equal('a description');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it.skip('should be generated from the rendered markdown if not explicitly set', function () {
|
|
|
|
// can't test right now because the rendered markdown is being pulled
|
|
|
|
// from the DOM via jquery
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should truncate to 156 characters with an appended ellipsis', function () {
|
|
|
|
let longDescription = new Array(200).join('a');
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(longDescription.length).to.equal(199);
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
let expected = `${longDescription.substr(0, 156)}…`;
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('metaDescriptionScratch', longDescription);
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoDescription').toString().length).to.equal(164);
|
|
|
|
expect(component.get('seoDescription').toString()).to.equal(expected);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('seoURL', function () {
|
|
|
|
it('should be the URL of the blog if no post slug exists', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
|
|
|
|
model: EmberObject.create()
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should be the URL of the blog plus the post slug', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
|
|
|
|
model: EmberObject.create({slug: 'post-slug'})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should update when the post slug changes', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
|
|
|
|
model: EmberObject.create({slug: 'post-slug'})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('model.slug', 'changed-slug');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/changed-slug/');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should truncate a long URL to 70 characters with an appended ellipsis', function () {
|
|
|
|
let blogURL = 'http://my-ghost-blog.com';
|
|
|
|
let longSlug = new Array(75).join('a');
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
config: EmberObject.create({blogUrl: blogURL}),
|
|
|
|
model: EmberObject.create({slug: longSlug})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
let expected;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(longSlug.length).to.equal(74);
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expected = `${blogURL}/${longSlug}/`;
|
|
|
|
expected = `${expected.substr(0, 70)}…`;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('seoURL').toString().length).to.equal(78);
|
|
|
|
expect(component.get('seoURL').toString()).to.equal(expected);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('togglePage', function () {
|
|
|
|
it('should toggle the page property', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
page: false,
|
|
|
|
isNew: true
|
|
|
|
})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.page')).to.not.be.ok;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('togglePage');
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.page')).to.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should not save the post if it is still new', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
page: false,
|
|
|
|
isNew: true,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
return RSVP.resolve();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('togglePage');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.page')).to.be.ok;
|
|
|
|
expect(component.get('model.saved')).to.not.be.ok;
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should save the post if it is not new', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
page: false,
|
|
|
|
isNew: false,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
return RSVP.resolve();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('togglePage');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.page')).to.be.ok;
|
|
|
|
expect(component.get('model.saved')).to.equal(1);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('toggleFeatured', function () {
|
|
|
|
it('should toggle the featured property', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
featured: false,
|
|
|
|
isNew: true
|
|
|
|
})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('toggleFeatured');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.featured')).to.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should not save the post if it is still new', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
featured: false,
|
|
|
|
isNew: true,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
return RSVP.resolve();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('toggleFeatured');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.featured')).to.be.ok;
|
|
|
|
expect(component.get('model.saved')).to.not.be.ok;
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should save the post if it is not new', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
featured: false,
|
|
|
|
isNew: false,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
return RSVP.resolve();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.send('toggleFeatured');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.featured')).to.be.ok;
|
|
|
|
expect(component.get('model.saved')).to.equal(1);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('updateSlug', function () {
|
|
|
|
it('should reset slugValue to the previous slug when the new slug is blank or unchanged', function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'slug'
|
|
|
|
})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
|
|
|
// unchanged
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'slug');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.slug')).to.equal('slug');
|
|
|
|
expect(component.get('slugValue')).to.equal('slug');
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
|
|
|
// unchanged after trim
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'slug ');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.slug')).to.equal('slug');
|
|
|
|
expect(component.get('slugValue')).to.equal('slug');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
|
|
|
// blank
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', '');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
expect(component.get('model.slug')).to.equal('slug');
|
|
|
|
expect(component.get('slugValue')).to.equal('slug');
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should not set a new slug if the server-generated slug matches existing slug', function (done) {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
|
|
|
generateSlug(slugType, str) {
|
|
|
|
let promise = RSVP.resolve(str.split('#')[0]);
|
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'whatever'
|
|
|
|
})
|
|
|
|
});
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'whatever#slug');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
RSVP.resolve(component.get('lastPromise')).then(function () {
|
|
|
|
expect(component.get('model.slug')).to.equal('whatever');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should not set a new slug if the only change is to the appended increment value', function (done) {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
|
|
|
generateSlug(slugType, str) {
|
|
|
|
let sanitizedStr = str.replace(/[^a-zA-Z]/g, '');
|
|
|
|
let promise = RSVP.resolve(`${sanitizedStr}-2`);
|
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'whatever'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'whatever!');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
RSVP.resolve(component.get('lastPromise')).then(function () {
|
|
|
|
expect(component.get('model.slug')).to.equal('whatever');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should set the slug if the new slug is different', function (done) {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
|
|
|
generateSlug(slugType, str) {
|
|
|
|
let promise = RSVP.resolve(str);
|
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'whatever',
|
|
|
|
save: K
|
|
|
|
})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'changed');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
RSVP.resolve(component.get('lastPromise')).then(function () {
|
|
|
|
expect(component.get('model.slug')).to.equal('changed');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('should save the post when the slug changes and the post is not new', function (done) {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
|
|
|
generateSlug(slugType, str) {
|
|
|
|
let promise = RSVP.resolve(str);
|
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'whatever',
|
|
|
|
saved: 0,
|
|
|
|
isNew: false,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'changed');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
RSVP.resolve(component.get('lastPromise')).then(function () {
|
|
|
|
expect(component.get('model.slug')).to.equal('changed');
|
|
|
|
expect(component.get('model.saved')).to.equal(1);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not save the post when the slug changes and the post is new', function (done) {
|
2017-03-10 17:30:01 +03:00
|
|
|
let component = this.subject({
|
2016-11-24 01:50:57 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
|
|
|
generateSlug(slugType, str) {
|
|
|
|
let promise = RSVP.resolve(str);
|
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
model: EmberObject.create({
|
|
|
|
slug: 'whatever',
|
|
|
|
saved: 0,
|
|
|
|
isNew: true,
|
|
|
|
save() {
|
|
|
|
this.incrementProperty('saved');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
run(function () {
|
2017-03-10 17:30:01 +03:00
|
|
|
component.set('slugValue', 'changed');
|
|
|
|
component.send('updateSlug', component.get('slugValue'));
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-10 17:30:01 +03:00
|
|
|
RSVP.resolve(component.get('lastPromise')).then(function () {
|
|
|
|
expect(component.get('model.slug')).to.equal('changed');
|
|
|
|
expect(component.get('model.saved')).to.equal(0);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|