diff options
Diffstat (limited to 'spec/frontend/persistent_user_callout_spec.js')
-rw-r--r-- | spec/frontend/persistent_user_callout_spec.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/frontend/persistent_user_callout_spec.js b/spec/frontend/persistent_user_callout_spec.js index db324990e71..97985ba3a07 100644 --- a/spec/frontend/persistent_user_callout_spec.js +++ b/spec/frontend/persistent_user_callout_spec.js @@ -43,6 +43,23 @@ describe('PersistentUserCallout', () => { return fixture; } + function createFollowLinkFixture() { + const fixture = document.createElement('div'); + fixture.innerHTML = ` + <ul> + <li + class="container" + data-dismiss-endpoint="${dismissEndpoint}" + data-feature-id="${featureName}" + > + <a class="js-follow-link" href="/somewhere-pleasant">A Link</a> + </li> + </ul> + `; + + return fixture; + } + describe('dismiss', () => { let button; let mockAxios; @@ -144,6 +161,55 @@ describe('PersistentUserCallout', () => { }); }); + describe('follow links', () => { + let link; + let mockAxios; + let persistentUserCallout; + + beforeEach(() => { + const fixture = createFollowLinkFixture(); + const container = fixture.querySelector('.container'); + link = fixture.querySelector('.js-follow-link'); + mockAxios = new MockAdapter(axios); + + persistentUserCallout = new PersistentUserCallout(container); + jest.spyOn(persistentUserCallout.container, 'remove').mockImplementation(() => {}); + + delete window.location; + window.location = { assign: jest.fn() }; + }); + + afterEach(() => { + mockAxios.restore(); + }); + + it('uses a link to trigger callout and defers following until callout is finished', () => { + const { href } = link; + mockAxios.onPost(dismissEndpoint).replyOnce(200); + + link.click(); + + return waitForPromises().then(() => { + expect(window.location.assign).toBeCalledWith(href); + expect(mockAxios.history.post[0].data).toBe(JSON.stringify({ feature_name: featureName })); + expect(persistentUserCallout.container.remove).not.toHaveBeenCalled(); + }); + }); + + it('invokes Flash when the dismiss request fails', () => { + mockAxios.onPost(dismissEndpoint).replyOnce(500); + + link.click(); + + return waitForPromises().then(() => { + expect(window.location.assign).not.toHaveBeenCalled(); + expect(Flash).toHaveBeenCalledWith( + 'An error occurred while acknowledging the notification. Refresh the page and try again.', + ); + }); + }); + }); + describe('factory', () => { it('returns an instance of PersistentUserCallout with the provided container property', () => { const fixture = createFixture(); |