2017-08-22 10:53:26 +03:00
|
|
|
import EmberObject from '@ember/object';
|
2016-05-24 15:06:59 +03:00
|
|
|
import NavItem from 'ghost-admin/models/navigation-item';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {assert, expect} from 'chai';
|
|
|
|
import {describe, it} from 'mocha';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {run} from '@ember/runloop';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {setupTest} from 'ember-mocha';
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-14 16:16:51 +03:00
|
|
|
// const navSettingJSON = `[
|
|
|
|
// {"label":"Home","url":"/"},
|
|
|
|
// {"label":"JS Test","url":"javascript:alert('hello');"},
|
|
|
|
// {"label":"About","url":"/about"},
|
|
|
|
// {"label":"Sub Folder","url":"/blah/blah"},
|
|
|
|
// {"label":"Telephone","url":"tel:01234-567890"},
|
|
|
|
// {"label":"Mailto","url":"mailto:test@example.com"},
|
|
|
|
// {"label":"External","url":"https://example.com/testing?query=test#anchor"},
|
|
|
|
// {"label":"No Protocol","url":"//example.com"}
|
|
|
|
// ]`;
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2017-02-21 22:04:50 +03:00
|
|
|
describe('Unit: Controller: settings/design', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
setupTest();
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('blogUrl: captures config and ensures trailing slash', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
ctrl.set('config.blogUrl', 'http://localhost:2368/blog');
|
|
|
|
expect(ctrl.get('blogUrl')).to.equal('http://localhost:2368/blog/');
|
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('init: creates a new navigation item', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
|
|
|
expect(ctrl.get('newNavItem')).to.exist;
|
|
|
|
expect(ctrl.get('newNavItem.isNew')).to.be.true;
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('blogUrl: captures config and ensures trailing slash', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
ctrl.set('config.blogUrl', 'http://localhost:2368/blog');
|
|
|
|
expect(ctrl.get('blogUrl')).to.equal('http://localhost:2368/blog/');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('save: validates nav items', function (done) {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: [
|
2018-01-05 18:38:23 +03:00
|
|
|
NavItem.create({label: 'First', url: '/'}),
|
|
|
|
NavItem.create({label: '', url: '/second'}),
|
|
|
|
NavItem.create({label: 'Third', url: ''})
|
2016-11-24 01:50:57 +03:00
|
|
|
]}));
|
|
|
|
// blank item won't get added because the last item is incomplete
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(3);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2017-03-08 16:55:35 +03:00
|
|
|
ctrl.get('save').perform().then(function passedValidation() {
|
2016-11-24 01:50:57 +03:00
|
|
|
assert(false, 'navigationItems weren\'t validated on save');
|
|
|
|
done();
|
|
|
|
}).catch(function failedValidation() {
|
2018-01-11 01:57:43 +03:00
|
|
|
let navItems = ctrl.get('settings.navigation');
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(navItems[0].get('errors').toArray()).to.be.empty;
|
|
|
|
expect(navItems[1].get('errors.firstObject.attribute')).to.equal('label');
|
|
|
|
expect(navItems[2].get('errors.firstObject.attribute')).to.equal('url');
|
|
|
|
done();
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
it('save: ignores blank last item when saving', function (done) {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-02-04 18:33:33 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: [
|
2018-01-05 18:38:23 +03:00
|
|
|
NavItem.create({label: 'First', url: '/'}),
|
|
|
|
NavItem.create({label: '', url: ''})
|
2016-11-24 01:50:57 +03:00
|
|
|
]}));
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(2);
|
2016-02-09 20:16:18 +03:00
|
|
|
|
2017-03-08 16:55:35 +03:00
|
|
|
ctrl.get('save').perform().then(function passedValidation() {
|
2016-11-24 01:50:57 +03:00
|
|
|
assert(false, 'navigationItems weren\'t validated on save');
|
|
|
|
done();
|
|
|
|
}).catch(function failedValidation() {
|
2018-01-11 01:57:43 +03:00
|
|
|
let navItems = ctrl.get('settings.navigation');
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(navItems[0].get('errors').toArray()).to.be.empty;
|
|
|
|
done();
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2017-02-21 22:04:50 +03:00
|
|
|
it('action - addNavItem: adds item to navigationItems', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: [
|
2016-11-24 01:50:57 +03:00
|
|
|
NavItem.create({label: 'First', url: '/first', last: true})
|
|
|
|
]}));
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(1);
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
ctrl.set('newNavItem.label', 'New');
|
|
|
|
ctrl.set('newNavItem.url', '/new');
|
|
|
|
|
|
|
|
run(() => {
|
2017-02-21 22:04:50 +03:00
|
|
|
ctrl.send('addNavItem');
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
|
|
|
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(2);
|
|
|
|
expect(ctrl.get('settings.navigation.lastObject.label')).to.equal('New');
|
|
|
|
expect(ctrl.get('settings.navigation.lastObject.url')).to.equal('/new');
|
|
|
|
expect(ctrl.get('settings.navigation.lastObject.isNew')).to.be.false;
|
2018-03-26 13:41:45 +03:00
|
|
|
expect(ctrl.get('newNavItem.label')).to.be.empty;
|
|
|
|
expect(ctrl.get('newNavItem.url')).to.be.empty;
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(ctrl.get('newNavItem.isNew')).to.be.true;
|
|
|
|
});
|
|
|
|
|
2017-02-21 22:04:50 +03:00
|
|
|
it('action - addNavItem: doesn\'t insert new item if last object is incomplete', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: [
|
2016-11-24 01:50:57 +03:00
|
|
|
NavItem.create({label: '', url: '', last: true})
|
|
|
|
]}));
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(1);
|
2017-02-21 22:04:50 +03:00
|
|
|
ctrl.send('addNavItem');
|
2018-01-11 01:57:43 +03:00
|
|
|
expect(ctrl.get('settings.navigation.length')).to.equal(1);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-21 22:04:50 +03:00
|
|
|
it('action - deleteNavItem: removes item from navigationItems', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
let navItems = [
|
|
|
|
NavItem.create({label: 'First', url: '/first'}),
|
|
|
|
NavItem.create({label: 'Second', url: '/second', last: true})
|
|
|
|
];
|
|
|
|
|
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: navItems}));
|
|
|
|
expect(ctrl.get('settings.navigation').mapBy('label')).to.deep.equal(['First', 'Second']);
|
|
|
|
ctrl.send('deleteNavItem', ctrl.get('settings.navigation.firstObject'));
|
|
|
|
expect(ctrl.get('settings.navigation').mapBy('label')).to.deep.equal(['Second']);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('action - updateUrl: updates URL on navigationItem', function () {
|
2019-05-13 15:43:53 +03:00
|
|
|
let ctrl = this.owner.lookup('controller:settings/design');
|
2016-11-24 01:50:57 +03:00
|
|
|
let navItems = [
|
|
|
|
NavItem.create({label: 'First', url: '/first'}),
|
|
|
|
NavItem.create({label: 'Second', url: '/second', last: true})
|
|
|
|
];
|
|
|
|
|
|
|
|
run(() => {
|
2018-01-11 01:57:43 +03:00
|
|
|
ctrl.set('settings', EmberObject.create({navigation: navItems}));
|
|
|
|
expect(ctrl.get('settings.navigation').mapBy('url')).to.deep.equal(['/first', '/second']);
|
|
|
|
ctrl.send('updateUrl', '/new', ctrl.get('settings.navigation.firstObject'));
|
|
|
|
expect(ctrl.get('settings.navigation').mapBy('url')).to.deep.equal(['/new', '/second']);
|
2015-09-16 20:02:06 +03:00
|
|
|
});
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|