blob: 0ac72aa9afb3aa8d4fa59592b30039f5612e7d98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { setHTMLFixture } from 'helpers/fixtures';
import {
calculateBlameOffset,
toggleBlameClasses,
} from '~/vue_shared/components/source_viewer/utils';
import { SOURCE_CODE_CONTENT_MOCK, BLAME_DATA_MOCK } from './mock_data';
describe('SourceViewer utils', () => {
beforeEach(() => setHTMLFixture(SOURCE_CODE_CONTENT_MOCK));
const findContent = () => document.querySelector('.content');
describe('calculateBlameOffset', () => {
it('returns an offset of zero if line number === 1', () => {
expect(calculateBlameOffset(1)).toBe('0px');
});
it('calculates an offset for the blame component', () => {
const { offsetTop } = document.querySelector('#LC3');
expect(calculateBlameOffset(3)).toBe(`${offsetTop}px`);
});
});
describe('toggleBlameClasses', () => {
it('adds classes', () => {
toggleBlameClasses(BLAME_DATA_MOCK, true);
expect(findContent()).toMatchSnapshot();
});
it('removes classes', () => {
toggleBlameClasses(BLAME_DATA_MOCK, false);
expect(findContent()).toMatchSnapshot();
});
});
});
|