2021-11-01 20:48:49 +03:00
|
|
|
import enableLabsFlag from '../../helpers/enable-labs-flag';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
2021-11-01 20:48:49 +03:00
|
|
|
import {click, currentURL, find, findAll} from '@ember/test-helpers';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2021-01-22 15:28:05 +03:00
|
|
|
import {fileUpload} from '../../helpers/file-upload';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {visit} from '../../helpers/visit';
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
describe('Acceptance: Settings - Design', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
enableLabsFlag(this.server, 'customThemeSettings');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
let role = this.server.create('role', {name: 'Administrator'});
|
|
|
|
this.server.create('user', {roles: [role]});
|
2018-02-07 12:42:46 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
this.server.loadFixtures('themes');
|
2018-02-07 12:42:46 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
return await authenticateSession();
|
2018-02-07 12:42:46 +03:00
|
|
|
});
|
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('redirects to signin when not authenticated', async function () {
|
|
|
|
await invalidateSession();
|
|
|
|
await visit('/settings/general');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
2017-02-21 22:04:50 +03:00
|
|
|
});
|
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('renders with no custom theme settings', async function () {
|
|
|
|
await visit('/settings');
|
|
|
|
await click('[data-test-nav="design"]');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/design');
|
|
|
|
expect(document.title, 'page title').to.equal('Settings - Design - Test Blog');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// side nav menu changes
|
|
|
|
expect(find('[data-test-nav-menu="design"]'), 'design menu').to.exist;
|
|
|
|
expect(find('[data-test-nav-menu="main"]'), 'main menu').to.not.exist;
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// side nav defaults to general group open
|
|
|
|
expect(find('[data-test-nav-toggle="general"]'), 'general toggle').to.exist;
|
|
|
|
expect(find('[data-test-nav-group="general"]'), 'general form').to.exist;
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// no other side nav groups exist
|
|
|
|
expect(findAll('[data-test-nav-toggle]'), 'no of group toggles').to.have.lengthOf(1);
|
|
|
|
expect(findAll('[data-test-nav-group]'), 'no of groups open').to.have.lengthOf(1);
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// current theme is shown in nav menu
|
|
|
|
expect(find('[data-test-text="current-theme"]')).to.contain.text('casper - v1.0');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// defaults to "home" desktop preview
|
|
|
|
expect(find('[data-test-button="desktop-preview"]')).to.have.class('gh-btn-group-selected');
|
|
|
|
expect(find('[data-test-button="mobile-preview"]')).to.not.have.class('gh-btn-group-selected');
|
|
|
|
});
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('renders with custom theme settings');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('can install an official theme', async function () {
|
|
|
|
await visit('/settings/design');
|
|
|
|
await click('[data-test-nav="change-theme"]');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/design/change-theme');
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await click('[data-test-theme-link="Journal"]');
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/design/change-theme/Journal');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await click('[data-test-button="install-theme"]');
|
|
|
|
expect(find('[data-test-modal="install-theme"]'), 'install-theme modal').to.exist;
|
|
|
|
expect(find('[data-test-state="confirm"]'), 'confirm state').to.exist;
|
|
|
|
expect(findAll('[data-test-state]').length, 'state count').to.equal(1);
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await click('[data-test-button="confirm-install"]');
|
|
|
|
expect(find('[data-test-state="installed-no-notes"]'), 'success state').to.exist;
|
|
|
|
expect(findAll('[data-test-state]').length, 'state count').to.equal(1);
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// navigates back to design screen in background
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/design');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await click('[data-test-button="cancel"]');
|
|
|
|
expect(find('[data-test-modal="install-theme"]')).to.not.exist;
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
// nav menu shows current theme
|
|
|
|
expect(find('[data-test-text="current-theme"]')).to.contain.text('Journal - v0.1');
|
|
|
|
});
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('can upload custom theme', async function () {
|
|
|
|
this.server.post('/themes/upload/', function ({themes}) {
|
|
|
|
const theme = themes.create({
|
|
|
|
name: 'custom',
|
|
|
|
package: {
|
|
|
|
name: 'Custom',
|
|
|
|
version: '1.0'
|
|
|
|
}
|
2017-05-18 13:48:37 +03:00
|
|
|
});
|
2017-02-21 22:04:50 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
return {themes: [theme]};
|
2017-02-21 22:04:50 +03:00
|
|
|
});
|
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await visit('/settings/design/change-theme');
|
|
|
|
await click('[data-test-button="upload-theme"]');
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
expect(find('[data-test-modal="upload-theme"]'), 'upload-theme modal').to.exist;
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await fileUpload('[data-test-modal="upload-theme"] input[type="file"]', ['test'], {name: 'valid-theme.zip', type: 'application/zip'});
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
expect(find('[data-test-state="installed-no-notes"]'), 'success state').to.exist;
|
|
|
|
expect(currentURL(), 'url after upload').to.equal('/settings/design/change-theme');
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
await click('[data-test-button="activate"]');
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
expect(currentURL(), 'url after activate').to.equal('/settings/design');
|
|
|
|
expect(find('[data-test-modal="install-theme"]')).to.not.exist;
|
|
|
|
expect(find('[data-test-text="current-theme"]')).to.contain.text('custom - v1.0');
|
|
|
|
});
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
it('can change between installed themes');
|
|
|
|
it('can delete installed theme');
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-11-01 20:48:49 +03:00
|
|
|
describe('limits', function () {
|
|
|
|
it('displays upgrade notice when custom themes are not allowed');
|
2017-02-21 22:04:50 +03:00
|
|
|
});
|
|
|
|
});
|