2022-03-16 08:07:24 -04:00
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import { GlPagination } from '@gitlab/ui';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
|
|
|
import { sprintf, __, s__ } from '~/locale';
|
2020-02-19 04:08:59 -05:00
|
|
|
import EnvironmentsApp from '~/environments/components/environments_app.vue';
|
2022-03-16 08:07:24 -04:00
|
|
|
import EnvironmentsFolder from '~/environments/components/environment_folder.vue';
|
|
|
|
import EnvironmentsItem from '~/environments/components/new_environment_item.vue';
|
|
|
|
import EmptyState from '~/environments/components/empty_state.vue';
|
|
|
|
import StopEnvironmentModal from '~/environments/components/stop_environment_modal.vue';
|
|
|
|
import CanaryUpdateModal from '~/environments/components/canary_update_modal.vue';
|
|
|
|
import { resolvedEnvironmentsApp, resolvedFolder, resolvedEnvironment } from './graphql/mock_data';
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
Vue.use(VueApollo);
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
describe('~/environments/components/environments_app.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
let environmentAppMock;
|
|
|
|
let environmentFolderMock;
|
|
|
|
let paginationMock;
|
|
|
|
let environmentToStopMock;
|
|
|
|
let environmentToChangeCanaryMock;
|
|
|
|
let weightMock;
|
|
|
|
|
|
|
|
const createApolloProvider = () => {
|
|
|
|
const mockResolvers = {
|
|
|
|
Query: {
|
|
|
|
environmentApp: environmentAppMock,
|
|
|
|
folder: environmentFolderMock,
|
|
|
|
pageInfo: paginationMock,
|
|
|
|
environmentToStop: environmentToStopMock,
|
|
|
|
environmentToDelete: jest.fn().mockResolvedValue(resolvedEnvironment),
|
|
|
|
environmentToRollback: jest.fn().mockResolvedValue(resolvedEnvironment),
|
|
|
|
environmentToChangeCanary: environmentToChangeCanaryMock,
|
|
|
|
weight: weightMock,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return createMockApollo([], mockResolvers);
|
2020-02-19 04:08:59 -05:00
|
|
|
};
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const createWrapper = ({ provide = {}, apolloProvider } = {}) =>
|
|
|
|
mountExtended(EnvironmentsApp, {
|
|
|
|
provide: {
|
|
|
|
newEnvironmentPath: '/environments/new',
|
|
|
|
canCreateEnvironment: true,
|
|
|
|
defaultBranchName: 'main',
|
|
|
|
helpPagePath: '/help',
|
|
|
|
projectId: '1',
|
|
|
|
...provide,
|
|
|
|
},
|
|
|
|
apolloProvider,
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const createWrapperWithMocked = async ({
|
|
|
|
provide = {},
|
|
|
|
environmentsApp,
|
|
|
|
folder,
|
|
|
|
environmentToStop = {},
|
|
|
|
environmentToChangeCanary = {},
|
|
|
|
weight = 0,
|
|
|
|
pageInfo = {
|
|
|
|
total: 20,
|
|
|
|
perPage: 5,
|
|
|
|
nextPage: 3,
|
|
|
|
page: 2,
|
|
|
|
previousPage: 1,
|
|
|
|
__typename: 'LocalPageInfo',
|
|
|
|
},
|
|
|
|
location = '?scope=available&page=2',
|
|
|
|
}) => {
|
|
|
|
setWindowLocation(location);
|
|
|
|
environmentAppMock.mockReturnValue(environmentsApp);
|
|
|
|
environmentFolderMock.mockReturnValue(folder);
|
|
|
|
paginationMock.mockReturnValue(pageInfo);
|
|
|
|
environmentToStopMock.mockReturnValue(environmentToStop);
|
|
|
|
environmentToChangeCanaryMock.mockReturnValue(environmentToChangeCanary);
|
|
|
|
weightMock.mockReturnValue(weight);
|
|
|
|
const apolloProvider = createApolloProvider();
|
|
|
|
wrapper = createWrapper({ apolloProvider, provide });
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
await nextTick();
|
2020-02-19 04:08:59 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-03-16 08:07:24 -04:00
|
|
|
environmentAppMock = jest.fn();
|
|
|
|
environmentFolderMock = jest.fn();
|
|
|
|
environmentToStopMock = jest.fn();
|
|
|
|
environmentToChangeCanaryMock = jest.fn();
|
|
|
|
weightMock = jest.fn();
|
|
|
|
paginationMock = jest.fn();
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should request available environments if the scope is invalid', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
location: '?scope=bad&page=2',
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
expect(environmentAppMock).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ scope: 'available', page: 2 }),
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show all the folders that are fetched', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const text = wrapper.findAllComponents(EnvironmentsFolder).wrappers.map((w) => w.text());
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
expect(text).toContainEqual(expect.stringMatching('review'));
|
|
|
|
expect(text).not.toContainEqual(expect.stringMatching('production'));
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should show all the environments that are fetched', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const text = wrapper.findAllComponents(EnvironmentsItem).wrappers.map((w) => w.text());
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
expect(text).not.toContainEqual(expect.stringMatching('review'));
|
|
|
|
expect(text).toContainEqual(expect.stringMatching('production'));
|
|
|
|
});
|
2021-01-05 13:10:25 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should show an empty state with no environments', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: { ...resolvedEnvironmentsApp, environments: [] },
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
2022-03-16 08:07:24 -04:00
|
|
|
|
|
|
|
expect(wrapper.findComponent(EmptyState).exists()).toBe(true);
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should show a button to create a new environment', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const button = wrapper.findByRole('link', { name: s__('Environments|New environment') });
|
|
|
|
expect(button.attributes('href')).toBe('/environments/new');
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should not show a button to create a new environment if the user has no permissions', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
provide: { canCreateEnvironment: false, newEnvironmentPath: '' },
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const button = wrapper.findByRole('link', { name: s__('Environments|New environment') });
|
|
|
|
expect(button.exists()).toBe(false);
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should show a button to open the review app modal', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const button = wrapper.findByRole('button', { name: s__('Environments|Enable review app') });
|
|
|
|
button.trigger('click');
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
await nextTick();
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
expect(wrapper.findByText(s__('ReviewApp|Enable Review App')).exists()).toBe(true);
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should not show a button to open the review app modal if review apps are configured', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: {
|
|
|
|
...resolvedEnvironmentsApp,
|
|
|
|
reviewApp: { canSetupReviewApp: false },
|
|
|
|
},
|
|
|
|
folder: resolvedFolder,
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const button = wrapper.findByRole('button', { name: s__('Environments|Enable review app') });
|
|
|
|
expect(button.exists()).toBe(false);
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|
2020-10-10 08:08:27 -04:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
describe('tabs', () => {
|
|
|
|
it('should show tabs for available and stopped environmets', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const [available, stopped] = wrapper.findAllByRole('tab').wrappers;
|
|
|
|
|
|
|
|
expect(available.text()).toContain(__('Available'));
|
|
|
|
expect(available.text()).toContain(resolvedEnvironmentsApp.availableCount);
|
|
|
|
expect(stopped.text()).toContain(__('Stopped'));
|
|
|
|
expect(stopped.text()).toContain(resolvedEnvironmentsApp.stoppedCount);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change the requested scope on tab change', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
});
|
|
|
|
const stopped = wrapper.findByRole('tab', {
|
|
|
|
name: `${__('Stopped')} ${resolvedEnvironmentsApp.stoppedCount}`,
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
2022-03-16 08:07:24 -04:00
|
|
|
|
|
|
|
stopped.trigger('click');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(environmentAppMock).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ scope: 'stopped', page: 1 }),
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
2022-03-16 08:07:24 -04:00
|
|
|
});
|
2020-10-10 08:08:27 -04:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
describe('modals', () => {
|
|
|
|
it('should pass the environment to stop to the stop environment modal', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
environmentToStop: resolvedEnvironment,
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const modal = wrapper.findComponent(StopEnvironmentModal);
|
|
|
|
|
|
|
|
expect(modal.props('environment')).toMatchObject(resolvedEnvironment);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pass the environment to change canary to the canary update modal', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
environmentToChangeCanary: resolvedEnvironment,
|
|
|
|
weight: 10,
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
2022-03-16 08:07:24 -04:00
|
|
|
|
|
|
|
const modal = wrapper.findComponent(CanaryUpdateModal);
|
|
|
|
|
|
|
|
expect(modal.props('environment')).toMatchObject(resolvedEnvironment);
|
2020-10-10 08:08:27 -04:00
|
|
|
});
|
|
|
|
});
|
2020-10-16 08:09:33 -04:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
describe('pagination', () => {
|
|
|
|
it('should sync page from query params on load', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
expect(wrapper.findComponent(GlPagination).props('value')).toBe(2);
|
|
|
|
});
|
2020-10-16 08:09:33 -04:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should change the requested page on next page click', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
});
|
|
|
|
const next = wrapper.findByRole('link', {
|
|
|
|
name: __('Go to next page'),
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
2022-03-16 08:07:24 -04:00
|
|
|
|
|
|
|
next.trigger('click');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(environmentAppMock).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ page: 3 }),
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should change the requested page on previous page click', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
});
|
|
|
|
const prev = wrapper.findByRole('link', {
|
|
|
|
name: __('Go to previous page'),
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
prev.trigger('click');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(environmentAppMock).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ page: 1 }),
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change the requested page on specific page click', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
const page = 1;
|
|
|
|
const pageButton = wrapper.findByRole('link', {
|
|
|
|
name: sprintf(__('Go to page %{page}'), { page }),
|
2020-10-16 08:09:33 -04:00
|
|
|
});
|
2021-06-21 08:07:45 -04:00
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
pageButton.trigger('click');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(environmentAppMock).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
expect.objectContaining({ page }),
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
2021-06-21 08:07:45 -04:00
|
|
|
});
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
it('should sync the query params to the new page', async () => {
|
|
|
|
await createWrapperWithMocked({
|
|
|
|
environmentsApp: resolvedEnvironmentsApp,
|
|
|
|
folder: resolvedFolder,
|
|
|
|
});
|
|
|
|
const next = wrapper.findByRole('link', {
|
|
|
|
name: __('Go to next page'),
|
|
|
|
});
|
|
|
|
|
|
|
|
next.trigger('click');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
expect(window.location.search).toBe('?scope=available&page=3');
|
2021-06-21 08:07:45 -04:00
|
|
|
});
|
|
|
|
});
|
2020-02-19 04:08:59 -05:00
|
|
|
});
|