2021-01-03 14:25:43 +05:30
|
|
|
import { GlPagination } from '@gitlab/ui';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { removeBreakLine, removeWhitespace } from 'helpers/text_helper';
|
2020-03-13 15:44:24 +05:30
|
|
|
import EnvironmentTable from '~/environments/components/environments_table.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
import EnvironmentsFolderViewComponent from '~/environments/folder/environments_folder_view.vue';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { environmentsList } from '../mock_data';
|
|
|
|
|
|
|
|
describe('Environments Folder View', () => {
|
|
|
|
let mock;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const mockData = {
|
|
|
|
endpoint: 'environments.json',
|
|
|
|
folderName: 'review',
|
|
|
|
cssContainerClass: 'container',
|
|
|
|
userCalloutsPath: '/callouts',
|
|
|
|
lockPromotionSvgPath: '/assets/illustrations/lock-promotion.svg',
|
|
|
|
helpCanaryDeploymentsPath: 'help/canary-deployments',
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const mockEnvironments = (environmentList) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mock.onGet(mockData.endpoint).reply(
|
2023-04-23 21:23:45 +05:30
|
|
|
HTTP_STATUS_OK,
|
2020-03-13 15:44:24 +05:30
|
|
|
{
|
|
|
|
environments: environmentList,
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const createWrapper = () => {
|
|
|
|
wrapper = mount(EnvironmentsFolderViewComponent, { propsData: mockData });
|
|
|
|
};
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const findEnvironmentsTabAvailable = () =>
|
|
|
|
wrapper.find('[data-testid="environments-tab-available"]');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const findEnvironmentsTabStopped = () => wrapper.find('[data-testid="environments-tab-stopped"]');
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('successful request', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockEnvironments(environmentsList);
|
|
|
|
createWrapper();
|
|
|
|
return axios.waitForAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a table with environments', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const table = wrapper.findComponent(EnvironmentTable);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(table.exists()).toBe(true);
|
|
|
|
expect(table.find('.environment-name').text()).toEqual(environmentsList[0].name);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render available tab with count', () => {
|
|
|
|
const tabTable = findEnvironmentsTabAvailable();
|
|
|
|
|
|
|
|
expect(tabTable.text()).toContain('Available');
|
|
|
|
expect(tabTable.find('.badge').text()).toContain('0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render stopped tab with count', () => {
|
|
|
|
const tabTable = findEnvironmentsTabStopped();
|
|
|
|
|
|
|
|
expect(tabTable.text()).toContain('Stopped');
|
|
|
|
expect(tabTable.find('.badge').text()).toContain('1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render parent folder name', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(
|
|
|
|
removeBreakLine(removeWhitespace(wrapper.find('[data-testid="folder-name"]').text())),
|
|
|
|
).toContain('Environments / review');
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('pagination', () => {
|
|
|
|
it('should render pagination', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlPagination).exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unsuccessfull request', () => {
|
|
|
|
beforeEach(() => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(mockData.endpoint).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR, { environments: [] });
|
2020-03-13 15:44:24 +05:30
|
|
|
createWrapper();
|
|
|
|
return axios.waitForAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render a table', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(EnvironmentTable).exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render available tab with count 0', () => {
|
|
|
|
const tabTable = findEnvironmentsTabAvailable();
|
|
|
|
|
|
|
|
expect(tabTable.text()).toContain('Available');
|
|
|
|
expect(tabTable.find('.badge').text()).toContain('0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render stopped tab with count 0', () => {
|
|
|
|
const tabTable = findEnvironmentsTabStopped();
|
|
|
|
|
|
|
|
expect(tabTable.text()).toContain('Stopped');
|
|
|
|
expect(tabTable.find('.badge').text()).toContain('0');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockEnvironments([]);
|
|
|
|
createWrapper();
|
|
|
|
jest.spyOn(window.history, 'pushState').mockImplementation(() => {});
|
|
|
|
return axios.waitForAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateContent', () => {
|
|
|
|
it('should set given parameters', () =>
|
|
|
|
wrapper.vm.updateContent({ scope: 'stopped', page: '4' }).then(() => {
|
|
|
|
expect(wrapper.vm.page).toEqual('4');
|
|
|
|
expect(wrapper.vm.scope).toEqual('stopped');
|
|
|
|
expect(wrapper.vm.requestData.page).toEqual('4');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|