0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Removed more leftover unsplash code & fixed tests

refs refs 07abb5443a

- Found some more unnecessary code for previous unsplash setting structure and removed it.
- Refactored the tests to be more in line to how AMP tests are done
This commit is contained in:
Naz 2021-02-18 15:03:53 +13:00
parent 098790ec75
commit d84a70752d
5 changed files with 40 additions and 76 deletions

View file

@ -3,31 +3,14 @@ import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
import {inject as service} from '@ember/service';
export default AuthenticatedRoute.extend(CurrentUserSettings, {
config: service(),
settings: service(),
// reload settings to ensure we have latest values and pre-configure
// Unsplash to be active if the server doesn't have any unsplash setting
beforeModel() {
this._super(...arguments);
let {settings} = this;
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor())
.then(this.settings.reload())
.then(() => {
if (settings.get('unsplash')) {
return;
}
// server doesn't have any unsplash settings by default but it can provide
// overrides via config:
// - unsplash: use as default but allow settings override
let unsplash = true;
settings.set('unsplash', unsplash);
});
.then(this.settings.reload());
},
actions: {
@ -37,7 +20,7 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, {
willTransition(transition) {
let controller = this.controller;
let modelIsDirty = controller.dirtyAttributes;
let modelIsDirty = this.settings.get('hasDirtyAttributes');
if (modelIsDirty) {
transition.abort();

View file

@ -42,14 +42,14 @@
<div class="gh-setting-action">
<div class="form-group right gh-setting-unsplash-checkbox">
<div class="for-checkbox">
<label for="isActive" class="checkbox">
<label for="unsplash" class="checkbox">
<input
type="checkbox"
checked={{this.unsplashSettings}}
id="isActive"
name="isActive"
checked={{this.settings.unsplash}}
id="unsplash"
name="unsplash"
onclick={{action "update" value="target.checked"}}
data-test-checkbox="unsplash"
data-test-unsplash-checkbox
>
<span class="input-toggle-component"></span>
</label>

View file

@ -1,25 +0,0 @@
/* eslint-disable camelcase */
import Transform from '@ember-data/serializer/transform';
const DEFAULT_VALUE = true;
export default Transform.extend({
deserialize(serialized) {
if (serialized) {
let settingsObject;
try {
settingsObject = JSON.parse(serialized) || DEFAULT_VALUE;
} catch (e) {
settingsObject = DEFAULT_VALUE;
}
return settingsObject;
}
return DEFAULT_VALUE;
},
serialize(deserialized) {
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_VALUE);
}
});

View file

@ -202,5 +202,15 @@ export default [
updated_at: '2019-11-20T13:32:49.868Z',
updated_by: 1,
value: JSON.stringify([])
},
{
id: 26,
created_at: '2020-01-09T08:40:59.000Z',
created_by: 1,
key: 'unsplash',
group: 'unsplash',
updated_at: '2020-01-09T08:49:42.991Z',
updated_by: 1,
value: 'true'
}
];

View file

@ -66,39 +66,37 @@ describe('Acceptance: Settings - Integrations - Unsplash', function () {
// has correct url
expect(currentURL(), 'currentURL').to.equal('/integrations/unsplash');
// verify we don't have an unsplash setting fixture loaded
expect(
this.server.db.settings.where({key: 'unsplash'}),
'initial server settings'
).to.be.empty;
// it's enabled by default when settings is empty
expect(
find('[data-test-checkbox="unsplash"]').checked,
'checked by default'
).to.be.true;
expect(find('[data-test-unsplash-checkbox]').checked, 'checked by default').to.be.true;
await click('[data-test-unsplash-checkbox]');
expect(find('[data-test-unsplash-checkbox]').checked, 'unsplash checkbox').to.be.false;
// trigger a save
await click('[data-test-save-button]');
// server should now have an unsplash setting
let [setting] = this.server.db.settings.where({key: 'unsplash'});
expect(setting, 'unsplash setting after save').to.exist;
expect(setting.value).to.equal(true);
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
let params = JSON.parse(lastRequest.requestBody);
// disable
await click('[data-test-checkbox="unsplash"]');
expect(params.settings.findBy('key', 'unsplash').value).to.equal(false);
// save via CMD-S shortcut
await click('[data-test-unsplash-checkbox]');
await triggerEvent('.gh-app', 'keydown', {
keyCode: 83, // s
metaKey: ctrlOrCmd === 'command',
ctrlKey: ctrlOrCmd === 'ctrl'
});
// server should have an updated setting
[setting] = this.server.db.settings.where({key: 'unsplash'});
expect(setting.value).to.equal(false);
// we've already saved in this test so there's no on-screen indication
// that we've had another save, check the request was fired instead
let [newRequest] = this.server.pretender.handledRequests.slice(-1);
params = JSON.parse(newRequest.requestBody);
expect(find('[data-test-unsplash-checkbox]').checked, 'AMP checkbox').to.be.true;
expect(params.settings.findBy('key', 'unsplash').value).to.equal(true);
});
it('warns when leaving without saving', async function () {
@ -107,30 +105,28 @@ describe('Acceptance: Settings - Integrations - Unsplash', function () {
// has correct url
expect(currentURL(), 'currentURL').to.equal('/integrations/unsplash');
expect(
find('[data-test-checkbox="unsplash"]').checked,
'checked by default'
).to.be.true;
// AMP is enabled by default
expect(find('[data-test-unsplash-checkbox]').checked, 'AMP checkbox default').to.be.true;
await click('[data-test-checkbox="unsplash"]');
await click('[data-test-unsplash-checkbox]');
expect(find('[data-test-checkbox="unsplash"]').checked, 'Unsplash checkbox').to.be.false;
expect(find('[data-test-unsplash-checkbox]').checked, 'Unsplash checkbox').to.be.false;
await visit('/settings/labs');
expect(findAll('.fullscreen-modal').length, 'modal exists').to.equal(1);
expect(findAll('.fullscreen-modal').length, 'unsaved changes modal exists').to.equal(1);
// Leave without saving
await click('.fullscreen-modal [data-test-leave-button]');
expect(currentURL(), 'currentURL').to.equal('/settings/labs');
expect(currentURL(), 'currentURL after leave without saving').to.equal('/settings/labs');
await visit('/integrations/unsplash');
expect(currentURL(), 'currentURL').to.equal('/integrations/unsplash');
// settings were not saved
expect(find('[data-test-checkbox="unsplash"]').checked, 'Unsplash checkbox').to.be.true;
expect(find('[data-test-unsplash-checkbox]').checked, 'Unsplash checkbox').to.be.true;
});
});
});