summaryrefslogtreecommitdiff
path: root/spec/frontend/persistent_user_callout_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/persistent_user_callout_spec.js
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/frontend/persistent_user_callout_spec.js')
-rw-r--r--spec/frontend/persistent_user_callout_spec.js66
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();