diff --git a/core/client/app/mirage/fixtures/settings.js b/core/client/app/mirage/fixtures/settings.js index eb7104fd8f..6ecffc3579 100644 --- a/core/client/app/mirage/fixtures/settings.js +++ b/core/client/app/mirage/fixtures/settings.js @@ -24,17 +24,6 @@ export default [ }, { id: 3, - uuid: '347cedbe-f867-4184-a04d-e176dff24053', - key: 'email', - value: 'info@example.com', - type: 'blog', - created_at: '2013-11-25T14:48:11.000Z', - created_by: 1, - updated_at: '2015-08-20T04:30:20.000Z', - updated_by: 1 - }, - { - id: 4, uuid: '4339ce48-b485-418a-acc2-1d34cf17a5e3', key: 'logo', value: '/content/images/2013/Nov/logo.png', @@ -45,7 +34,7 @@ export default [ updated_by: 1 }, { - id: 5, + id: 4, uuid: 'e41b6c2a-7f72-45ea-96d8-ee016f06d78b', key: 'cover', value: '/content/images/2014/Feb/cover.jpg', @@ -56,7 +45,7 @@ export default [ updated_by: 1 }, { - id: 6, + id: 5, uuid: '4558457e-9f61-47a5-9d45-8b83829bf1cf', key: 'defaultLang', value: 'en_US', @@ -69,7 +58,7 @@ export default [ { created_at: '2015-09-11T09:44:30.809Z', created_by: 1, - id: 7, + id: 6, key: 'postsPerPage', type: 'blog', updated_at: '2015-10-04T16:26:05.211Z', @@ -78,7 +67,7 @@ export default [ value: '5' }, { - id: 8, + id: 7, uuid: '3c93b240-d22b-473f-9063-537023e06c2d', key: 'forceI18n', value: 'true', @@ -89,7 +78,7 @@ export default [ updated_by: 1 }, { - id: 9, + id: 8, uuid: '4e58389f-f173-4387-b28c-0435623882ad', key: 'activeTheme', value: 'casper', @@ -100,7 +89,7 @@ export default [ updated_by: 1 }, { - id: 10, + id: 9, uuid: '8052c2bf-9c19-4d6c-8944-7465321d00be', key: 'permalinks', value: '/:slug/', @@ -113,7 +102,7 @@ export default [ { created_at: '2015-09-11T09:44:30.809Z', created_by: 1, - id: 11, + id: 10, key: 'ghost_head', type: 'blog', updated_at: '2015-09-23T13:32:49.858Z', @@ -124,7 +113,7 @@ export default [ { created_at: '2015-09-11T09:44:30.809Z', created_by: 1, - id: 12, + id: 11, key: 'ghost_foot', type: 'blog', updated_at: '2015-09-23T13:32:49.858Z', @@ -133,7 +122,7 @@ export default [ value: '' }, { - id: 13, + id: 12, uuid: 'd806f358-7996-4c74-b153-8876959c4b70', key: 'labs', value: '{"codeInjectionUI":true}', @@ -146,7 +135,7 @@ export default [ { created_at: '2015-09-11T09:44:30.810Z', created_by: 1, - id: 14, + id: 13, key: 'navigation', type: 'blog', updated_at: '2015-09-23T13:32:49.868Z', @@ -157,6 +146,28 @@ export default [ {label: 'About', url: '/about'} ]) }, + { + created_at: '2015-09-11T09:44:30.810Z', + created_by: 1, + id: 14, + key: 'isPrivate', + type: 'blog', + updated_at: '2015-09-23T13:32:49.868Z', + updated_by: 1, + uuid: 'e306ec3e-d079-11e5-ab30-625662870761', + value: false + }, + { + created_at: '2015-09-11T09:44:30.810Z', + created_by: 1, + id: 15, + key: 'password', + type: 'blog', + updated_at: '2015-09-23T13:32:49.868Z', + updated_by: 1, + uuid: 'f8e8cbda-d079-11e5-ab30-625662870761', + value: '' + }, { key: 'availableThemes', value: [ diff --git a/core/client/tests/acceptance/settings/general-test.js b/core/client/tests/acceptance/settings/general-test.js new file mode 100644 index 0000000000..23bcb946cc --- /dev/null +++ b/core/client/tests/acceptance/settings/general-test.js @@ -0,0 +1,161 @@ +/* jshint expr:true */ +import { + describe, + it, + beforeEach, + afterEach +} from 'mocha'; +import { expect } from 'chai'; +import Ember from 'ember'; +import startApp from '../../helpers/start-app'; +import destroyApp from '../../helpers/destroy-app'; +import { invalidateSession, authenticateSession } from 'ghost/tests/helpers/ember-simple-auth'; + +const {run} = Ember; + +describe('Acceptance: Settings - General', function () { + let application; + + beforeEach(function() { + application = startApp(); + }); + + afterEach(function() { + destroyApp(application); + }); + + it('redirects to signin when not authenticated', function () { + invalidateSession(application); + visit('/settings/general'); + + andThen(function() { + expect(currentURL(), 'currentURL').to.equal('/signin'); + }); + }); + + it('redirects to team page when authenticated as author', function () { + let role = server.create('role', {name: 'Author'}); + let user = server.create('user', {roles: [role], slug: 'test-user'}); + + authenticateSession(application); + visit('/settings/general'); + + andThen(() => { + expect(currentURL(), 'currentURL').to.equal('/team/test-user'); + }); + }); + + it('redirects to team page when authenticated as editor', function () { + let role = server.create('role', {name: 'Editor'}); + let user = server.create('user', {roles: [role], slug: 'test-user'}); + + authenticateSession(application); + visit('/settings/general'); + + andThen(() => { + expect(currentURL(), 'currentURL').to.equal('/team'); + }); + }); + + describe('when logged in', function () { + beforeEach(function () { + let role = server.create('role', {name: 'Administrator'}); + let user = server.create('user', {roles: [role]}); + + server.loadFixtures(); + + return authenticateSession(application); + }); + + it('it renders, shows image uploader modals', function () { + visit('/settings/general'); + + andThen(() => { + // has correct url + expect(currentURL(), 'currentURL').to.equal('/settings/general'); + + // has correct page title + expect(document.title, 'page title').to.equal('Settings - General - Test Blog'); + + // highlights nav menu + expect($('.gh-nav-settings-general').hasClass('active'), 'highlights nav menu item') + .to.be.true; + + expect(find('.view-header .view-actions .btn-blue').text().trim(), 'save button text').to.equal('Save'); + + // initial postsPerPage should be 5 + expect(find('input#postsPerPage').val(), 'post per page value').to.equal('5'); + + expect(find('input#permalinks').prop('checked'), 'date permalinks checkbox').to.be.false; + }); + + click('.blog-logo'); + + andThen(() => { + expect(find('.fullscreen-modal .modal-content .js-drop-zone').length, 'modal selector').to.equal(1); + }); + + click('.fullscreen-modal .modal-content .js-drop-zone .js-cancel'); + + andThen(() => { + expect(find('.fullscreen-modal .modal-content .js-drop-zone .description').text()).to.equal('Add image'); + }); + + // click cancel button + click('.fullscreen-modal .modal-footer .btn.btn-minor'); + + andThen(() => { + expect(find('.fullscreen-modal').length).to.equal(0); + }); + + click('.blog-cover'); + + andThen(() => { + expect(find('.fullscreen-modal .modal-content .js-drop-zone').length, 'modal selector').to.equal(1); + }); + + click('.fullscreen-modal .modal-footer .js-button-accept'); + + andThen(() => { + expect(find('.fullscreen-modal').length).to.equal(0); + }); + }); + + it('renders theme selector correctly', function () { + visit('/settings/general'); + + andThen(() => { + expect(currentURL(), 'currentURL').to.equal('/settings/general'); + + expect(find('#activeTheme select option').length, 'available themes').to.equal(1); + expect(find('#activeTheme select option').text().trim()).to.equal('Blog - 1.0'); + }); + }); + + it('handles private blog settings correctly', function () { + visit('/settings/general'); + + andThen(() => { + expect(currentURL(), 'currentURL').to.equal('/settings/general'); + + expect(find('input#isPrivate').prop('checked'), 'isPrivate checkbox').to.be.false; + }); + + click('input#isPrivate'); + + andThen(() => { + expect(find('input#isPrivate').prop('checked'), 'isPrivate checkbox').to.be.true; + expect(find('#settings-general input[name="general[password]"]').length, 'password input').to.equal(1); + expect(find('#settings-general input[name="general[password]"]').val(), 'password default value').to.not.equal(''); + }); + + fillIn('#settings-general input[name="general[password]"]', ''); + click('.view-header .view-actions .btn-blue'); + + andThen(() => { + expect(find('#settings-general .error .response').text().trim(), 'inline validation response') + .to.equal('Password must be supplied'); + }); + }); + }); +});