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

add final theme management acceptance tests

refs https://github.com/TryGhost/Ghost-Admin/pull/210
- adds missing acceptance tests for theme deletion
- adds theme deletion endpoint to mirage config
- fixes mirage settings update endpoint (was previously removing config that the client didn't send and also losing the `type` key for all entries preventing the `GET` request from working properly)
This commit is contained in:
Kevin Ansfield 2016-08-23 15:27:46 +01:00
parent a684280fd0
commit a255f937dd
3 changed files with 87 additions and 8 deletions

View file

@ -18,18 +18,15 @@ export default function mockSettings(server) {
});
server.put('/settings/', function (db, request) {
console.log('/settings/', request.requestBody);
let newSettings = JSON.parse(request.requestBody).settings;
db.settings.remove();
db.settings.insert(newSettings);
newSettings.forEach((newSetting) => {
db.settings.update({key: newSetting.key}, newSetting);
});
let [activeTheme] = db.settings.where({key: 'activeTheme'});
let [availableThemes] = db.settings.where({key: 'availableThemes'});
console.log('activeTheme', activeTheme);
console.log('availableThemes', availableThemes);
availableThemes.value.forEach((theme) => {
if (theme.name === activeTheme.value) {
theme.active = true;
@ -38,7 +35,8 @@ export default function mockSettings(server) {
}
});
db.settings.update(availableThemes.id, availableThemes);
db.settings.remove({key: 'availableThemes'});
db.settings.insert(availableThemes);
return {
meta: {},

View file

@ -1,3 +1,5 @@
import Mirage from 'ember-cli-mirage';
let themeCount = 1;
export default function mockThemes(server) {
@ -24,4 +26,17 @@ export default function mockThemes(server) {
themes: [theme]
};
});
server.del('/themes/:theme/', function (db, request) {
let [availableThemes] = db.settings.where({key: 'availableThemes'});
availableThemes.value = availableThemes.value.filter((theme) => {
return theme.name !== request.params.theme;
});
db.settings.remove({key: 'availableThemes'});
db.settings.insert(availableThemes);
return new Mirage.Response(204, {}, null);
});
}

View file

@ -387,7 +387,7 @@ describe('Acceptance: Settings - General', function () {
andThen(() => {
expect(
find('.fullscreen-modal').length === 0,
'modal is closed when cancelling'
'upload theme modal is closed when cancelling'
).to.be.true;
});
@ -490,10 +490,76 @@ describe('Acceptance: Settings - General', function () {
});
// theme deletion displays modal
click('.theme-list-item:contains("Test 1") a:contains("Delete")');
andThen(() => {
expect(
find('.fullscreen-modal .modal-content:contains("delete this theme")').length,
'theme deletion modal displayed after button click'
).to.equal(1);
});
// cancelling theme deletion closes modal
click('.fullscreen-modal button:contains("Cancel")');
andThen(() => {
expect(
find('.fullscreen-modal').length === 0,
'delete theme modal is closed when cancelling'
).to.be.true;
});
// confirming theme deletion closes modal and refreshes list
click('.theme-list-item:contains("Test 1") a:contains("Delete")');
click('.fullscreen-modal button:contains("Delete")');
andThen(() => {
expect(
find('.fullscreen-modal').length === 0,
'delete theme modal closes after deletion'
).to.be.true;
});
andThen(() => {
expect(
find('.theme-list-item').length,
'number of themes in list shrinks after delete'
).to.equal(4);
expect(
find('.theme-list-item .name').text(),
'correct theme is removed from theme list after deletion'
).to.not.match(/Test 1/);
});
// validation errors are handled when deleting a theme
andThen(() => {
server.del('/themes/:theme/', function () {
return new Mirage.Response(422, {}, {
errors: [{
message: 'Can\'t delete theme'
}]
});
});
});
click('.theme-list-item:contains("Test 2") a:contains("Delete")');
click('.fullscreen-modal button:contains("Delete")');
andThen(() => {
expect(
find('.fullscreen-modal').length === 0,
'delete theme modal closes after failed deletion'
).to.be.true;
expect(
find('.gh-alert').length,
'alert is shown when deletion fails'
).to.equal(1);
expect(
find('.gh-alert').text(),
'failed deletion alert has correct text'
).to.match(/Can't delete theme/);
// restore default mirage handlers
mockThemes(server);
});
});
});
});