2017-03-13 20:58:26 -04:00
|
|
|
import Vue from 'vue';
|
2018-05-14 13:29:21 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-04-27 10:06:17 -04:00
|
|
|
import environmentsFolderViewComponent from '~/environments/folder/environments_folder_view.vue';
|
2018-02-26 14:43:34 -05:00
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2017-03-13 20:58:26 -04:00
|
|
|
import { environmentsList } from '../mock_data';
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
describe('Environments Folder View', () => {
|
2017-11-23 07:04:03 -05:00
|
|
|
let Component;
|
|
|
|
let component;
|
2018-05-14 13:29:21 -04:00
|
|
|
let mock;
|
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
const mockData = {
|
|
|
|
endpoint: 'environments.json',
|
|
|
|
folderName: 'review',
|
|
|
|
canCreateDeployment: true,
|
|
|
|
canReadEnvironment: true,
|
|
|
|
cssContainerClass: 'container',
|
|
|
|
};
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-05-14 13:29:21 -04:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
Component = Vue.extend(environmentsFolderViewComponent);
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
|
|
|
|
2017-09-06 12:14:34 -04:00
|
|
|
afterEach(() => {
|
2018-05-14 13:29:21 -04:00
|
|
|
mock.restore();
|
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$destroy();
|
2017-09-06 12:14:34 -04:00
|
|
|
});
|
|
|
|
|
2018-10-30 06:53:01 -04:00
|
|
|
describe('successful request', () => {
|
2018-05-14 13:29:21 -04:00
|
|
|
beforeEach(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
mock.onGet(mockData.endpoint).reply(
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
environments: environmentsList,
|
|
|
|
stopped_count: 1,
|
|
|
|
available_count: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'X-nExt-pAge': '2',
|
|
|
|
'x-page': '1',
|
|
|
|
'X-Per-Page': '2',
|
|
|
|
'X-Prev-Page': '',
|
|
|
|
'X-TOTAL': '20',
|
|
|
|
'X-Total-Pages': '10',
|
|
|
|
},
|
|
|
|
);
|
2017-07-12 10:47:09 -04:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
component = mountComponent(Component, mockData);
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render a table with environments', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(component.$el.querySelectorAll('table')).not.toBeNull();
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.environment-name').textContent.trim()).toEqual(
|
|
|
|
environmentsList[0].name,
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render available tab with count', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-environments-tab-available').textContent).toContain(
|
|
|
|
'Available',
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
expect(
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$el.querySelector('.js-environments-tab-available .badge').textContent,
|
2017-02-13 11:11:11 -05:00
|
|
|
).toContain('0');
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render stopped tab with count', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-environments-tab-stopped').textContent).toContain(
|
|
|
|
'Stopped',
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
expect(
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$el.querySelector('.js-environments-tab-stopped .badge').textContent,
|
2017-02-13 11:11:11 -05:00
|
|
|
).toContain('1');
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render parent folder name', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-folder-name').textContent.trim()).toContain(
|
|
|
|
'Environments / review',
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('pagination', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render pagination', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelectorAll('.gl-pagination')).not.toBeNull();
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should make an API request when changing page', done => {
|
2017-11-23 07:04:03 -05:00
|
|
|
spyOn(component, 'updateContent');
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$el.querySelector('.gl-pagination .js-last-button a').click();
|
2017-02-13 11:11:11 -05:00
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({
|
|
|
|
scope: component.scope,
|
|
|
|
page: '10',
|
|
|
|
});
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should make an API request when using tabs', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2017-11-23 07:04:03 -05:00
|
|
|
spyOn(component, 'updateContent');
|
|
|
|
component.$el.querySelector('.js-environments-tab-stopped').click();
|
2017-02-13 11:11:11 -05:00
|
|
|
|
2017-11-23 07:04:03 -05:00
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'stopped', page: '1' });
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unsuccessfull request', () => {
|
|
|
|
beforeEach(() => {
|
2018-05-14 13:29:21 -04:00
|
|
|
mock.onGet(mockData.endpoint).reply(500, {
|
|
|
|
environments: [],
|
|
|
|
});
|
2017-02-13 11:11:11 -05:00
|
|
|
|
2018-05-14 13:29:21 -04:00
|
|
|
component = mountComponent(Component, mockData);
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should not render a table', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('table')).toBe(null);
|
2017-02-13 11:11:11 -05:00
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render available tab with count 0', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-environments-tab-available').textContent).toContain(
|
|
|
|
'Available',
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
expect(
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$el.querySelector('.js-environments-tab-available .badge').textContent,
|
2017-02-13 11:11:11 -05:00
|
|
|
).toContain('0');
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should render stopped tab with count 0', done => {
|
2017-02-13 11:11:11 -05:00
|
|
|
setTimeout(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(component.$el.querySelector('.js-environments-tab-stopped').textContent).toContain(
|
|
|
|
'Stopped',
|
|
|
|
);
|
2017-02-13 11:11:11 -05:00
|
|
|
|
|
|
|
expect(
|
2017-11-23 07:04:03 -05:00
|
|
|
component.$el.querySelector('.js-environments-tab-stopped .badge').textContent,
|
2017-02-13 11:11:11 -05:00
|
|
|
).toContain('0');
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
2018-05-14 13:29:21 -04:00
|
|
|
mock.onGet(mockData.endpoint).reply(200, {
|
|
|
|
environments: [],
|
|
|
|
});
|
2017-11-23 07:04:03 -05:00
|
|
|
|
|
|
|
component = mountComponent(Component, mockData);
|
2018-06-15 11:58:27 -04:00
|
|
|
spyOn(window.history, 'pushState').and.stub();
|
2017-11-23 07:04:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateContent', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
it('should set given parameters', done => {
|
|
|
|
component
|
|
|
|
.updateContent({ scope: 'stopped', page: '4' })
|
2017-11-23 07:04:03 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(component.page).toEqual('4');
|
|
|
|
expect(component.scope).toEqual('stopped');
|
|
|
|
expect(component.requestData.scope).toEqual('stopped');
|
|
|
|
expect(component.requestData.page).toEqual('4');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangeTab', () => {
|
|
|
|
it('should set page to 1', () => {
|
|
|
|
spyOn(component, 'updateContent');
|
|
|
|
component.onChangeTab('stopped');
|
|
|
|
|
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'stopped', page: '1' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChangePage', () => {
|
|
|
|
it('should update page and keep scope', () => {
|
|
|
|
spyOn(component, 'updateContent');
|
|
|
|
|
|
|
|
component.onChangePage(4);
|
|
|
|
|
|
|
|
expect(component.updateContent).toHaveBeenCalledWith({ scope: component.scope, page: '4' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-02-13 11:11:11 -05:00
|
|
|
});
|