debian-mirror-gitlab/spec/frontend/feature_flags/components/empty_state_spec.js

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

138 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import { GlAlert, GlEmptyState, GlLink, GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2021-09-04 01:27:46 +05:30
import EmptyState from '~/feature_flags/components/empty_state.vue';
2021-01-03 14:25:43 +05:30
const DEFAULT_PROPS = {
alerts: ['an alert', 'another alert'],
isLoading: false,
loadingLabel: 'test loading',
errorState: false,
errorTitle: 'test title',
2021-09-04 01:27:46 +05:30
emptyState: false,
2021-01-03 14:25:43 +05:30
emptyTitle: 'test empty',
2021-02-22 17:27:13 +05:30
emptyDescription: 'empty description',
2021-01-03 14:25:43 +05:30
};
const DEFAULT_PROVIDE = {
errorStateSvgPath: '/error.svg',
featureFlagsHelpPagePath: '/help/page/path',
};
describe('feature_flags/components/feature_flags_tab.vue', () => {
let wrapper;
const factory = (props = {}) =>
mount(
{
components: {
2021-09-04 01:27:46 +05:30
EmptyState,
2021-01-03 14:25:43 +05:30
},
render(h) {
2021-09-04 01:27:46 +05:30
return h(EmptyState, { props: this.$attrs, on: this.$listeners }, this.$slots.default);
2021-01-03 14:25:43 +05:30
},
},
{
propsData: {
...DEFAULT_PROPS,
...props,
},
provide: DEFAULT_PROVIDE,
slots: {
default: '<p data-testid="test-slot">testing</p>',
},
},
);
afterEach(() => {
if (wrapper?.destroy) {
wrapper.destroy();
}
wrapper = null;
});
describe('alerts', () => {
let alerts;
beforeEach(() => {
wrapper = factory();
alerts = wrapper.findAll(GlAlert);
});
it('should show any alerts', () => {
expect(alerts).toHaveLength(DEFAULT_PROPS.alerts.length);
alerts.wrappers.forEach((alert, i) => expect(alert.text()).toBe(DEFAULT_PROPS.alerts[i]));
});
it('should emit a dismiss event for a dismissed alert', () => {
alerts.at(0).vm.$emit('dismiss');
2021-09-04 01:27:46 +05:30
expect(wrapper.find(EmptyState).emitted('dismissAlert')).toEqual([[0]]);
2021-01-03 14:25:43 +05:30
});
});
describe('loading', () => {
beforeEach(() => {
wrapper = factory({ isLoading: true });
});
it('should show a loading icon and nothing else', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
expect(wrapper.findAll(GlEmptyState)).toHaveLength(0);
});
});
describe('error', () => {
let emptyState;
beforeEach(() => {
wrapper = factory({ errorState: true });
emptyState = wrapper.find(GlEmptyState);
});
it('should show an error state if there has been an error', () => {
expect(emptyState.text()).toContain(DEFAULT_PROPS.errorTitle);
expect(emptyState.text()).toContain(
'Try again in a few moments or contact your support team.',
);
expect(emptyState.props('svgPath')).toBe(DEFAULT_PROVIDE.errorStateSvgPath);
});
});
describe('empty', () => {
let emptyState;
let emptyStateLink;
beforeEach(() => {
wrapper = factory({ emptyState: true });
emptyState = wrapper.find(GlEmptyState);
emptyStateLink = emptyState.find(GlLink);
});
it('should show an empty state if it is empty', () => {
expect(emptyState.text()).toContain(DEFAULT_PROPS.emptyTitle);
2021-02-22 17:27:13 +05:30
expect(emptyState.text()).toContain(DEFAULT_PROPS.emptyDescription);
2021-01-03 14:25:43 +05:30
expect(emptyState.props('svgPath')).toBe(DEFAULT_PROVIDE.errorStateSvgPath);
expect(emptyStateLink.attributes('href')).toBe(DEFAULT_PROVIDE.featureFlagsHelpPagePath);
expect(emptyStateLink.text()).toBe('More information');
});
});
describe('slot', () => {
let slot;
beforeEach(async () => {
wrapper = factory();
2022-04-04 11:22:00 +05:30
await nextTick();
2021-01-03 14:25:43 +05:30
slot = wrapper.find('[data-testid="test-slot"]');
});
it('should display the passed slot', () => {
expect(slot.exists()).toBe(true);
expect(slot.text()).toBe('testing');
});
});
});