2021-12-11 22:18:48 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2022-03-02 08:16:31 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { GlCollapse, GlIcon } from '@gitlab/ui';
|
2022-03-02 08:16:31 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-12-11 22:18:48 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2022-03-02 08:16:31 +05:30
|
|
|
import { stubTransition } from 'helpers/stub_transition';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { __, s__ } from '~/locale';
|
2021-12-11 22:18:48 +05:30
|
|
|
import EnvironmentsFolder from '~/environments/components/new_environment_folder.vue';
|
2022-03-02 08:16:31 +05:30
|
|
|
import EnvironmentItem from '~/environments/components/new_environment_item.vue';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { resolvedEnvironmentsApp, resolvedFolder } from './graphql/mock_data';
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
describe('~/environments/components/new_environments_folder.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
let environmentFolderMock;
|
|
|
|
let nestedEnvironment;
|
|
|
|
let folderName;
|
2022-01-26 12:08:38 +05:30
|
|
|
let button;
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
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-03-02 08:16:31 +05:30
|
|
|
mountExtended(EnvironmentsFolder, {
|
|
|
|
apolloProvider,
|
|
|
|
propsData,
|
|
|
|
stubs: { transition: stubTransition() },
|
2022-04-04 11:22:00 +05:30
|
|
|
provide: { helpPagePath: '/help' },
|
2022-03-02 08:16:31 +05:30
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
beforeEach(async () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
environmentFolderMock = jest.fn();
|
|
|
|
[nestedEnvironment] = resolvedEnvironmentsApp.environments;
|
|
|
|
environmentFolderMock.mockReturnValue(resolvedFolder);
|
|
|
|
wrapper = createWrapper({ nestedEnvironment }, createApolloProvider());
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
await waitForPromises();
|
2021-12-11 22:18:48 +05:30
|
|
|
folderName = wrapper.findByText(nestedEnvironment.name);
|
2022-01-26 12:08:38 +05:30
|
|
|
button = wrapper.findByRole('button', { name: __('Expand') });
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper?.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the name of the folder', () => {
|
|
|
|
expect(folderName.text()).toBe(nestedEnvironment.name);
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
2022-03-02 08:16:31 +05:30
|
|
|
const iconNames = icons.wrappers.map((i) => i.props('name')).slice(0, 2);
|
|
|
|
expect(iconNames).toEqual(['angle-right', 'folder-o']);
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(folderName.classes('gl-font-weight-bold')).toBe(false);
|
|
|
|
expect(link.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens on click', async () => {
|
2022-01-26 12:08:38 +05:30
|
|
|
await button.trigger('click');
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
const link = findLink();
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(button.attributes('aria-label')).toBe(__('Collapse'));
|
2022-03-02 08:16:31 +05:30
|
|
|
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']);
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(folderName.classes('gl-font-weight-bold')).toBe(true);
|
|
|
|
expect(link.attributes('href')).toBe(nestedEnvironment.latest.folderPath);
|
|
|
|
});
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
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-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
});
|