debian-mirror-gitlab/spec/frontend/monitoring/components/links_section_spec.js

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

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { GlLink } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2021-12-11 22:18:48 +05:30
import { nextTick } from 'vue';
2020-06-23 00:09:42 +05:30
import LinksSection from '~/monitoring/components/links_section.vue';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/monitoring/stores';
2020-06-23 00:09:42 +05:30
describe('Links Section component', () => {
let store;
let wrapper;
const createShallowWrapper = () => {
wrapper = shallowMount(LinksSection, {
store,
});
};
2021-03-08 18:12:59 +05:30
const setState = (links) => {
2020-06-23 00:09:42 +05:30
store.state.monitoringDashboard = {
...store.state.monitoringDashboard,
2020-07-28 23:09:34 +05:30
emptyState: null,
2020-06-23 00:09:42 +05:30
links,
};
};
2022-08-27 11:52:29 +05:30
const findLinks = () => wrapper.findAllComponents(GlLink);
2020-06-23 00:09:42 +05:30
beforeEach(() => {
store = createStore();
createShallowWrapper();
});
2021-12-11 22:18:48 +05:30
it('does not render a section if no links are present', async () => {
2020-06-23 00:09:42 +05:30
setState();
2021-12-11 22:18:48 +05:30
await nextTick();
expect(findLinks().length).toBe(0);
2020-06-23 00:09:42 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders a link inside a section', async () => {
2020-06-23 00:09:42 +05:30
setState([
{
title: 'GitLab Website',
url: 'https://gitlab.com',
},
]);
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findLinks()).toHaveLength(1);
const firstLink = findLinks().at(0);
2020-06-23 00:09:42 +05:30
2022-04-04 11:22:00 +05:30
expect(firstLink.attributes('href')).toBe('https://gitlab.com');
expect(firstLink.text()).toBe('GitLab Website');
2020-06-23 00:09:42 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders multiple links inside a section', async () => {
2020-06-23 00:09:42 +05:30
const links = new Array(10)
.fill(null)
.map((_, i) => ({ title: `Title ${i}`, url: `https://gitlab.com/projects/${i}` }));
setState(links);
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findLinks()).toHaveLength(10);
2020-06-23 00:09:42 +05:30
});
});