2021-10-29 18:13:13 +00:00
|
|
|
import { GlEmptyState, GlButton } from '@gitlab/ui';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import ClustersEmptyState from '~/clusters_list/components/clusters_empty_state.vue';
|
|
|
|
import ClusterStore from '~/clusters_list/store';
|
|
|
|
|
|
|
|
const clustersEmptyStateImage = 'path/to/svg';
|
2022-03-16 18:08:16 +00:00
|
|
|
const addClusterPath = '/path/to/connect/cluster';
|
2021-10-29 18:13:13 +00:00
|
|
|
const emptyStateHelpText = 'empty state text';
|
|
|
|
|
|
|
|
describe('ClustersEmptyStateComponent', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-12-02 21:10:16 +00:00
|
|
|
const defaultProvideData = {
|
2021-10-29 18:13:13 +00:00
|
|
|
clustersEmptyStateImage,
|
2022-03-16 18:08:16 +00:00
|
|
|
addClusterPath,
|
2021-10-29 18:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
|
|
|
const findEmptyStateText = () => wrapper.findByTestId('clusters-empty-state-text');
|
|
|
|
|
2021-12-02 21:10:16 +00:00
|
|
|
const createWrapper = ({
|
|
|
|
provideData = { emptyStateHelpText: null },
|
|
|
|
isChildComponent = false,
|
|
|
|
canAddCluster = true,
|
|
|
|
} = {}) => {
|
2021-10-29 18:13:13 +00:00
|
|
|
wrapper = shallowMountExtended(ClustersEmptyState, {
|
2021-12-02 21:10:16 +00:00
|
|
|
store: ClusterStore({ canAddCluster }),
|
|
|
|
propsData: { isChildComponent },
|
|
|
|
provide: { ...defaultProvideData, ...provideData },
|
2021-10-29 18:13:13 +00:00
|
|
|
stubs: { GlEmptyState },
|
|
|
|
});
|
2021-12-02 21:10:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
2021-10-29 18:13:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2021-11-15 18:12:21 +00:00
|
|
|
describe('when the component is loaded independently', () => {
|
|
|
|
it('should render the action button', () => {
|
|
|
|
expect(findButton().exists()).toBe(true);
|
|
|
|
});
|
2021-10-29 18:13:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the help text is not provided', () => {
|
|
|
|
it('should not render the empty state text', () => {
|
|
|
|
expect(findEmptyStateText().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-15 18:12:21 +00:00
|
|
|
describe('when the component is loaded as a child component', () => {
|
|
|
|
beforeEach(() => {
|
2021-12-02 21:10:16 +00:00
|
|
|
createWrapper({ isChildComponent: true });
|
2021-11-15 18:12:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the action button', () => {
|
|
|
|
expect(findButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-29 18:13:13 +00:00
|
|
|
describe('when the help text is provided', () => {
|
|
|
|
beforeEach(() => {
|
2021-12-02 21:10:16 +00:00
|
|
|
createWrapper({ provideData: { emptyStateHelpText } });
|
2021-10-29 18:13:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the empty state text', () => {
|
|
|
|
expect(findEmptyStateText().text()).toBe(emptyStateHelpText);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the user cannot add clusters', () => {
|
|
|
|
beforeEach(() => {
|
2021-12-02 21:10:16 +00:00
|
|
|
createWrapper({ canAddCluster: false });
|
2021-10-29 18:13:13 +00:00
|
|
|
});
|
|
|
|
it('should disable the button', () => {
|
|
|
|
expect(findButton().props('disabled')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|