2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
2016-06-30 13:21:47 +03:00
|
|
|
import run from 'ember-runloop';
|
|
|
|
import RSVP from 'rsvp';
|
|
|
|
import EmberObject from 'ember-object';
|
2015-02-18 23:02:48 +03:00
|
|
|
import {
|
|
|
|
describeModule,
|
|
|
|
it
|
|
|
|
} from 'ember-mocha';
|
Timezones: Always use the timezone of blog setting
closes TryGhost/Ghost#6406
follow-up PR of #2
- adds a `timeZone` Service to provide the offset (=timezone reg. moment-timezone) of the users blog settings
- `gh-datetime-input` will read the offset of the timezone now and adjust the `publishedAt` date with it. This is the date which will be shown in the PSM 'Publish Date' field. When the user writes a new date/time, the offset is considered and will be deducted again before saving it to the model. This way, we always work with a UTC publish date except for this input field.
- gets `availableTimezones` from `configuration/timezones` API endpoint
- adds a `moment-utc` transform on all date attr (`createdAt`, `updatedAt`, `publishedAt`, `unsubscribedAt` and `lastLogin`) to only work with UTC times on serverside
- when switching the timezone in the select box, the user will be shown the local time of the selected timezone
- `createdAt`-property in `gh-user-invited` returns now `moment(createdAt).fromNow()` as `createdAt` is a moment date already
- added clock service to show actual time ticking below select box
- default timezone is '(GMT) Greenwich Mean Time : Dublin, Edinburgh, London'
- if no timezone is saved in the settings yet, the default value will be used
- shows the local time in 'Publish Date' in PSM by default, until user overwrites it
- adds dependency `moment-timezone 0.5.4` to `bower.json`
---------
**Tests:**
- sets except for clock service in test env
- adds fixtures to mirage
- adds `service.ajax` and `service:ghostPaths` to navigation-test.js
- adds unit test for `gh-format-timeago` helper
- updates acceptance test `general-setting`
- adds acceptance test for `editor`
- adds integration tests for `services/config` and `services/time-zone`
---------
**Todos:**
- [ ] Integration tests: ~~`services/config`~~, ~~`services/time-zone`~~, `components/gh-datetime-input`
- [x] Acceptance test: `editor`
- [ ] Unit tests: `utils/date-formatting`
- [ ] write issue for renaming date properties (e. g. `createdAt` to `createdAtUTC`) and translate those for server side with serializers
2016-02-02 10:04:40 +03:00
|
|
|
import sinon from 'sinon';
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
function K() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-02-18 23:02:48 +03:00
|
|
|
describeModule(
|
|
|
|
'controller:post-settings-menu',
|
2015-10-06 19:31:03 +03:00
|
|
|
'Unit: Controller: post-settings-menu',
|
2015-02-18 23:02:48 +03:00
|
|
|
{
|
Timezones: Always use the timezone of blog setting
closes TryGhost/Ghost#6406
follow-up PR of #2
- adds a `timeZone` Service to provide the offset (=timezone reg. moment-timezone) of the users blog settings
- `gh-datetime-input` will read the offset of the timezone now and adjust the `publishedAt` date with it. This is the date which will be shown in the PSM 'Publish Date' field. When the user writes a new date/time, the offset is considered and will be deducted again before saving it to the model. This way, we always work with a UTC publish date except for this input field.
- gets `availableTimezones` from `configuration/timezones` API endpoint
- adds a `moment-utc` transform on all date attr (`createdAt`, `updatedAt`, `publishedAt`, `unsubscribedAt` and `lastLogin`) to only work with UTC times on serverside
- when switching the timezone in the select box, the user will be shown the local time of the selected timezone
- `createdAt`-property in `gh-user-invited` returns now `moment(createdAt).fromNow()` as `createdAt` is a moment date already
- added clock service to show actual time ticking below select box
- default timezone is '(GMT) Greenwich Mean Time : Dublin, Edinburgh, London'
- if no timezone is saved in the settings yet, the default value will be used
- shows the local time in 'Publish Date' in PSM by default, until user overwrites it
- adds dependency `moment-timezone 0.5.4` to `bower.json`
---------
**Tests:**
- sets except for clock service in test env
- adds fixtures to mirage
- adds `service.ajax` and `service:ghostPaths` to navigation-test.js
- adds unit test for `gh-format-timeago` helper
- updates acceptance test `general-setting`
- adds acceptance test for `editor`
- adds integration tests for `services/config` and `services/time-zone`
---------
**Todos:**
- [ ] Integration tests: ~~`services/config`~~, ~~`services/time-zone`~~, `components/gh-datetime-input`
- [x] Acceptance test: `editor`
- [ ] Unit tests: `utils/date-formatting`
- [ ] write issue for renaming date properties (e. g. `createdAt` to `createdAtUTC`) and translate those for server side with serializers
2016-02-02 10:04:40 +03:00
|
|
|
needs: ['controller:application', 'service:notifications', 'service:slug-generator', 'service:timeZone']
|
2015-02-18 23:02:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
function () {
|
|
|
|
it('slugValue is one-way bound to model.slug', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'a-slug'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('model.slug')).to.equal('a-slug');
|
|
|
|
expect(controller.get('slugValue')).to.equal('a-slug');
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('model.slug', 'changed-slug');
|
|
|
|
|
|
|
|
expect(controller.get('slugValue')).to.equal('changed-slug');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'changed-directly');
|
|
|
|
|
|
|
|
expect(controller.get('model.slug')).to.equal('changed-slug');
|
|
|
|
expect(controller.get('slugValue')).to.equal('changed-directly');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// test that the one-way binding is still in place
|
|
|
|
controller.set('model.slug', 'should-update');
|
|
|
|
|
|
|
|
expect(controller.get('slugValue')).to.equal('should-update');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
it('metaTitleScratch is one-way bound to model.metaTitle', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaTitle: 'a title'
|
2015-02-18 23:02:48 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
expect(controller.get('model.metaTitle')).to.equal('a title');
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('metaTitleScratch')).to.equal('a title');
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2016-01-23 21:12:22 +03:00
|
|
|
controller.set('model.metaTitle', 'a different title');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('metaTitleScratch')).to.equal('a different title');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('metaTitleScratch', 'changed directly');
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
expect(controller.get('model.metaTitle')).to.equal('a different title');
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('metaTitleScratch')).to.equal('changed directly');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// test that the one-way binding is still in place
|
2016-01-23 21:12:22 +03:00
|
|
|
controller.set('model.metaTitle', 'should update');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('metaTitleScratch')).to.equal('should update');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
it('metaDescriptionScratch is one-way bound to model.metaDescription', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaDescription: 'a description'
|
2015-02-18 23:02:48 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
expect(controller.get('model.metaDescription')).to.equal('a description');
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('metaDescriptionScratch')).to.equal('a description');
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2016-01-23 21:12:22 +03:00
|
|
|
controller.set('model.metaDescription', 'a different description');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('metaDescriptionScratch')).to.equal('a different description');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('metaDescriptionScratch', 'changed directly');
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
expect(controller.get('model.metaDescription')).to.equal('a different description');
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('metaDescriptionScratch')).to.equal('changed directly');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// test that the one-way binding is still in place
|
2016-01-23 21:12:22 +03:00
|
|
|
controller.set('model.metaDescription', 'should update');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('metaDescriptionScratch')).to.equal('should update');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('seoTitle', function () {
|
2016-01-23 21:12:22 +03:00
|
|
|
it('should be the metaTitle if one exists', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2015-02-18 23:02:48 +03:00
|
|
|
titleScratch: 'should not be used'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoTitle')).to.equal('a meta-title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should default to the title if an explicit meta-title does not exist', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
titleScratch: 'should be the meta-title'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoTitle')).to.equal('should be the meta-title');
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
it('should be the metaTitle if both title and metaTitle exist', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2015-02-18 23:02:48 +03:00
|
|
|
titleScratch: 'a title'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoTitle')).to.equal('a meta-title');
|
|
|
|
});
|
|
|
|
|
2016-01-23 21:12:22 +03:00
|
|
|
it('should revert to the title if explicit metaTitle is removed', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaTitle: 'a meta-title',
|
2015-02-18 23:02:48 +03:00
|
|
|
titleScratch: 'a title'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoTitle')).to.equal('a meta-title');
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2016-01-23 21:12:22 +03:00
|
|
|
controller.set('model.metaTitle', '');
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('seoTitle')).to.equal('a title');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate to 70 characters with an appended ellipsis', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let longTitle = new Array(100).join('a');
|
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
expect(longTitle.length).to.equal(99);
|
|
|
|
|
|
|
|
run(function () {
|
|
|
|
let expected = `${longTitle.substr(0, 70)}…`;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
controller.set('metaTitleScratch', longTitle);
|
|
|
|
|
|
|
|
expect(controller.get('seoTitle').toString().length).to.equal(78);
|
|
|
|
expect(controller.get('seoTitle').toString()).to.equal(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('seoDescription', function () {
|
2016-01-23 21:12:22 +03:00
|
|
|
it('should be the metaDescription if one exists', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2016-01-23 21:12:22 +03:00
|
|
|
metaDescription: 'a description'
|
2015-02-18 23:02:48 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoDescription')).to.equal('a description');
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate to 156 characters with an appended ellipsis', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let longDescription = new Array(200).join('a');
|
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
expect(longDescription.length).to.equal(199);
|
|
|
|
|
|
|
|
run(function () {
|
|
|
|
let expected = `${longDescription.substr(0, 156)}…`;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
controller.set('metaDescriptionScratch', longDescription);
|
|
|
|
|
|
|
|
expect(controller.get('seoDescription').toString().length).to.equal(164);
|
|
|
|
expect(controller.get('seoDescription').toString()).to.equal(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('seoURL', function () {
|
|
|
|
it('should be the URL of the blog if no post slug exists', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
|
|
|
|
model: EmberObject.create()
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be the URL of the blog plus the post slug', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +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
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update when the post slug changes', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +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
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('model.slug', 'changed-slug');
|
|
|
|
|
|
|
|
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/changed-slug/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should truncate a long URL to 70 characters with an appended ellipsis', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let blogURL = 'http://my-ghost-blog.com';
|
|
|
|
let longSlug = new Array(75).join('a');
|
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
config: EmberObject.create({blogUrl: blogURL}),
|
|
|
|
model: EmberObject.create({slug: longSlug})
|
2015-02-18 23:02:48 +03:00
|
|
|
});
|
2015-10-28 14:36:45 +03:00
|
|
|
let expected;
|
|
|
|
|
|
|
|
expect(longSlug.length).to.equal(74);
|
2015-02-18 23:02:48 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
expected = `${blogURL}/${longSlug}/`;
|
|
|
|
expected = `${expected.substr(0, 70)}…`;
|
2015-02-18 23:02:48 +03:00
|
|
|
|
|
|
|
expect(controller.get('seoURL').toString().length).to.equal(78);
|
|
|
|
expect(controller.get('seoURL').toString()).to.equal(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('togglePage', function () {
|
|
|
|
it('should toggle the page property', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
page: false,
|
|
|
|
isNew: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(controller.get('model.page')).to.not.be.ok;
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('togglePage');
|
|
|
|
|
|
|
|
expect(controller.get('model.page')).to.be.ok;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not save the post if it is still new', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
page: false,
|
|
|
|
isNew: true,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
2016-06-11 19:52:36 +03:00
|
|
|
return RSVP.resolve();
|
2015-02-18 23:02:48 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('togglePage');
|
|
|
|
|
|
|
|
expect(controller.get('model.page')).to.be.ok;
|
|
|
|
expect(controller.get('model.saved')).to.not.be.ok;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save the post if it is not new', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
page: false,
|
|
|
|
isNew: false,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
2016-06-11 19:52:36 +03:00
|
|
|
return RSVP.resolve();
|
2015-02-18 23:02:48 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('togglePage');
|
|
|
|
|
|
|
|
expect(controller.get('model.page')).to.be.ok;
|
|
|
|
expect(controller.get('model.saved')).to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleFeatured', function () {
|
|
|
|
it('should toggle the featured property', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
featured: false,
|
|
|
|
isNew: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('toggleFeatured');
|
|
|
|
|
|
|
|
expect(controller.get('model.featured')).to.be.ok;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not save the post if it is still new', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
featured: false,
|
|
|
|
isNew: true,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
2016-06-11 19:52:36 +03:00
|
|
|
return RSVP.resolve();
|
2015-02-18 23:02:48 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('toggleFeatured');
|
|
|
|
|
|
|
|
expect(controller.get('model.featured')).to.be.ok;
|
|
|
|
expect(controller.get('model.saved')).to.not.be.ok;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save the post if it is not new', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
featured: false,
|
|
|
|
isNew: false,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
2016-06-11 19:52:36 +03:00
|
|
|
return RSVP.resolve();
|
2015-02-18 23:02:48 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.send('toggleFeatured');
|
|
|
|
|
|
|
|
expect(controller.get('model.featured')).to.be.ok;
|
|
|
|
expect(controller.get('model.saved')).to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateSlug', function () {
|
|
|
|
it('should reset slugValue to the previous slug when the new slug is blank or unchanged', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'slug'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// unchanged
|
|
|
|
controller.set('slugValue', 'slug');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
|
|
|
expect(controller.get('model.slug')).to.equal('slug');
|
|
|
|
expect(controller.get('slugValue')).to.equal('slug');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// unchanged after trim
|
|
|
|
controller.set('slugValue', 'slug ');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
|
|
|
expect(controller.get('model.slug')).to.equal('slug');
|
|
|
|
expect(controller.get('slugValue')).to.equal('slug');
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
// blank
|
|
|
|
controller.set('slugValue', '');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
|
|
|
expect(controller.get('model.slug')).to.equal('slug');
|
|
|
|
expect(controller.get('slugValue')).to.equal('slug');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not set a new slug if the server-generated slug matches existing slug', function (done) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
2016-01-15 18:43:16 +03:00
|
|
|
generateSlug(slugType, str) {
|
2016-06-11 19:52:36 +03:00
|
|
|
let promise = RSVP.resolve(str.split('#')[0]);
|
2015-02-18 23:02:48 +03:00
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'whatever'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'whatever#slug');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
RSVP.resolve(controller.get('lastPromise')).then(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('model.slug')).to.equal('whatever');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not set a new slug if the only change is to the appended increment value', function (done) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
2016-01-15 18:43:16 +03:00
|
|
|
generateSlug(slugType, str) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let sanitizedStr = str.replace(/[^a-zA-Z]/g, '');
|
2016-06-11 19:52:36 +03:00
|
|
|
let promise = RSVP.resolve(`${sanitizedStr}-2`);
|
2015-02-18 23:02:48 +03:00
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'whatever'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'whatever!');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
RSVP.resolve(controller.get('lastPromise')).then(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('model.slug')).to.equal('whatever');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the slug if the new slug is different', function (done) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
2016-01-15 18:43:16 +03:00
|
|
|
generateSlug(slugType, str) {
|
2016-06-11 19:52:36 +03:00
|
|
|
let promise = RSVP.resolve(str);
|
2015-02-18 23:02:48 +03:00
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'whatever',
|
2015-10-28 14:36:45 +03:00
|
|
|
save: K
|
2015-02-18 23:02:48 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'changed');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
RSVP.resolve(controller.get('lastPromise')).then(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('model.slug')).to.equal('changed');
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save the post when the slug changes and the post is not new', function (done) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
2016-01-15 18:43:16 +03:00
|
|
|
generateSlug(slugType, str) {
|
2016-06-11 19:52:36 +03:00
|
|
|
let promise = RSVP.resolve(str);
|
2015-02-18 23:02:48 +03:00
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'whatever',
|
|
|
|
saved: 0,
|
|
|
|
isNew: false,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'changed');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
RSVP.resolve(controller.get('lastPromise')).then(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('model.slug')).to.equal('changed');
|
|
|
|
expect(controller.get('model.saved')).to.equal(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not save the post when the slug changes and the post is new', function (done) {
|
2015-10-28 14:36:45 +03:00
|
|
|
let controller = this.subject({
|
2016-06-11 19:52:36 +03:00
|
|
|
slugGenerator: EmberObject.create({
|
2016-01-15 18:43:16 +03:00
|
|
|
generateSlug(slugType, str) {
|
2016-06-11 19:52:36 +03:00
|
|
|
let promise = RSVP.resolve(str);
|
2015-02-18 23:02:48 +03:00
|
|
|
this.set('lastPromise', promise);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}),
|
2016-06-11 19:52:36 +03:00
|
|
|
model: EmberObject.create({
|
2015-02-18 23:02:48 +03:00
|
|
|
slug: 'whatever',
|
|
|
|
saved: 0,
|
|
|
|
isNew: true,
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2015-02-18 23:02:48 +03:00
|
|
|
this.incrementProperty('saved');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
run(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
controller.set('slugValue', 'changed');
|
|
|
|
controller.send('updateSlug', controller.get('slugValue'));
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
RSVP.resolve(controller.get('lastPromise')).then(function () {
|
2015-02-18 23:02:48 +03:00
|
|
|
expect(controller.get('model.slug')).to.equal('changed');
|
|
|
|
expect(controller.get('model.saved')).to.equal(0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|