2017-09-10 17:25:29 +05:30
|
|
|
import Vue from 'vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import EmptyState from '~/monitoring/components/empty_state.vue';
|
2017-09-10 17:25:29 +05:30
|
|
|
import { statePaths } from './mock_data';
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
function createComponent(props) {
|
2018-03-17 18:26:18 +05:30
|
|
|
const Component = Vue.extend(EmptyState);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
return new Component({
|
2018-05-09 12:01:36 +05:30
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
settingsPath: statePaths.settingsPath,
|
|
|
|
clustersPath: statePaths.clustersPath,
|
|
|
|
documentationPath: statePaths.documentationPath,
|
|
|
|
emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
|
|
|
|
emptyLoadingSvgPath: '/path/to/loading.svg',
|
|
|
|
emptyNoDataSvgPath: '/path/to/no-data.svg',
|
|
|
|
emptyUnableToConnectSvgPath: '/path/to/unable-to-connect.svg',
|
|
|
|
},
|
2017-09-10 17:25:29 +05:30
|
|
|
}).$mount();
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
function getTextFromNode(component, selector) {
|
|
|
|
return component.$el.querySelector(selector).firstChild.nodeValue.trim();
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('EmptyState', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('Computed props', () => {
|
|
|
|
it('currentState', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'gettingStarted',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.currentState).toBe(component.states.gettingStarted);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('showButtonDescription returns a description with a link for the unableToConnect state', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'unableToConnect',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.showButtonDescription).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('showButtonDescription returns the description without a link for any other state', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'loading',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.showButtonDescription).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the gettingStarted state', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'gettingStarted',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.$el.querySelector('svg')).toBeDefined();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(getTextFromNode(component, '.state-title')).toEqual(
|
|
|
|
component.states.gettingStarted.title,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getTextFromNode(component, '.state-description')).toEqual(
|
|
|
|
component.states.gettingStarted.description,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getTextFromNode(component, '.btn-success')).toEqual(
|
|
|
|
component.states.gettingStarted.buttonText,
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the loading state', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'loading',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.$el.querySelector('svg')).toBeDefined();
|
|
|
|
expect(getTextFromNode(component, '.state-title')).toEqual(component.states.loading.title);
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(getTextFromNode(component, '.state-description')).toEqual(
|
|
|
|
component.states.loading.description,
|
|
|
|
);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(getTextFromNode(component, '.btn-success')).toEqual(component.states.loading.buttonText);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show the unableToConnect state', () => {
|
|
|
|
const component = createComponent({
|
|
|
|
selectedState: 'unableToConnect',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(component.$el.querySelector('svg')).toBeDefined();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(getTextFromNode(component, '.state-title')).toEqual(
|
|
|
|
component.states.unableToConnect.title,
|
|
|
|
);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(component.$el.querySelector('.state-description a')).toBeDefined();
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(getTextFromNode(component, '.btn-success')).toEqual(
|
|
|
|
component.states.unableToConnect.buttonText,
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|