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

67 lines
1.6 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,
};
};
const findLinks = () => wrapper.findAll(GlLink);
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
});
it('renders a link inside a section', () => {
setState([
{
title: 'GitLab Website',
url: 'https://gitlab.com',
},
]);
return wrapper.vm.$nextTick(() => {
expect(findLinks()).toHaveLength(1);
const firstLink = findLinks().at(0);
expect(firstLink.attributes('href')).toBe('https://gitlab.com');
expect(firstLink.text()).toBe('GitLab Website');
});
});
it('renders multiple links inside a section', () => {
const links = new Array(10)
.fill(null)
.map((_, i) => ({ title: `Title ${i}`, url: `https://gitlab.com/projects/${i}` }));
setState(links);
return wrapper.vm.$nextTick(() => {
expect(findLinks()).toHaveLength(10);
});
});
});