debian-mirror-gitlab/spec/frontend/import_entities/import_projects/components/provider_repo_table_row_spec.js

167 lines
4.6 KiB
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import { GlBadge, GlButton, GlDropdown } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import { nextTick } from 'vue';
2019-07-31 22:56:46 +05:30
import Vuex from 'vuex';
2021-02-22 17:27:13 +05:30
import { STATUSES } from '~/import_entities//constants';
2021-09-30 23:02:18 +05:30
import ImportGroupDropdown from '~/import_entities/components/group_dropdown.vue';
2021-03-11 19:13:27 +05:30
import ImportStatus from '~/import_entities/components/import_status.vue';
import ProviderRepoTableRow from '~/import_entities/import_projects/components/provider_repo_table_row.vue';
2019-07-07 11:18:12 +05:30
describe('ProviderRepoTableRow', () => {
2020-10-24 23:57:45 +05:30
let wrapper;
2020-06-23 00:09:42 +05:30
const fetchImport = jest.fn();
2020-10-24 23:57:45 +05:30
const setImportTarget = jest.fn();
const fakeImportTarget = {
targetNamespace: 'target',
newName: 'newName',
};
2019-07-07 11:18:12 +05:30
2021-09-30 23:02:18 +05:30
const availableNamespaces = ['test'];
const userNamespace = 'root';
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
function initStore(initialState) {
2019-07-31 22:56:46 +05:30
const store = new Vuex.Store({
2020-10-24 23:57:45 +05:30
state: initialState,
getters: {
getImportTarget: () => () => fakeImportTarget,
},
actions: { fetchImport, setImportTarget },
2019-07-31 22:56:46 +05:30
});
return store;
}
2020-11-24 15:15:51 +05:30
const findImportButton = () => {
2021-03-11 19:13:27 +05:30
const buttons = wrapper.findAllComponents(GlButton).filter((node) => node.text() === 'Import');
2020-11-24 15:15:51 +05:30
return buttons.length ? buttons.at(0) : buttons;
};
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
function mountComponent(props) {
2019-07-31 22:56:46 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
2020-11-24 15:15:51 +05:30
const store = initStore();
2019-07-31 22:56:46 +05:30
2020-10-24 23:57:45 +05:30
wrapper = shallowMount(ProviderRepoTableRow, {
2019-07-31 22:56:46 +05:30
localVue,
2019-07-07 11:18:12 +05:30
store,
2021-09-30 23:02:18 +05:30
propsData: { availableNamespaces, userNamespace, ...props },
2019-07-31 22:56:46 +05:30
});
2019-07-07 11:18:12 +05:30
}
afterEach(() => {
2020-10-24 23:57:45 +05:30
wrapper.destroy();
2020-11-24 15:15:51 +05:30
wrapper = null;
2019-07-07 11:18:12 +05:30
});
2020-11-24 15:15:51 +05:30
describe('when rendering importable project', () => {
const repo = {
importSource: {
id: 'remote-1',
fullName: 'fullName',
providerLink: 'providerLink',
},
};
beforeEach(() => {
mountComponent({ repo });
});
it('renders project information', () => {
const providerLink = wrapper.find('[data-testid=providerLink]');
expect(providerLink.attributes().href).toMatch(repo.importSource.providerLink);
expect(providerLink.text()).toMatch(repo.importSource.fullName);
});
it('renders empty import status', () => {
expect(wrapper.find(ImportStatus).props().status).toBe(STATUSES.NONE);
});
2021-09-30 23:02:18 +05:30
it('renders a group namespace select', () => {
expect(wrapper.find(ImportGroupDropdown).props().namespaces).toBe(availableNamespaces);
2020-11-24 15:15:51 +05:30
});
it('renders import button', () => {
expect(findImportButton().exists()).toBe(true);
});
it('imports repo when clicking import button', async () => {
2021-03-11 19:13:27 +05:30
findImportButton().vm.$emit('click');
2020-11-24 15:15:51 +05:30
await nextTick();
const { calls } = fetchImport.mock;
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
expect(calls).toHaveLength(1);
expect(calls[0][1]).toBe(repo.importSource.id);
});
2019-07-07 11:18:12 +05:30
});
2020-11-24 15:15:51 +05:30
describe('when rendering imported project', () => {
const repo = {
importSource: {
id: 'remote-1',
fullName: 'fullName',
providerLink: 'providerLink',
},
importedProject: {
id: 1,
fullPath: 'fullPath',
importSource: 'importSource',
importStatus: STATUSES.FINISHED,
},
};
beforeEach(() => {
mountComponent({ repo });
});
it('renders project information', () => {
const providerLink = wrapper.find('[data-testid=providerLink]');
expect(providerLink.attributes().href).toMatch(repo.importSource.providerLink);
expect(providerLink.text()).toMatch(repo.importSource.fullName);
});
it('renders proper import status', () => {
expect(wrapper.find(ImportStatus).props().status).toBe(repo.importedProject.importStatus);
});
it('does not renders a namespace select', () => {
2021-09-30 23:02:18 +05:30
expect(wrapper.find(GlDropdown).exists()).toBe(false);
2020-11-24 15:15:51 +05:30
});
it('does not render import button', () => {
expect(findImportButton().exists()).toBe(false);
});
2019-07-07 11:18:12 +05:30
});
2020-11-24 15:15:51 +05:30
describe('when rendering incompatible project', () => {
const repo = {
importSource: {
id: 'remote-1',
fullName: 'fullName',
providerLink: 'providerLink',
incompatible: true,
},
};
2019-07-07 11:18:12 +05:30
2020-11-24 15:15:51 +05:30
beforeEach(() => {
mountComponent({ repo });
});
it('renders project information', () => {
const providerLink = wrapper.find('[data-testid=providerLink]');
2019-07-31 22:56:46 +05:30
2020-11-24 15:15:51 +05:30
expect(providerLink.attributes().href).toMatch(repo.importSource.providerLink);
expect(providerLink.text()).toMatch(repo.importSource.fullName);
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
it('renders badge with error', () => {
expect(wrapper.find(GlBadge).text()).toBe('Incompatible project');
});
2019-07-07 11:18:12 +05:30
});
});