debian-mirror-gitlab/spec/frontend/environments/empty_state_spec.js

113 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-06-21 17:19:12 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
import { s__ } from '~/locale';
import EmptyState from '~/environments/components/empty_state.vue';
import { ENVIRONMENTS_SCOPE } from '~/environments/constants';
const HELP_PATH = '/help';
2022-11-25 23:54:43 +05:30
const NEW_PATH = '/new';
2022-06-21 17:19:12 +05:30
describe('~/environments/components/empty_state.vue', () => {
let wrapper;
2022-11-25 23:54:43 +05:30
const findNewEnvironmentLink = () =>
wrapper.findByRole('link', {
2023-07-09 08:55:56 +05:30
name: s__('Environments|Create an environment'),
2022-11-25 23:54:43 +05:30
});
const findDocsLink = () =>
wrapper.findByRole('link', {
2023-07-09 08:55:56 +05:30
name: 'Learn more',
});
const finfEnablingReviewButton = () =>
wrapper.findByRole('button', {
name: s__('Environments|Enable review apps'),
2022-11-25 23:54:43 +05:30
});
2022-06-21 17:19:12 +05:30
const createWrapper = ({ propsData = {} } = {}) =>
mountExtended(EmptyState, {
propsData: {
scope: ENVIRONMENTS_SCOPE.AVAILABLE,
helpPath: HELP_PATH,
...propsData,
},
2022-11-25 23:54:43 +05:30
provide: { newEnvironmentPath: NEW_PATH },
2022-06-21 17:19:12 +05:30
});
2023-07-09 08:55:56 +05:30
describe('without search term', () => {
beforeEach(() => {
wrapper = createWrapper();
2022-06-21 17:19:12 +05:30
});
2023-07-09 08:55:56 +05:30
it('shows an empty state environments', () => {
const title = wrapper.findByRole('heading', {
name: s__('Environments|Get started with environments'),
});
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
expect(title.exists()).toBe(true);
});
it('shows a link to the the help path', () => {
const link = findDocsLink();
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
expect(link.attributes('href')).toBe(HELP_PATH);
2022-06-21 17:19:12 +05:30
});
2023-07-09 08:55:56 +05:30
it('shows a link to creating a new environment', () => {
const link = findNewEnvironmentLink();
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
expect(link.attributes('href')).toBe(NEW_PATH);
});
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
it('shows a button to enable review apps', () => {
const button = finfEnablingReviewButton();
2022-06-21 17:19:12 +05:30
2023-07-09 08:55:56 +05:30
expect(button.exists()).toBe(true);
});
it('should emit enable review', () => {
const button = finfEnablingReviewButton();
2022-11-25 23:54:43 +05:30
2023-07-09 08:55:56 +05:30
button.vm.$emit('click');
2022-11-25 23:54:43 +05:30
2023-07-09 08:55:56 +05:30
expect(wrapper.emitted('enable-review')).toBeDefined();
});
2022-11-25 23:54:43 +05:30
});
describe('with search term', () => {
beforeEach(() => {
wrapper = createWrapper({ propsData: { hasTerm: true } });
});
it('should show text about searching', () => {
const header = wrapper.findByRole('heading', {
name: s__('Environments|No results found'),
});
expect(header.exists()).toBe(true);
const text = wrapper.findByText(s__('Environments|Edit your search and try again'));
expect(text.exists()).toBe(true);
});
it('hides the documentation link', () => {
const link = findDocsLink();
expect(link.exists()).toBe(false);
});
2023-07-09 08:55:56 +05:30
it('hide a link to create a new environment', () => {
2022-11-25 23:54:43 +05:30
const link = findNewEnvironmentLink();
2023-07-09 08:55:56 +05:30
expect(link.exists()).toBe(false);
});
it('hide a button to enable review apps', () => {
const button = finfEnablingReviewButton();
expect(button.exists()).toBe(false);
2022-11-25 23:54:43 +05:30
});
});
2022-06-21 17:19:12 +05:30
});