debian-mirror-gitlab/spec/frontend/behaviors/markdown/render_metrics_spec.js

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

50 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-10-12 21:52:04 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2020-01-01 13:55:28 +05:30
import renderMetrics from '~/behaviors/markdown/render_metrics';
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
const mockEmbedGroup = jest.fn();
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
jest.mock('vue', () => ({ extend: () => mockEmbedGroup }));
jest.mock('~/monitoring/components/embeds/embed_group.vue', () => jest.fn());
jest.mock('~/monitoring/stores/embed_group/', () => ({ createStore: jest.fn() }));
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
const getElements = () => Array.from(document.getElementsByClassName('js-render-metrics'));
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
describe('Render metrics for Gitlab Flavoured Markdown', () => {
2019-10-12 21:52:04 +05:30
it('does nothing when no elements are found', () => {
2020-05-24 23:13:21 +05:30
return renderMetrics([]).then(() => {
expect(mockEmbedGroup).not.toHaveBeenCalled();
});
2019-10-12 21:52:04 +05:30
});
it('renders a vue component when elements are found', () => {
2020-04-22 19:07:51 +05:30
document.body.innerHTML = `<div class="js-render-metrics" data-dashboard-url="${TEST_HOST}"></div>`;
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
return renderMetrics(getElements()).then(() => {
expect(mockEmbedGroup).toHaveBeenCalledTimes(1);
expect(mockEmbedGroup).toHaveBeenCalledWith(
expect.objectContaining({ propsData: { urls: [`${TEST_HOST}`] } }),
);
});
2020-04-22 19:07:51 +05:30
});
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
it('takes sibling metrics and groups them under a shared parent', () => {
document.body.innerHTML = `
<p><span>Hello</span></p>
<div class="js-render-metrics" data-dashboard-url="${TEST_HOST}/1"></div>
<div class="js-render-metrics" data-dashboard-url="${TEST_HOST}/2"></div>
<p><span>Hello</span></p>
<div class="js-render-metrics" data-dashboard-url="${TEST_HOST}/3"></div>
`;
2020-05-24 23:13:21 +05:30
return renderMetrics(getElements()).then(() => {
expect(mockEmbedGroup).toHaveBeenCalledTimes(2);
expect(mockEmbedGroup).toHaveBeenCalledWith(
expect.objectContaining({ propsData: { urls: [`${TEST_HOST}/1`, `${TEST_HOST}/2`] } }),
);
expect(mockEmbedGroup).toHaveBeenCalledWith(
expect.objectContaining({ propsData: { urls: [`${TEST_HOST}/3`] } }),
);
});
2019-10-12 21:52:04 +05:30
});
});