debian-mirror-gitlab/spec/frontend/jira_connect/subscriptions/index_spec.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-10-27 15:23:28 +05:30
import { initJiraConnect } from '~/jira_connect/subscriptions';
2021-12-11 22:18:48 +05:30
import { getGitlabSignInURL } from '~/jira_connect/subscriptions/utils';
2021-03-11 19:13:27 +05:30
2021-12-11 22:18:48 +05:30
jest.mock('~/jira_connect/subscriptions/utils');
2021-03-11 19:13:27 +05:30
describe('initJiraConnect', () => {
2021-12-11 22:18:48 +05:30
const mockInitialHref = 'https://gitlab.com';
beforeEach(() => {
2021-03-11 19:13:27 +05:30
setFixtures(`
2021-12-11 22:18:48 +05:30
<a class="js-jira-connect-sign-in" href="${mockInitialHref}">Sign In</a>
<a class="js-jira-connect-sign-in" href="${mockInitialHref}">Another Sign In</a>
2021-03-11 19:13:27 +05:30
`);
});
2021-12-11 22:18:48 +05:30
const assertSignInLinks = (expectedLink) => {
Array.from(document.querySelectorAll('.js-jira-connect-sign-in')).forEach((el) => {
expect(el.getAttribute('href')).toBe(expectedLink);
});
};
2021-03-11 19:13:27 +05:30
describe('Sign in links', () => {
2021-12-11 22:18:48 +05:30
it('are updated on initialization', async () => {
const mockSignInLink = `https://gitlab.com?return_to=${encodeURIComponent('/test/location')}`;
getGitlabSignInURL.mockResolvedValue(mockSignInLink);
// assert the initial state
assertSignInLinks(mockInitialHref);
await initJiraConnect();
// assert the update has occurred
assertSignInLinks(mockSignInLink);
2021-03-11 19:13:27 +05:30
});
});
});