🎨 convert post-settings-menu into a component (#137)

no issue
- cleans up some of the render code
- aligns things with the "ember way"
- move metaTitleScratch and metaDescriptionScratch bindings to post model
This commit is contained in:
Austin Burdine 2017-03-10 07:30:01 -07:00 committed by Kevin Ansfield
parent 56e5e90334
commit ab287848d4
10 changed files with 196 additions and 203 deletions

View File

@ -1,29 +1,29 @@
import $ from 'jquery';
import Ember from 'ember';
import Controller from 'ember-controller';
import computed from 'ember-computed';
import Component from 'ember-component';
import computed, {alias} from 'ember-computed';
import {guidFor} from 'ember-metal/utils';
import injectService from 'ember-service/inject';
import injectController from 'ember-controller/inject';
import {htmlSafe} from 'ember-string';
import observer from 'ember-metal/observer';
import {invokeAction} from 'ember-invoke-action';
import {parseDateString} from 'ghost-admin/utils/date-formatting';
import SettingsMenuMixin from 'ghost-admin/mixins/settings-menu-controller';
import SettingsMenuMixin from 'ghost-admin/mixins/settings-menu-component';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import isNumber from 'ghost-admin/utils/isNumber';
const {ArrayProxy, Handlebars, PromiseProxyMixin} = Ember;
export default Controller.extend(SettingsMenuMixin, {
export default Component.extend(SettingsMenuMixin, {
selectedAuthor: null,
application: injectController(),
store: injectService(),
config: injectService(),
ghostPaths: injectService(),
notifications: injectService(),
session: injectService(),
slugGenerator: injectService(),
session: injectService(),
timeZone: injectService(),
initializeSelectedAuthor: observer('model', function () {
@ -37,7 +37,7 @@ export default Controller.extend(SettingsMenuMixin, {
// Loaded asynchronously, so must use promise proxies.
let deferred = {};
deferred.promise = this.store.query('user', {limit: 'all'}).then((users) => {
deferred.promise = this.get('store').query('user', {limit: 'all'}).then((users) => {
return users.rejectBy('id', 'me').sortBy('name');
}).then((users) => {
return users.filter((user) => {
@ -51,8 +51,8 @@ export default Controller.extend(SettingsMenuMixin, {
}),
slugValue: boundOneWay('model.slug'),
metaTitleScratch: boundOneWay('model.metaTitle'),
metaDescriptionScratch: boundOneWay('model.metaDescription'),
metaTitleScratch: alias('model.metaTitleScratch'),
metaDescriptionScratch: alias('model.metaDescriptionScratch'),
seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () {
let metaTitle = this.get('metaTitleScratch') || '';
@ -78,7 +78,7 @@ export default Controller.extend(SettingsMenuMixin, {
let html = this.get('model.html');
// Strip HTML
placeholder = $('<div />', {html}).text();
placeholder = this.$('<div />', {html}).text();
// Replace new lines and trim
placeholder = placeholder.replace(/\n+/g, ' ').trim();
}
@ -383,12 +383,12 @@ export default Controller.extend(SettingsMenuMixin, {
});
},
resetPubDate() {
this.set('publishedAtUTCValue', '');
closeNavMenu() {
invokeAction(this, 'closeNavMenu');
},
closeNavMenu() {
this.get('application').send('closeNavMenu');
closeMenus() {
invokeAction(this, 'closeMenus');
},
changeAuthor(newAuthor) {

View File

@ -37,7 +37,7 @@ export default Mixin.create({
showLeaveEditorModal: false,
showReAuthenticateModal: false,
postSettingsMenuController: injectController('post-settings-menu'),
application: injectController(),
notifications: injectService(),
clock: injectService(),
slugGenerator: injectService(),
@ -398,7 +398,6 @@ export default Mixin.create({
save(options) {
let prevStatus = this.get('model.status');
let isNew = this.get('model.isNew');
let psmController = this.get('postSettingsMenuController');
let promise, status;
options = options || {};
@ -433,8 +432,8 @@ export default Mixin.create({
}
this.set('model.title', this.get('model.titleScratch'));
this.set('model.metaTitle', psmController.get('metaTitleScratch'));
this.set('model.metaDescription', psmController.get('metaDescriptionScratch'));
this.set('model.metaTitle', this.get('model.metaTitleScratch'));
this.set('model.metaDescription', this.get('model.metaDescriptionScratch'));
if (!this.get('model.slug')) {
this.get('updateTitle').cancelAll();
@ -496,6 +495,14 @@ export default Mixin.create({
}
},
closeNavMenu() {
this.get('application').send('closeAutoNav');
},
closeMenus() {
this.get('application').send('closeMenus');
},
toggleLeaveEditorModal(transition) {
this.set('leaveEditorTransition', transition);
this.toggleProperty('showLeaveEditorModal');

View File

@ -1,6 +1,5 @@
import $ from 'jquery';
import Mixin from 'ember-metal/mixin';
import RSVP from 'rsvp';
import run from 'ember-runloop';
import ShortcutsRoute from 'ghost-admin/mixins/shortcuts-route';
@ -52,11 +51,9 @@ export default Mixin.create(styleBody, ShortcutsRoute, {
// so we abort the transition and retry after the save has completed.
if (state.isSaving) {
transition.abort();
return run.later(this, function () {
RSVP.resolve(controller.get('lastPromise')).then(() => {
transition.retry();
});
}, 100);
controller.get('generateSlug.last').then(() => {
transition.retry();
});
}
fromNewToEdit = this.get('routeName') === 'editor.new'
@ -94,16 +91,6 @@ export default Mixin.create(styleBody, ShortcutsRoute, {
}
},
renderTemplate(controller, model) {
this._super(controller, model);
this.render('post-settings-menu', {
model,
into: 'application',
outlet: 'settings-menu'
});
},
attachModelHooks(controller, model) {
// this will allow us to track when the model is saved and update the controller
// so that we can be sure controller.hasDirtyAttributes is correct, without having to update the

View File

@ -1,17 +1,16 @@
import Mixin from 'ember-metal/mixin';
import computed from 'ember-computed';
import injectController from 'ember-controller/inject';
export default Mixin.create({
application: injectController(),
showSettingsMenu: false,
isViewingSubview: computed('application.showSettingsMenu', {
isViewingSubview: computed('showSettingsMenu', {
get() {
return false;
},
set(key, value) {
// Not viewing a subview if we can't even see the PSM
if (!this.get('application.showSettingsMenu')) {
if (!this.get('showSettingsMenu')) {
return false;
}
return value;

View File

@ -8,6 +8,7 @@ import attr from 'ember-data/attr';
import {belongsTo, hasMany} from 'ember-data/relationships';
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import {BLANK_DOC} from 'ghost-admin/components/gh-koenig'; // a blank mobile doc
@ -119,6 +120,8 @@ export default Model.extend(Comparable, ValidationEngine, {
scratch: null,
titleScratch: null,
metaTitleScratch: boundOneWay('metaTitle'),
metaDescriptionScratch: boundOneWay('metaDescription'),
// Computed post properties

View File

@ -17,25 +17,6 @@ export default AuthenticatedRoute.extend(base, {
controller,
model
});
this.render('post-settings-menu', {
model,
into: 'application',
outlet: 'settings-menu'
});
},
setupController() {
let psm = this.controllerFor('post-settings-menu');
// make sure there are no titleObserver functions hanging around
// from previous posts
psm.removeObserver('titleScratch', psm, 'titleObserver');
// Ensure that the PSM Publish Date selector resets
psm.send('resetPubDate');
this._super(...arguments);
},
actions: {

View File

@ -17,7 +17,6 @@
{{gh-content-cover onClick="closeMenus" onMouseEnter="closeAutoNav"}}
{{outlet "settings-menu"}}
{{gh-mobile-nav-bar}}
</div>{{!gh-viewport}}
{{/gh-app}}

View File

@ -75,3 +75,12 @@
close=(action "toggleReAuthenticateModal")
modifier="action wide"}}
{{/if}}
{{#liquid-wormhole}}
{{gh-post-settings-menu
model=model
showSettingsMenu=application.showSettingsMenu
closeNavMenu=(action "closeNavMenu")
closeMenus=(action "closeMenus")
}}
{{/liquid-wormhole}}

View File

@ -3,163 +3,170 @@ import run from 'ember-runloop';
import RSVP from 'rsvp';
import EmberObject from 'ember-object';
import {describe, it} from 'mocha';
import {setupTest} from 'ember-mocha';
import {setupComponentTest} from 'ember-mocha';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
function K() {
return this;
}
describe('Unit: Controller: post-settings-menu', function () {
setupTest('controller:post-settings-menu', {
needs: ['controller:application', 'service:notifications', 'service:slug-generator', 'service:timeZone']
describe('Unit: Component: post-settings-menu', function () {
setupComponentTest('gh-post-settings-menu', {
needs: ['service:notifications', 'service:slug-generator', 'service:timeZone']
});
it('slugValue is one-way bound to model.slug', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
slug: 'a-slug'
})
});
expect(controller.get('model.slug')).to.equal('a-slug');
expect(controller.get('slugValue')).to.equal('a-slug');
expect(component.get('model.slug')).to.equal('a-slug');
expect(component.get('slugValue')).to.equal('a-slug');
run(function () {
controller.set('model.slug', 'changed-slug');
component.set('model.slug', 'changed-slug');
expect(controller.get('slugValue')).to.equal('changed-slug');
expect(component.get('slugValue')).to.equal('changed-slug');
});
run(function () {
controller.set('slugValue', 'changed-directly');
component.set('slugValue', 'changed-directly');
expect(controller.get('model.slug')).to.equal('changed-slug');
expect(controller.get('slugValue')).to.equal('changed-directly');
expect(component.get('model.slug')).to.equal('changed-slug');
expect(component.get('slugValue')).to.equal('changed-directly');
});
run(function () {
// test that the one-way binding is still in place
controller.set('model.slug', 'should-update');
component.set('model.slug', 'should-update');
expect(controller.get('slugValue')).to.equal('should-update');
expect(component.get('slugValue')).to.equal('should-update');
});
});
it('metaTitleScratch is one-way bound to model.metaTitle', function () {
let controller = this.subject({
model: EmberObject.create({
metaTitle: 'a title'
})
let component = this.subject({
model: EmberObject.extend({
metaTitle: 'a title',
metaTitleScratch: boundOneWay('metaTitle')
}).create()
});
expect(controller.get('model.metaTitle')).to.equal('a title');
expect(controller.get('metaTitleScratch')).to.equal('a title');
expect(component.get('model.metaTitle')).to.equal('a title');
expect(component.get('metaTitleScratch')).to.equal('a title');
run(function () {
controller.set('model.metaTitle', 'a different title');
component.set('model.metaTitle', 'a different title');
expect(controller.get('metaTitleScratch')).to.equal('a different title');
expect(component.get('metaTitleScratch')).to.equal('a different title');
});
run(function () {
controller.set('metaTitleScratch', 'changed directly');
component.set('metaTitleScratch', 'changed directly');
expect(controller.get('model.metaTitle')).to.equal('a different title');
expect(controller.get('metaTitleScratch')).to.equal('changed directly');
expect(component.get('model.metaTitle')).to.equal('a different title');
expect(component.get('model.metaTitleScratch')).to.equal('changed directly');
});
run(function () {
// test that the one-way binding is still in place
controller.set('model.metaTitle', 'should update');
component.set('model.metaTitle', 'should update');
expect(controller.get('metaTitleScratch')).to.equal('should update');
expect(component.get('metaTitleScratch')).to.equal('should update');
});
});
it('metaDescriptionScratch is one-way bound to model.metaDescription', function () {
let controller = this.subject({
model: EmberObject.create({
metaDescription: 'a description'
})
let component = this.subject({
model: EmberObject.extend({
metaDescription: 'a description',
metaDescriptionScratch: boundOneWay('metaDescription')
}).create()
});
expect(controller.get('model.metaDescription')).to.equal('a description');
expect(controller.get('metaDescriptionScratch')).to.equal('a description');
expect(component.get('model.metaDescription')).to.equal('a description');
expect(component.get('metaDescriptionScratch')).to.equal('a description');
run(function () {
controller.set('model.metaDescription', 'a different description');
component.set('model.metaDescription', 'a different description');
expect(controller.get('metaDescriptionScratch')).to.equal('a different description');
expect(component.get('metaDescriptionScratch')).to.equal('a different description');
});
run(function () {
controller.set('metaDescriptionScratch', 'changed directly');
component.set('metaDescriptionScratch', 'changed directly');
expect(controller.get('model.metaDescription')).to.equal('a different description');
expect(controller.get('metaDescriptionScratch')).to.equal('changed directly');
expect(component.get('model.metaDescription')).to.equal('a different description');
expect(component.get('metaDescriptionScratch')).to.equal('changed directly');
});
run(function () {
// test that the one-way binding is still in place
controller.set('model.metaDescription', 'should update');
component.set('model.metaDescription', 'should update');
expect(controller.get('metaDescriptionScratch')).to.equal('should update');
expect(component.get('metaDescriptionScratch')).to.equal('should update');
});
});
describe('seoTitle', function () {
it('should be the metaTitle if one exists', function () {
let controller = this.subject({
model: EmberObject.create({
let component = this.subject({
model: EmberObject.extend({
metaTitle: 'a meta-title',
metaTitleScratch: boundOneWay('metaTitle'),
titleScratch: 'should not be used'
})
}).create()
});
expect(controller.get('seoTitle')).to.equal('a meta-title');
expect(component.get('seoTitle')).to.equal('a meta-title');
});
it('should default to the title if an explicit meta-title does not exist', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
titleScratch: 'should be the meta-title'
})
});
expect(controller.get('seoTitle')).to.equal('should be the meta-title');
expect(component.get('seoTitle')).to.equal('should be the meta-title');
});
it('should be the metaTitle if both title and metaTitle exist', function () {
let controller = this.subject({
model: EmberObject.create({
let component = this.subject({
model: EmberObject.extend({
metaTitle: 'a meta-title',
metaTitleScratch: boundOneWay('metaTitle'),
titleScratch: 'a title'
})
}).create()
});
expect(controller.get('seoTitle')).to.equal('a meta-title');
expect(component.get('seoTitle')).to.equal('a meta-title');
});
it('should revert to the title if explicit metaTitle is removed', function () {
let controller = this.subject({
model: EmberObject.create({
let component = this.subject({
model: EmberObject.extend({
metaTitle: 'a meta-title',
metaTitleScratch: boundOneWay('metaTitle'),
titleScratch: 'a title'
})
}).create()
});
expect(controller.get('seoTitle')).to.equal('a meta-title');
expect(component.get('seoTitle')).to.equal('a meta-title');
run(function () {
controller.set('model.metaTitle', '');
component.set('model.metaTitle', '');
expect(controller.get('seoTitle')).to.equal('a title');
expect(component.get('seoTitle')).to.equal('a title');
});
});
it('should truncate to 70 characters with an appended ellipsis', function () {
let longTitle = new Array(100).join('a');
let controller = this.subject({
let component = this.subject({
model: EmberObject.create()
});
@ -168,23 +175,24 @@ describe('Unit: Controller: post-settings-menu', function () {
run(function () {
let expected = `${longTitle.substr(0, 70)}&hellip;`;
controller.set('metaTitleScratch', longTitle);
component.set('metaTitleScratch', longTitle);
expect(controller.get('seoTitle').toString().length).to.equal(78);
expect(controller.get('seoTitle').toString()).to.equal(expected);
expect(component.get('seoTitle').toString().length).to.equal(78);
expect(component.get('seoTitle').toString()).to.equal(expected);
});
});
});
describe('seoDescription', function () {
it('should be the metaDescription if one exists', function () {
let controller = this.subject({
model: EmberObject.create({
metaDescription: 'a description'
})
let component = this.subject({
model: EmberObject.extend({
metaDescription: 'a description',
metaDescriptionScratch: boundOneWay('metaDescription')
}).create()
});
expect(controller.get('seoDescription')).to.equal('a description');
expect(component.get('seoDescription')).to.equal('a description');
});
it.skip('should be generated from the rendered markdown if not explicitly set', function () {
@ -194,7 +202,7 @@ describe('Unit: Controller: post-settings-menu', function () {
it('should truncate to 156 characters with an appended ellipsis', function () {
let longDescription = new Array(200).join('a');
let controller = this.subject({
let component = this.subject({
model: EmberObject.create()
});
@ -203,52 +211,52 @@ describe('Unit: Controller: post-settings-menu', function () {
run(function () {
let expected = `${longDescription.substr(0, 156)}&hellip;`;
controller.set('metaDescriptionScratch', longDescription);
component.set('metaDescriptionScratch', longDescription);
expect(controller.get('seoDescription').toString().length).to.equal(164);
expect(controller.get('seoDescription').toString()).to.equal(expected);
expect(component.get('seoDescription').toString().length).to.equal(164);
expect(component.get('seoDescription').toString()).to.equal(expected);
});
});
});
describe('seoURL', function () {
it('should be the URL of the blog if no post slug exists', function () {
let controller = this.subject({
let component = this.subject({
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
model: EmberObject.create()
});
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/');
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/');
});
it('should be the URL of the blog plus the post slug', function () {
let controller = this.subject({
let component = this.subject({
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
model: EmberObject.create({slug: 'post-slug'})
});
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
});
it('should update when the post slug changes', function () {
let controller = this.subject({
let component = this.subject({
config: EmberObject.create({blogUrl: 'http://my-ghost-blog.com'}),
model: EmberObject.create({slug: 'post-slug'})
});
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
expect(component.get('seoURL')).to.equal('http://my-ghost-blog.com/post-slug/');
run(function () {
controller.set('model.slug', 'changed-slug');
component.set('model.slug', 'changed-slug');
expect(controller.get('seoURL')).to.equal('http://my-ghost-blog.com/changed-slug/');
expect(component.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 () {
let blogURL = 'http://my-ghost-blog.com';
let longSlug = new Array(75).join('a');
let controller = this.subject({
let component = this.subject({
config: EmberObject.create({blogUrl: blogURL}),
model: EmberObject.create({slug: longSlug})
});
@ -259,31 +267,31 @@ describe('Unit: Controller: post-settings-menu', function () {
expected = `${blogURL}/${longSlug}/`;
expected = `${expected.substr(0, 70)}&hellip;`;
expect(controller.get('seoURL').toString().length).to.equal(78);
expect(controller.get('seoURL').toString()).to.equal(expected);
expect(component.get('seoURL').toString().length).to.equal(78);
expect(component.get('seoURL').toString()).to.equal(expected);
});
});
describe('togglePage', function () {
it('should toggle the page property', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
page: false,
isNew: true
})
});
expect(controller.get('model.page')).to.not.be.ok;
expect(component.get('model.page')).to.not.be.ok;
run(function () {
controller.send('togglePage');
component.send('togglePage');
expect(controller.get('model.page')).to.be.ok;
expect(component.get('model.page')).to.be.ok;
});
});
it('should not save the post if it is still new', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
page: false,
isNew: true,
@ -295,15 +303,15 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.send('togglePage');
component.send('togglePage');
expect(controller.get('model.page')).to.be.ok;
expect(controller.get('model.saved')).to.not.be.ok;
expect(component.get('model.page')).to.be.ok;
expect(component.get('model.saved')).to.not.be.ok;
});
});
it('should save the post if it is not new', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
page: false,
isNew: false,
@ -315,17 +323,17 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.send('togglePage');
component.send('togglePage');
expect(controller.get('model.page')).to.be.ok;
expect(controller.get('model.saved')).to.equal(1);
expect(component.get('model.page')).to.be.ok;
expect(component.get('model.saved')).to.equal(1);
});
});
});
describe('toggleFeatured', function () {
it('should toggle the featured property', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
featured: false,
isNew: true
@ -333,14 +341,14 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.send('toggleFeatured');
component.send('toggleFeatured');
expect(controller.get('model.featured')).to.be.ok;
expect(component.get('model.featured')).to.be.ok;
});
});
it('should not save the post if it is still new', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
featured: false,
isNew: true,
@ -352,15 +360,15 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.send('toggleFeatured');
component.send('toggleFeatured');
expect(controller.get('model.featured')).to.be.ok;
expect(controller.get('model.saved')).to.not.be.ok;
expect(component.get('model.featured')).to.be.ok;
expect(component.get('model.saved')).to.not.be.ok;
});
});
it('should save the post if it is not new', function () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
featured: false,
isNew: false,
@ -372,17 +380,17 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.send('toggleFeatured');
component.send('toggleFeatured');
expect(controller.get('model.featured')).to.be.ok;
expect(controller.get('model.saved')).to.equal(1);
expect(component.get('model.featured')).to.be.ok;
expect(component.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 () {
let controller = this.subject({
let component = this.subject({
model: EmberObject.create({
slug: 'slug'
})
@ -390,34 +398,34 @@ describe('Unit: Controller: post-settings-menu', function () {
run(function () {
// unchanged
controller.set('slugValue', 'slug');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'slug');
component.send('updateSlug', component.get('slugValue'));
expect(controller.get('model.slug')).to.equal('slug');
expect(controller.get('slugValue')).to.equal('slug');
expect(component.get('model.slug')).to.equal('slug');
expect(component.get('slugValue')).to.equal('slug');
});
run(function () {
// unchanged after trim
controller.set('slugValue', 'slug ');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'slug ');
component.send('updateSlug', component.get('slugValue'));
expect(controller.get('model.slug')).to.equal('slug');
expect(controller.get('slugValue')).to.equal('slug');
expect(component.get('model.slug')).to.equal('slug');
expect(component.get('slugValue')).to.equal('slug');
});
run(function () {
// blank
controller.set('slugValue', '');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', '');
component.send('updateSlug', component.get('slugValue'));
expect(controller.get('model.slug')).to.equal('slug');
expect(controller.get('slugValue')).to.equal('slug');
expect(component.get('model.slug')).to.equal('slug');
expect(component.get('slugValue')).to.equal('slug');
});
});
it('should not set a new slug if the server-generated slug matches existing slug', function (done) {
let controller = this.subject({
let component = this.subject({
slugGenerator: EmberObject.create({
generateSlug(slugType, str) {
let promise = RSVP.resolve(str.split('#')[0]);
@ -431,11 +439,11 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.set('slugValue', 'whatever#slug');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'whatever#slug');
component.send('updateSlug', component.get('slugValue'));
RSVP.resolve(controller.get('lastPromise')).then(function () {
expect(controller.get('model.slug')).to.equal('whatever');
RSVP.resolve(component.get('lastPromise')).then(function () {
expect(component.get('model.slug')).to.equal('whatever');
done();
}).catch(done);
@ -443,7 +451,7 @@ describe('Unit: Controller: post-settings-menu', function () {
});
it('should not set a new slug if the only change is to the appended increment value', function (done) {
let controller = this.subject({
let component = this.subject({
slugGenerator: EmberObject.create({
generateSlug(slugType, str) {
let sanitizedStr = str.replace(/[^a-zA-Z]/g, '');
@ -458,11 +466,11 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.set('slugValue', 'whatever!');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'whatever!');
component.send('updateSlug', component.get('slugValue'));
RSVP.resolve(controller.get('lastPromise')).then(function () {
expect(controller.get('model.slug')).to.equal('whatever');
RSVP.resolve(component.get('lastPromise')).then(function () {
expect(component.get('model.slug')).to.equal('whatever');
done();
}).catch(done);
@ -470,7 +478,7 @@ describe('Unit: Controller: post-settings-menu', function () {
});
it('should set the slug if the new slug is different', function (done) {
let controller = this.subject({
let component = this.subject({
slugGenerator: EmberObject.create({
generateSlug(slugType, str) {
let promise = RSVP.resolve(str);
@ -485,11 +493,11 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.set('slugValue', 'changed');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'changed');
component.send('updateSlug', component.get('slugValue'));
RSVP.resolve(controller.get('lastPromise')).then(function () {
expect(controller.get('model.slug')).to.equal('changed');
RSVP.resolve(component.get('lastPromise')).then(function () {
expect(component.get('model.slug')).to.equal('changed');
done();
}).catch(done);
@ -497,7 +505,7 @@ describe('Unit: Controller: post-settings-menu', function () {
});
it('should save the post when the slug changes and the post is not new', function (done) {
let controller = this.subject({
let component = this.subject({
slugGenerator: EmberObject.create({
generateSlug(slugType, str) {
let promise = RSVP.resolve(str);
@ -516,12 +524,12 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.set('slugValue', 'changed');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'changed');
component.send('updateSlug', component.get('slugValue'));
RSVP.resolve(controller.get('lastPromise')).then(function () {
expect(controller.get('model.slug')).to.equal('changed');
expect(controller.get('model.saved')).to.equal(1);
RSVP.resolve(component.get('lastPromise')).then(function () {
expect(component.get('model.slug')).to.equal('changed');
expect(component.get('model.saved')).to.equal(1);
done();
}).catch(done);
@ -529,7 +537,7 @@ describe('Unit: Controller: post-settings-menu', function () {
});
it('should not save the post when the slug changes and the post is new', function (done) {
let controller = this.subject({
let component = this.subject({
slugGenerator: EmberObject.create({
generateSlug(slugType, str) {
let promise = RSVP.resolve(str);
@ -548,12 +556,12 @@ describe('Unit: Controller: post-settings-menu', function () {
});
run(function () {
controller.set('slugValue', 'changed');
controller.send('updateSlug', controller.get('slugValue'));
component.set('slugValue', 'changed');
component.send('updateSlug', component.get('slugValue'));
RSVP.resolve(controller.get('lastPromise')).then(function () {
expect(controller.get('model.slug')).to.equal('changed');
expect(controller.get('model.saved')).to.equal(0);
RSVP.resolve(component.get('lastPromise')).then(function () {
expect(component.get('model.slug')).to.equal('changed');
expect(component.get('model.saved')).to.equal(0);
done();
}).catch(done);