2017-10-10 15:26:19 +03:00
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
2019-01-02 12:58:55 +03:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
|
|
import {authenticateSession} from 'ember-simple-auth/test-support';
|
|
|
|
import {beforeEach, describe, it} from 'mocha';
|
|
|
|
import {click, fillIn, find, triggerKeyEvent, visit} from '@ember/test-helpers';
|
2017-10-10 15:26:19 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2017-10-10 15:26:19 +03:00
|
|
|
|
|
|
|
// keyCodes
|
|
|
|
const KEY_S = 83;
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Acceptance: Custom Post Templates', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
this.server.loadFixtures('settings');
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
let role = this.server.create('role', {name: 'Administrator'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
return await authenticateSession();
|
2017-10-10 15:26:19 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with custom templates', function () {
|
|
|
|
beforeEach(function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.create('theme', {
|
2017-10-10 15:26:19 +03:00
|
|
|
active: true,
|
|
|
|
name: 'example-theme',
|
|
|
|
package: {
|
|
|
|
name: 'Example Theme',
|
|
|
|
version: '0.1'
|
|
|
|
},
|
|
|
|
templates: [
|
|
|
|
{
|
|
|
|
filename: 'custom-news-bulletin.hbs',
|
|
|
|
name: 'News Bulletin',
|
|
|
|
for: ['post', 'page'],
|
|
|
|
slug: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'custom-big-images.hbs',
|
|
|
|
name: 'Big Images',
|
|
|
|
for: ['post', 'page'],
|
|
|
|
slug: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'post-one.hbs',
|
|
|
|
name: 'One',
|
|
|
|
for: ['post'],
|
|
|
|
slug: 'one'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'page-about.hbs',
|
|
|
|
name: 'About',
|
|
|
|
for: ['page'],
|
|
|
|
slug: 'about'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can change selected template', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let post = this.server.create('post', {customTemplate: 'custom-news-bulletin.hbs'});
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-02-22 06:17:33 +03:00
|
|
|
await visit('/editor/post/1');
|
2017-10-10 15:26:19 +03:00
|
|
|
await click('[data-test-psm-trigger]');
|
|
|
|
|
|
|
|
// template form should be shown
|
|
|
|
expect(find('[data-test-custom-template-form]')).to.exist;
|
|
|
|
|
|
|
|
// custom template should be selected
|
|
|
|
let select = find('[data-test-select="custom-template"]');
|
|
|
|
expect(select.value, 'selected value').to.equal('custom-news-bulletin.hbs');
|
|
|
|
|
|
|
|
// templates list should contain default and custom templates in alphabetical order
|
|
|
|
expect(select.options.length).to.equal(3);
|
|
|
|
expect(select.options.item(0).value, 'default value').to.equal('');
|
|
|
|
expect(select.options.item(0).text, 'default text').to.equal('Default');
|
|
|
|
expect(select.options.item(1).value, 'first custom value').to.equal('custom-big-images.hbs');
|
|
|
|
expect(select.options.item(1).text, 'first custom text').to.equal('Big Images');
|
|
|
|
expect(select.options.item(2).value, 'second custom value').to.equal('custom-news-bulletin.hbs');
|
|
|
|
expect(select.options.item(2).text, 'second custom text').to.equal('News Bulletin');
|
|
|
|
|
|
|
|
// select the default template
|
|
|
|
await fillIn(select, '');
|
|
|
|
|
|
|
|
// save then check server record
|
2019-01-02 12:58:55 +03:00
|
|
|
await triggerKeyEvent('.gh-app', 'keydown', KEY_S, {
|
2017-10-10 15:26:19 +03:00
|
|
|
metaKey: ctrlOrCmd === 'command',
|
|
|
|
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.db.posts.find(post.id).customTemplate,
|
2017-10-10 15:26:19 +03:00
|
|
|
'saved custom template'
|
|
|
|
).to.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables template selector if slug matches slug-based template');
|
|
|
|
|
|
|
|
it('doesn\'t query themes endpoint unncessarily', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
// eslint-disable-next-line
|
|
|
|
let themeRequests = () => {
|
|
|
|
return this.server.pretender.handledRequests.filter(function (request) {
|
2017-10-10 15:26:19 +03:00
|
|
|
return request.url.match(/\/themes\//);
|
|
|
|
});
|
2019-01-02 12:58:55 +03:00
|
|
|
};
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.create('post', {customTemplate: 'custom-news-bulletin.hbs'});
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-02-22 06:17:33 +03:00
|
|
|
await visit('/editor/post/1');
|
2017-10-10 15:26:19 +03:00
|
|
|
await click('[data-test-psm-trigger]');
|
|
|
|
|
|
|
|
expect(themeRequests().length, 'after first open').to.equal(1);
|
|
|
|
|
|
|
|
await click('[data-test-psm-trigger]'); // hide
|
|
|
|
await click('[data-test-psm-trigger]'); // show
|
|
|
|
|
|
|
|
expect(themeRequests().length, 'after second open').to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without custom templates', function () {
|
|
|
|
beforeEach(function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.create('theme', {
|
2017-10-10 15:26:19 +03:00
|
|
|
active: true,
|
|
|
|
name: 'example-theme',
|
|
|
|
package: {
|
|
|
|
name: 'Example Theme',
|
|
|
|
version: '0.1'
|
|
|
|
},
|
|
|
|
templates: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('doesn\'t show template selector', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.create('post', {customTemplate: 'custom-news-bulletin.hbs'});
|
2017-10-10 15:26:19 +03:00
|
|
|
|
2019-02-22 06:17:33 +03:00
|
|
|
await visit('/editor/post/1');
|
2017-10-10 15:26:19 +03:00
|
|
|
await click('[data-test-psm-trigger]');
|
|
|
|
|
|
|
|
// template form should be shown
|
|
|
|
expect(find('[data-test-custom-template-form]')).to.not.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|