From 78e453c1b014f96650f25936e102d8be7d9d4194 Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Fri, 14 Feb 2020 16:37:25 +0530 Subject: [PATCH] Fixed tests for labels (#1493) no issue - Updated member settings css property in tests - Added mock for label API --- ghost/admin/mirage/config.js | 2 ++ ghost/admin/mirage/config/labels.js | 27 ++++++++++++++++++++ ghost/admin/tests/acceptance/members-test.js | 24 ++++++++--------- 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 ghost/admin/mirage/config/labels.js diff --git a/ghost/admin/mirage/config.js b/ghost/admin/mirage/config.js index ef90f61453..209fc889af 100644 --- a/ghost/admin/mirage/config.js +++ b/ghost/admin/mirage/config.js @@ -4,6 +4,7 @@ import mockConfig from './config/config'; import mockEmails from './config/emails'; import mockIntegrations from './config/integrations'; import mockInvites from './config/invites'; +import mockLabels from './config/labels'; import mockMembers from './config/members'; import mockPages from './config/pages'; import mockPosts from './config/posts'; @@ -59,6 +60,7 @@ export function testConfig() { mockIntegrations(this); mockInvites(this); mockMembers(this); + mockLabels(this); mockPages(this); mockPosts(this); mockRoles(this); diff --git a/ghost/admin/mirage/config/labels.js b/ghost/admin/mirage/config/labels.js new file mode 100644 index 0000000000..b8bf3c713d --- /dev/null +++ b/ghost/admin/mirage/config/labels.js @@ -0,0 +1,27 @@ +import {paginatedResponse} from '../utils'; + +export default function mockLabels(server) { + server.post('/labels/', function ({labels}) { + let attrs = this.normalizedRequestAttrs(); + + return labels.create(Object.assign({}, attrs, {id: 99})); + }); + + server.get('/labels/', paginatedResponse('labels')); + + server.get('/labels/:id/', function ({labels}, {params}) { + let {id} = params; + let label = labels.find(id); + + return label || new Response(404, {}, { + errors: [{ + type: 'NotFoundError', + message: 'Label not found.' + }] + }); + }); + + server.put('/labels/:id/'); + + server.del('/labels/:id/'); +} diff --git a/ghost/admin/tests/acceptance/members-test.js b/ghost/admin/tests/acceptance/members-test.js index 12f1ceac45..f0183d2049 100644 --- a/ghost/admin/tests/acceptance/members-test.js +++ b/ghost/admin/tests/acceptance/members-test.js @@ -86,15 +86,15 @@ describe('Acceptance: Members', function () { await wait(); // it shows selected member form - expect(find('.gh-member-basic-settings-form input[name="name"]').value, 'loads correct member into form') + expect(find('.gh-member-settings-primary input[name="name"]').value, 'loads correct member into form') .to.equal(member1.name); - expect(find('.gh-member-basic-settings-form input[name="email-disabled"]').disabled, 'makes sure email is disabled') + expect(find('.gh-member-settings-primary input[name="email-disabled"]').disabled, 'makes sure email is disabled') .to.equal(true); // trigger save - await fillIn('.gh-member-basic-settings-form input[name="name"]', 'New Name'); - await blur('.gh-member-basic-settings-form input[name="name"]'); + await fillIn('.gh-member-settings-primary input[name="name"]', 'New Name'); + await blur('.gh-member-settings-primary input[name="name"]'); await click('[data-test-button="save"]'); @@ -138,28 +138,28 @@ describe('Acceptance: Members', function () { .to.contain('New member'); // // all fields start blank - findAll('.gh-member-basic-settings-form .gh-input').forEach(function (elem) { + findAll('.gh-member-settings-primary .gh-input').forEach(function (elem) { expect(elem.value, `input field for ${elem.getAttribute('name')}`) .to.be.empty; }); - expect(find('.gh-member-basic-settings-form input[name="email"]').disabled, 'makes sure email is disabled') + expect(find('.gh-member-settings-primary input[name="email"]').disabled, 'makes sure email is disabled') .to.equal(false); // save new member - await fillIn('.gh-member-basic-settings-form input[name="name"]', 'New Name'); - await blur('.gh-member-basic-settings-form input[name="name"]'); + await fillIn('.gh-member-settings-primary input[name="name"]', 'New Name'); + await blur('.gh-member-settings-primary input[name="name"]'); - await fillIn('.gh-member-basic-settings-form input[name="email"]', 'example@domain.com'); - await blur('.gh-member-basic-settings-form input[name="email"]'); + await fillIn('.gh-member-settings-primary input[name="email"]', 'example@domain.com'); + await blur('.gh-member-settings-primary input[name="email"]'); await click('[data-test-button="save"]'); await wait(); - expect(find('.gh-member-basic-settings-form input[name="name"]').value, 'name has been preserved') + expect(find('.gh-member-settings-primary input[name="name"]').value, 'name has been preserved') .to.equal('New Name'); - expect(find('.gh-member-basic-settings-form input[name="email-disabled"]').disabled, 'makes sure email is disabled') + expect(find('.gh-member-settings-primary input[name="email-disabled"]').disabled, 'makes sure email is disabled') .to.equal(true); }); });