2019-07-22 08:01:42 -04:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2019-12-10 04:07:51 -05:00
|
|
|
import renderMetrics from '~/behaviors/markdown/render_metrics';
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2020-03-31 05:08:16 -04:00
|
|
|
const mockEmbedGroup = jest.fn();
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2020-03-31 05:08:16 -04:00
|
|
|
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-07-22 08:01:42 -04:00
|
|
|
|
2020-03-31 05:08:16 -04:00
|
|
|
const getElements = () => Array.from(document.getElementsByClassName('js-render-metrics'));
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2020-03-31 05:08:16 -04:00
|
|
|
describe('Render metrics for Gitlab Flavoured Markdown', () => {
|
2019-07-22 08:01:42 -04:00
|
|
|
it('does nothing when no elements are found', () => {
|
2020-05-14 20:08:06 -04:00
|
|
|
return renderMetrics([]).then(() => {
|
|
|
|
expect(mockEmbedGroup).not.toHaveBeenCalled();
|
|
|
|
});
|
2019-07-22 08:01:42 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a vue component when elements are found', () => {
|
2020-03-31 05:08:16 -04:00
|
|
|
document.body.innerHTML = `<div class="js-render-metrics" data-dashboard-url="${TEST_HOST}"></div>`;
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2020-05-14 20:08:06 -04:00
|
|
|
return renderMetrics(getElements()).then(() => {
|
|
|
|
expect(mockEmbedGroup).toHaveBeenCalledTimes(1);
|
|
|
|
expect(mockEmbedGroup).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({ propsData: { urls: [`${TEST_HOST}`] } }),
|
|
|
|
);
|
|
|
|
});
|
2020-03-31 05:08:16 -04:00
|
|
|
});
|
2019-07-22 08:01:42 -04:00
|
|
|
|
2020-03-31 05:08:16 -04:00
|
|
|
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-14 20:08:06 -04:00
|
|
|
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-07-22 08:01:42 -04:00
|
|
|
});
|
|
|
|
});
|