2021-11-03 17:10:35 -04:00
|
|
|
import VueApollo from 'vue-apollo';
|
2022-01-10 19:13:53 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-11-03 17:10:35 -04:00
|
|
|
import { GlCollapse, GlIcon } from '@gitlab/ui';
|
2022-01-10 19:13:53 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-11-03 17:10:35 -04:00
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2022-01-10 19:13:53 -05:00
|
|
|
import { stubTransition } from 'helpers/stub_transition';
|
2021-11-26 10:13:11 -05:00
|
|
|
import { __, s__ } from '~/locale';
|
2022-03-16 08:07:24 -04:00
|
|
|
import EnvironmentsFolder from '~/environments/components/environment_folder.vue';
|
2022-01-10 19:13:53 -05:00
|
|
|
import EnvironmentItem from '~/environments/components/new_environment_item.vue';
|
2021-11-03 17:10:35 -04:00
|
|
|
import { resolvedEnvironmentsApp, resolvedFolder } from './graphql/mock_data';
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2022-03-16 08:07:24 -04:00
|
|
|
describe('~/environments/components/environments_folder.vue', () => {
|
2021-11-03 17:10:35 -04:00
|
|
|
let wrapper;
|
|
|
|
let environmentFolderMock;
|
|
|
|
let nestedEnvironment;
|
|
|
|
|
|
|
|
const findLink = () => wrapper.findByRole('link', { name: s__('Environments|Show all') });
|
|
|
|
|
|
|
|
const createApolloProvider = () => {
|
|
|
|
const mockResolvers = { Query: { folder: environmentFolderMock } };
|
|
|
|
|
|
|
|
return createMockApollo([], mockResolvers);
|
|
|
|
};
|
|
|
|
|
|
|
|
const createWrapper = (propsData, apolloProvider) =>
|
2022-01-10 19:13:53 -05:00
|
|
|
mountExtended(EnvironmentsFolder, {
|
|
|
|
apolloProvider,
|
2022-03-11 13:08:37 -05:00
|
|
|
propsData: {
|
|
|
|
scope: 'available',
|
|
|
|
...propsData,
|
|
|
|
},
|
2022-01-10 19:13:53 -05:00
|
|
|
stubs: { transition: stubTransition() },
|
2022-01-25 01:16:04 -05:00
|
|
|
provide: { helpPagePath: '/help' },
|
2022-01-10 19:13:53 -05:00
|
|
|
});
|
2021-11-03 17:10:35 -04:00
|
|
|
|
2022-01-10 19:13:53 -05:00
|
|
|
beforeEach(async () => {
|
2021-11-03 17:10:35 -04:00
|
|
|
environmentFolderMock = jest.fn();
|
|
|
|
[nestedEnvironment] = resolvedEnvironmentsApp.environments;
|
|
|
|
environmentFolderMock.mockReturnValue(resolvedFolder);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper?.destroy();
|
|
|
|
});
|
|
|
|
|
2022-03-11 13:08:37 -05:00
|
|
|
describe('default', () => {
|
|
|
|
let folderName;
|
|
|
|
let button;
|
2021-11-03 17:10:35 -04:00
|
|
|
|
2022-03-11 13:08:37 -05:00
|
|
|
beforeEach(async () => {
|
|
|
|
wrapper = createWrapper({ nestedEnvironment }, createApolloProvider());
|
2021-11-03 17:10:35 -04:00
|
|
|
|
2022-03-11 13:08:37 -05:00
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
|
|
|
folderName = wrapper.findByText(nestedEnvironment.name);
|
|
|
|
button = wrapper.findByRole('button', { name: __('Expand') });
|
2021-11-03 17:10:35 -04:00
|
|
|
});
|
|
|
|
|
2022-03-11 13:08:37 -05:00
|
|
|
it('displays the name of the folder', () => {
|
|
|
|
expect(folderName.text()).toBe(nestedEnvironment.name);
|
2021-11-03 17:10:35 -04:00
|
|
|
});
|
|
|
|
|
2022-03-11 13:08:37 -05:00
|
|
|
describe('collapse', () => {
|
|
|
|
let icons;
|
|
|
|
let collapse;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
collapse = wrapper.findComponent(GlCollapse);
|
|
|
|
icons = wrapper.findAllComponents(GlIcon);
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
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));
|
|
|
|
});
|
2021-11-03 17:10:35 -04:00
|
|
|
});
|
2022-03-11 13:08:37 -05:00
|
|
|
});
|
2022-01-10 19:13:53 -05:00
|
|
|
|
2022-03-11 13:08:37 -05: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-10 19:13:53 -05:00
|
|
|
);
|
2022-03-11 13:08:37 -05:00
|
|
|
},
|
|
|
|
);
|
2021-11-03 17:10:35 -04:00
|
|
|
});
|