2021-04-17 20:07:23 +05:30
|
|
|
import { GlTab } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import Vue from 'vue';
|
2020-11-24 15:15:51 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
2020-11-24 15:15:51 +05:30
|
|
|
import RepoTab from '~/ide/components/repo_tab.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/ide/stores';
|
2023-07-09 08:55:56 +05:30
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { file } from '../helpers';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const GlTabStub = stubComponent(GlTab, {
|
|
|
|
template: '<li><slot name="title" /></li>',
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
describe('RepoTab', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
let wrapper;
|
2020-06-23 00:09:42 +05:30
|
|
|
let store;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
const pushMock = jest.fn();
|
2022-08-27 11:52:29 +05:30
|
|
|
const findTab = () => wrapper.findComponent(GlTabStub);
|
2023-07-09 08:55:56 +05:30
|
|
|
const findCloseButton = () => wrapper.findByTestId('close-button');
|
2021-04-17 20:07:23 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
function createComponent(propsData) {
|
2023-07-09 08:55:56 +05:30
|
|
|
wrapper = mountExtended(RepoTab, {
|
2018-05-09 12:01:36 +05:30
|
|
|
store,
|
|
|
|
propsData,
|
2021-04-17 20:07:23 +05:30
|
|
|
stubs: {
|
|
|
|
GlTab: GlTabStub,
|
|
|
|
},
|
2023-07-09 08:55:56 +05:30
|
|
|
mocks: {
|
|
|
|
$router: {
|
|
|
|
push: pushMock,
|
|
|
|
},
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
store = createStore();
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a close link and a name link', () => {
|
2023-07-09 08:55:56 +05:30
|
|
|
const tab = file();
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
2023-07-09 08:55:56 +05:30
|
|
|
tab,
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
store.state.openFiles.push(tab);
|
2020-11-24 15:15:51 +05:30
|
|
|
const name = wrapper.find(`[title]`);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(findCloseButton().html()).toContain('#close');
|
|
|
|
expect(name.text()).toBe(tab.name);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('does not call openPendingTab when tab is active', async () => {
|
|
|
|
createComponent({
|
2018-11-08 19:23:39 +05:30
|
|
|
tab: {
|
|
|
|
...file(),
|
|
|
|
pending: true,
|
|
|
|
active: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
jest.spyOn(store, 'dispatch');
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
await findTab().vm.$emit('click');
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(store.dispatch).not.toHaveBeenCalledWith('openPendingTab');
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
it('fires clickFile when the link is clicked', async () => {
|
|
|
|
const { getters } = store;
|
|
|
|
const tab = file();
|
|
|
|
createComponent({ tab });
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
await findTab().vm.$emit('click', tab);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(pushMock).toHaveBeenCalledWith(getters.getUrlForPath(tab.path));
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
it('calls closeFile when clicking close button', async () => {
|
|
|
|
const tab = file();
|
|
|
|
createComponent({ tab });
|
|
|
|
store.state.entries[tab.path] = tab;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
jest.spyOn(store, 'dispatch');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
await findCloseButton().trigger('click');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('closeFile', tab);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('changes icon on hover', async () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const tab = file();
|
|
|
|
tab.changed = true;
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
2018-05-09 12:01:36 +05:30
|
|
|
tab,
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
await findTab().vm.$emit('mouseover');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find('.file-modified').exists()).toBe(false);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
await findTab().vm.$emit('mouseout');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find('.file-modified').exists()).toBe(true);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it.each`
|
|
|
|
tabProps | closeLabel
|
|
|
|
${{}} | ${'Close foo.txt'}
|
|
|
|
${{ changed: true }} | ${'foo.txt changed'}
|
|
|
|
`('close button has label ($closeLabel) with tab ($tabProps)', ({ tabProps, closeLabel }) => {
|
|
|
|
const tab = { ...file('foo.txt'), ...tabProps };
|
|
|
|
|
|
|
|
createComponent({ tab });
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(findCloseButton().attributes('aria-label')).toBe(closeLabel);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
describe('locked file', () => {
|
|
|
|
let f;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
f = file('locked file');
|
|
|
|
f.file_lock = {
|
|
|
|
user: {
|
|
|
|
name: 'testuser',
|
|
|
|
updated_at: new Date(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
2018-05-09 12:01:36 +05:30
|
|
|
tab: f,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders lock icon', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find('.file-status-icon')).not.toBeNull();
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a tooltip', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(wrapper.find('span:nth-child(2)').attributes('title')).toBe('Locked by testuser');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('closeTab', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
it('closes tab if file has changed', async () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const tab = file();
|
|
|
|
tab.changed = true;
|
|
|
|
tab.opened = true;
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
2018-05-09 12:01:36 +05:30
|
|
|
tab,
|
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
store.state.openFiles.push(tab);
|
|
|
|
store.state.changedFiles.push(tab);
|
|
|
|
store.state.entries[tab.path] = tab;
|
|
|
|
store.dispatch('setFileActive', tab.path);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
await findCloseButton().trigger('click');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(tab.opened).toBe(false);
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(store.state.changedFiles).toHaveLength(1);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('closes tab when clicking close btn', async () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const tab = file('lose');
|
|
|
|
tab.opened = true;
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
2018-05-09 12:01:36 +05:30
|
|
|
tab,
|
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
store.state.openFiles.push(tab);
|
|
|
|
store.state.entries[tab.path] = tab;
|
|
|
|
store.dispatch('setFileActive', tab.path);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
await findCloseButton().trigger('click');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(tab.opened).toBe(false);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|