debian-mirror-gitlab/spec/frontend/blob/blob_blame_link_spec.js

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

56 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-10-02 17:18:49 +05:30
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2023-01-13 00:05:48 +05:30
import { addBlameLink } from '~/blob/blob_blame_link';
2022-10-02 17:18:49 +05:30
describe('Blob links', () => {
const mouseoverEvent = new MouseEvent('mouseover', {
view: window,
bubbles: true,
cancelable: true,
});
beforeEach(() => {
setHTMLFixture(`
2023-01-13 00:05:48 +05:30
<div id="blob-content-holder" class="js-per-page" data-blame-per-page="1000">
2022-10-02 17:18:49 +05:30
<div class="line-numbers" data-blame-path="/blamePath">
<a id="L5" href="#L5" data-line-number="5" class="file-line-num js-line-links">5</a>
2023-01-13 00:05:48 +05:30
<a id="L1005" href="#L1005" data-line-number="1005" class="file-line-num js-line-links">1005</a>
2022-10-02 17:18:49 +05:30
</div>
<pre id="LC5">Line 5 content</pre>
</div>
`);
addBlameLink('#blob-content-holder', 'js-line-links');
document.querySelector('.file-line-num').dispatchEvent(mouseoverEvent);
});
afterEach(() => {
resetHTMLFixture();
});
it('adds wrapper elements with correct classes', () => {
const wrapper = document.querySelector('.line-links');
2022-11-25 23:54:43 +05:30
expect(wrapper).not.toBeNull();
2022-10-02 17:18:49 +05:30
expect(wrapper.classList).toContain('diff-line-num');
});
it('adds blame link with correct classes and path', () => {
const blameLink = document.querySelector('.file-line-blame');
2022-11-25 23:54:43 +05:30
expect(blameLink).not.toBeNull();
2022-10-02 17:18:49 +05:30
expect(blameLink.getAttribute('href')).toBe('/blamePath#L5');
});
it('adds line link within wraper with correct classes and path', () => {
const lineLink = document.querySelector('.file-line-num');
2022-11-25 23:54:43 +05:30
expect(lineLink).not.toBeNull();
2022-10-02 17:18:49 +05:30
expect(lineLink.getAttribute('href')).toBe('#L5');
});
2023-01-13 00:05:48 +05:30
it('adds page parameter when needed', () => {
document.querySelectorAll('.file-line-num')[1].dispatchEvent(mouseoverEvent);
const blameLink = document.querySelectorAll('.file-line-blame')[1];
expect(blameLink).not.toBeNull();
expect(blameLink.getAttribute('href')).toBe('/blamePath?page=2#L1005');
});
2022-10-02 17:18:49 +05:30
});