2021-11-03 21:10:35 +00:00
|
|
|
import VueApollo from 'vue-apollo';
|
2022-01-11 00:13:53 +00:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-11-03 21:10:35 +00:00
|
|
|
import { GlCollapse, GlIcon } from '@gitlab/ui';
|
2022-01-11 00:13:53 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-11-03 21:10:35 +00:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2022-01-11 00:13:53 +00:00
|
|
|
import { stubTransition } from 'helpers/stub_transition';
|
2021-11-26 15:13:11 +00:00
|
|
|
import { __, s__ } from '~/locale';
|
2022-03-16 12:07:24 +00:00
|
|
|
import EnvironmentsFolder from '~/environments/components/environment_folder.vue';
|
2022-01-11 00:13:53 +00:00
|
|
|
import EnvironmentItem from '~/environments/components/new_environment_item.vue';
|
2021-11-03 21:10:35 +00:00
|
|
|
import { resolvedEnvironmentsApp, resolvedFolder } from './graphql/mock_data';
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2022-03-16 12:07:24 +00:00
|
|
|
describe('~/environments/components/environments_folder.vue', () => {
|
2021-11-03 21:10:35 +00:00
|
|
|
let wrapper;
|
|
|
|
let environmentFolderMock;
|
2022-05-11 18:07:55 +00:00
|
|
|
let intervalMock;
|
2021-11-03 21:10:35 +00:00
|
|
|
let nestedEnvironment;
|
|
|
|
|
|
|
|
const findLink = () => wrapper.findByRole('link', { name: s__('Environments|Show all') });
|
|
|
|
|
|
|
|
const createApolloProvider = () => {
|
2022-05-11 18:07:55 +00:00
|
|
|
const mockResolvers = { Query: { folder: environmentFolderMock, interval: intervalMock } };
|
2021-11-03 21:10:35 +00:00
|
|
|
|
|
|
|
return createMockApollo([], mockResolvers);
|
|
|
|
};
|
|
|
|
|
|
|
|
const createWrapper = (propsData, apolloProvider) =>
|
2022-01-11 00:13:53 +00:00
|
|
|
mountExtended(EnvironmentsFolder, {
|
|
|
|
apolloProvider,
|
2022-03-11 18:08:37 +00:00
|
|
|
propsData: {
|
|
|
|
scope: 'available',
|
|
|
|
...propsData,
|
|
|
|
},
|
2022-01-11 00:13:53 +00:00
|
|
|
stubs: { transition: stubTransition() },
|
2022-01-25 06:16:04 +00:00
|
|
|
provide: { helpPagePath: '/help' },
|
2022-01-11 00:13:53 +00:00
|
|
|
});
|
2021-11-03 21:10:35 +00:00
|
|
|
|
2022-01-11 00:13:53 +00:00
|
|
|
beforeEach(async () => {
|
2021-11-03 21:10:35 +00:00
|
|
|
environmentFolderMock = jest.fn();
|
|
|
|
[nestedEnvironment] = resolvedEnvironmentsApp.environments;
|
|
|
|
environmentFolderMock.mockReturnValue(resolvedFolder);
|
2022-05-11 18:07:55 +00:00
|
|
|
intervalMock = jest.fn();
|
|
|
|
intervalMock.mockReturnValue(2000);
|
2021-11-03 21:10:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper?.destroy();
|
|
|
|
});
|
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
describe('default', () => {
|
|
|
|
let folderName;
|
|
|
|
let button;
|
2021-11-03 21:10:35 +00:00
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = createWrapper({ nestedEnvironment }, createApolloProvider());
|
2021-11-03 21:10:35 +00:00
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
folderName = wrapper.findByText(nestedEnvironment.name);
|
|
|
|
button = wrapper.findByRole('button', { name: __('Expand') });
|
2021-11-03 21:10:35 +00:00
|
|
|
});
|
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
it('displays the name of the folder', () => {
|
|
|
|
expect(folderName.text()).toBe(nestedEnvironment.name);
|
2021-11-03 21:10:35 +00:00
|
|
|
});
|
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
describe('collapse', () => {
|
|
|
|
let icons;
|
|
|
|
let collapse;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
collapse = wrapper.findComponent(GlCollapse);
|
|
|
|
icons = wrapper.findAllComponents(GlIcon);
|
2022-05-11 18:07:55 +00:00
|
|
|
jest.spyOn(wrapper.vm.$apollo.queries.folder, 'startPolling');
|
|
|
|
jest.spyOn(wrapper.vm.$apollo.queries.folder, 'stopPolling');
|
2022-03-11 18:08:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('is collapsed by default', () => {
|
|
|
|
const link = findLink();
|
|
|
|
|
|
|
|
expect(collapse.attributes('visible')).toBeUndefined();
|
|
|
|
const iconNames = icons.wrappers.map((i) => i.props('name')).slice(0, 2);
|
|
|
|
expect(iconNames).toEqual(['angle-right', 'folder-o']);
|
|
|
|
expect(folderName.classes('gl-font-weight-bold')).toBe(false);
|
|
|
|
expect(link.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens on click', async () => {
|
|
|
|
await button.trigger('click');
|
|
|
|
|
|
|
|
const link = findLink();
|
|
|
|
|
|
|
|
expect(button.attributes('aria-label')).toBe(__('Collapse'));
|
|
|
|
expect(collapse.attributes('visible')).toBe('visible');
|
|
|
|
const iconNames = icons.wrappers.map((i) => i.props('name')).slice(0, 2);
|
|
|
|
expect(iconNames).toEqual(['angle-down', 'folder-open']);
|
|
|
|
expect(folderName.classes('gl-font-weight-bold')).toBe(true);
|
|
|
|
expect(link.attributes('href')).toBe(nestedEnvironment.latest.folderPath);
|
2022-05-11 18:07:55 +00:00
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.queries.folder.startPolling).toHaveBeenCalledWith(2000);
|
2022-03-11 18:08:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays all environments when opened', async () => {
|
|
|
|
await button.trigger('click');
|
|
|
|
|
|
|
|
const names = resolvedFolder.environments.map((e) =>
|
|
|
|
expect.stringMatching(e.nameWithoutType),
|
|
|
|
);
|
|
|
|
const environments = wrapper
|
|
|
|
.findAllComponents(EnvironmentItem)
|
|
|
|
.wrappers.map((w) => w.text());
|
|
|
|
expect(environments).toEqual(expect.arrayContaining(names));
|
|
|
|
});
|
2022-05-11 18:07:55 +00:00
|
|
|
|
|
|
|
it('stops polling on click', async () => {
|
|
|
|
await button.trigger('click');
|
|
|
|
expect(wrapper.vm.$apollo.queries.folder.startPolling).toHaveBeenCalledWith(2000);
|
|
|
|
|
|
|
|
const collapseButton = wrapper.findByRole('button', { name: __('Collapse') });
|
|
|
|
await collapseButton.trigger('click');
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.queries.folder.stopPolling).toHaveBeenCalled();
|
|
|
|
});
|
2021-11-03 21:10:35 +00:00
|
|
|
});
|
2022-03-11 18:08:37 +00:00
|
|
|
});
|
2022-01-11 00:13:53 +00:00
|
|
|
|
2022-03-11 18:08:37 +00:00
|
|
|
it.each(['available', 'stopped'])(
|
|
|
|
'with scope=%s, fetches environments with scope',
|
|
|
|
async (scope) => {
|
|
|
|
wrapper = createWrapper({ nestedEnvironment, scope }, createApolloProvider());
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(environmentFolderMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(environmentFolderMock).toHaveBeenCalledWith(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
environment: nestedEnvironment.latest,
|
|
|
|
scope,
|
|
|
|
},
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
2022-01-11 00:13:53 +00:00
|
|
|
);
|
2022-03-11 18:08:37 +00:00
|
|
|
},
|
|
|
|
);
|
2021-11-03 21:10:35 +00:00
|
|
|
});
|