debian-mirror-gitlab/spec/frontend/issuable/popover/index_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import { setHTMLFixture } from 'helpers/fixtures';
2019-07-07 11:18:12 +05:30
import * as createDefaultClient from '~/lib/graphql';
2022-07-23 23:45:48 +05:30
import initIssuablePopovers from '~/issuable/popover/index';
2019-07-07 11:18:12 +05:30
createDefaultClient.default = jest.fn();
2022-07-23 23:45:48 +05:30
describe('initIssuablePopovers', () => {
2019-07-07 11:18:12 +05:30
let mr1;
let mr2;
let mr3;
2022-07-23 23:45:48 +05:30
let issue1;
2019-07-07 11:18:12 +05:30
beforeEach(() => {
setHTMLFixture(`
2022-07-23 23:45:48 +05:30
<div id="one" class="gfm-merge_request" data-mr-title="title" data-iid="1" data-project-path="group/project" data-reference-type="merge_request">
2019-07-07 11:18:12 +05:30
MR1
</div>
2022-07-23 23:45:48 +05:30
<div id="two" class="gfm-merge_request" title="title" data-iid="1" data-project-path="group/project" data-reference-type="merge_request">
2019-07-07 11:18:12 +05:30
MR2
</div>
<div id="three" class="gfm-merge_request">
MR3
</div>
2022-07-23 23:45:48 +05:30
<div id="four" class="gfm-issue" title="title" data-iid="1" data-project-path="group/project" data-reference-type="issue">
MR3
</div>
2019-07-07 11:18:12 +05:30
`);
mr1 = document.querySelector('#one');
mr2 = document.querySelector('#two');
mr3 = document.querySelector('#three');
2022-07-23 23:45:48 +05:30
issue1 = document.querySelector('#four');
2019-07-07 11:18:12 +05:30
mr1.addEventListener = jest.fn();
mr2.addEventListener = jest.fn();
mr3.addEventListener = jest.fn();
2022-07-23 23:45:48 +05:30
issue1.addEventListener = jest.fn();
2019-07-07 11:18:12 +05:30
});
it('does not add the same event listener twice', () => {
2022-07-23 23:45:48 +05:30
initIssuablePopovers([mr1, mr1, mr2, issue1]);
2019-07-07 11:18:12 +05:30
expect(mr1.addEventListener).toHaveBeenCalledTimes(1);
expect(mr2.addEventListener).toHaveBeenCalledTimes(1);
2022-07-23 23:45:48 +05:30
expect(issue1.addEventListener).toHaveBeenCalledTimes(1);
2019-07-07 11:18:12 +05:30
});
it('does not add listener if it does not have the necessary data attributes', () => {
2022-07-23 23:45:48 +05:30
initIssuablePopovers([mr1, mr2, mr3]);
2019-07-07 11:18:12 +05:30
expect(mr3.addEventListener).not.toHaveBeenCalled();
});
});