Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js34
-rw-r--r--spec/frontend/diffs/components/tree_list_spec.js138
2 files changed, 166 insertions, 6 deletions
diff --git a/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js b/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
index 0170ef927cf..2c7891e4b1a 100644
--- a/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
+++ b/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
@@ -1,18 +1,25 @@
import { shallowMount } from '@vue/test-utils';
import Popover from '~/blob/suggest_gitlab_ci_yml/components/popover.vue';
import Cookies from 'js-cookie';
+import * as utils from '~/lib/utils/common_utils';
-const popoverTarget = 'gitlab-ci-yml-selector';
+jest.mock('~/lib/utils/common_utils', () => ({
+ ...jest.requireActual('~/lib/utils/common_utils'),
+ scrollToElement: jest.fn(),
+}));
+
+const target = 'gitlab-ci-yml-selector';
const dismissKey = 'suggest_gitlab_ci_yml_99';
+const defaultTrackLabel = 'suggest_gitlab_ci_yml';
describe('Suggest gitlab-ci.yml Popover', () => {
let wrapper;
- function createWrapper() {
+ function createWrapper(trackLabel) {
wrapper = shallowMount(Popover, {
propsData: {
- target: popoverTarget,
- cssClass: 'js-class',
+ target,
+ trackLabel,
dismissKey,
},
});
@@ -25,7 +32,7 @@ describe('Suggest gitlab-ci.yml Popover', () => {
describe('when no dismiss cookie is set', () => {
beforeEach(() => {
- createWrapper();
+ createWrapper(defaultTrackLabel);
});
it('sets popoverDismissed to false', () => {
@@ -36,11 +43,26 @@ describe('Suggest gitlab-ci.yml Popover', () => {
describe('when the dismiss cookie is set', () => {
beforeEach(() => {
Cookies.set(dismissKey, true);
- createWrapper();
+ createWrapper(defaultTrackLabel);
});
it('sets popoverDismissed to true', () => {
expect(wrapper.vm.popoverDismissed).toEqual(true);
});
+
+ beforeEach(() => {
+ Cookies.remove(dismissKey);
+ });
+ });
+
+ describe('when the popover is mounted with the trackLabel of the Confirm button popover at the bottom of the page', () => {
+ it('calls scrollToElement so that the Confirm button and popover will be in sight', () => {
+ const scrollToElementSpy = jest.spyOn(utils, 'scrollToElement');
+ const commitTrackLabel = 'suggest_commit_first_project_gitlab_ci_yml';
+
+ createWrapper(commitTrackLabel);
+
+ expect(scrollToElementSpy).toHaveBeenCalled();
+ });
});
});
diff --git a/spec/frontend/diffs/components/tree_list_spec.js b/spec/frontend/diffs/components/tree_list_spec.js
new file mode 100644
index 00000000000..f78c5f25ee7
--- /dev/null
+++ b/spec/frontend/diffs/components/tree_list_spec.js
@@ -0,0 +1,138 @@
+import Vuex from 'vuex';
+import { mount, createLocalVue } from '@vue/test-utils';
+import TreeList from '~/diffs/components/tree_list.vue';
+import createStore from '~/diffs/store/modules';
+
+describe('Diffs tree list component', () => {
+ let wrapper;
+ const getFileRows = () => wrapper.findAll('.file-row');
+ const localVue = createLocalVue();
+ localVue.use(Vuex);
+
+ const createComponent = state => {
+ const store = new Vuex.Store({
+ modules: {
+ diffs: createStore(),
+ },
+ });
+
+ // Setup initial state
+ store.state.diffs.diffFiles.push('test');
+ store.state.diffs = {
+ addedLines: 10,
+ removedLines: 20,
+ ...store.state.diffs,
+ ...state,
+ };
+
+ wrapper = mount(TreeList, {
+ store,
+ localVue,
+ propsData: { hideFileStats: false },
+ });
+ };
+
+ beforeEach(() => {
+ localStorage.removeItem('mr_diff_tree_list');
+
+ createComponent();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ it('renders empty text', () => {
+ expect(wrapper.text()).toContain('No files found');
+ });
+
+ describe('with files', () => {
+ beforeEach(() => {
+ const treeEntries = {
+ 'index.js': {
+ addedLines: 0,
+ changed: true,
+ deleted: false,
+ fileHash: 'test',
+ key: 'index.js',
+ name: 'index.js',
+ path: 'app/index.js',
+ removedLines: 0,
+ tempFile: true,
+ type: 'blob',
+ parentPath: 'app',
+ },
+ app: {
+ key: 'app',
+ path: 'app',
+ name: 'app',
+ type: 'tree',
+ tree: [],
+ },
+ };
+
+ createComponent({
+ treeEntries,
+ tree: [treeEntries['index.js'], treeEntries.app],
+ });
+
+ return wrapper.vm.$nextTick();
+ });
+
+ it('renders tree', () => {
+ expect(getFileRows()).toHaveLength(2);
+ expect(
+ getFileRows()
+ .at(0)
+ .text(),
+ ).toContain('index.js');
+ expect(
+ getFileRows()
+ .at(1)
+ .text(),
+ ).toContain('app');
+ });
+
+ it('hides file stats', () => {
+ wrapper.setProps({ hideFileStats: true });
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.find('.file-row-stats').exists()).toBe(false);
+ });
+ });
+
+ it('calls toggleTreeOpen when clicking folder', () => {
+ jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(undefined);
+
+ getFileRows()
+ .at(1)
+ .trigger('click');
+
+ expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/toggleTreeOpen', 'app');
+ });
+
+ it('calls scrollToFile when clicking blob', () => {
+ jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(undefined);
+
+ wrapper.find('.file-row').trigger('click');
+
+ expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/scrollToFile', 'app/index.js');
+ });
+
+ it('renders as file list when renderTreeList is false', () => {
+ wrapper.vm.$store.state.diffs.renderTreeList = false;
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(getFileRows()).toHaveLength(1);
+ });
+ });
+
+ it('renders file paths when renderTreeList is false', () => {
+ wrapper.vm.$store.state.diffs.renderTreeList = false;
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.find('.file-row').text()).toContain('index.js');
+ });
+ });
+ });
+});