From c4a4d3d1f02ec42a629b5a2558e68f4ce2961fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Wed, 8 May 2019 16:04:09 +0200 Subject: [PATCH] Wrote an additional frontend unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skipped writing of a modal dialog before deletion, because many code parts are on the way in the delete post PR. So makes no sense to write them twice. I make a new issue … --- cypress/integration/common/settings.js | 5 ---- .../user_profile/SocialMedia.feature | 1 - webapp/pages/settings/my-social-media.spec.js | 30 ++++++++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cypress/integration/common/settings.js b/cypress/integration/common/settings.js index fa2962dfb..b6621ec87 100644 --- a/cypress/integration/common/settings.js +++ b/cypress/integration/common/settings.js @@ -116,11 +116,6 @@ When('I delete a social media link', () => { .click() }) -// Then('Shows delete modal', () => { -// cy.get("a[name='delete']") -// .click() -// }) - Then('it gets deleted successfully', () => { cy.get('.iziToast-message') .should('contain', 'Deleted social media') diff --git a/cypress/integration/user_profile/SocialMedia.feature b/cypress/integration/user_profile/SocialMedia.feature index 4466b9537..d21167c6b 100644 --- a/cypress/integration/user_profile/SocialMedia.feature +++ b/cypress/integration/user_profile/SocialMedia.feature @@ -27,4 +27,3 @@ Feature: List Social Media Accounts Given I have added a social media link When I delete a social media link Then it gets deleted successfully - # And the new social media link shows up on the page diff --git a/webapp/pages/settings/my-social-media.spec.js b/webapp/pages/settings/my-social-media.spec.js index 673c1cd70..559ba87d2 100644 --- a/webapp/pages/settings/my-social-media.spec.js +++ b/webapp/pages/settings/my-social-media.spec.js @@ -72,10 +72,38 @@ describe('my-social-media.vue', () => { expect(socialMediaLink).toBe(socialMediaUrl) }) - it('displays a trash sympol after a social media', () => { + beforeEach(() => { + mocks = { + $t: jest.fn(), + $apollo: { + mutate: jest + .fn() + .mockRejectedValue({ message: 'Ouch!' }) + .mockResolvedValueOnce({ + data: { DeleteSocialMeda: { id: 's1', url: socialMediaUrl } } + }) + }, + $toast: { + error: jest.fn(), + success: jest.fn() + } + } + getters = { + 'auth/user': () => { + return { + socialMedia: [{ id: 's1', url: socialMediaUrl }] + } + } + } + }) + + it('displays a trash sympol after a social media and allows the user to delete it', () => { wrapper = Wrapper() const deleteSelector = wrapper.find({ name: 'delete' }) expect(deleteSelector).toEqual({ selector: 'Component' }) + const icon = wrapper.find({ name: 'trash' }) + icon.trigger('click') + expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1) }) })