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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-24 21:10:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-24 21:10:53 +0300
commite9322e019bfeb7f33ce4c17662d93e6579303c2b (patch)
tree0c1dd4ac4e8f60164f7e21ba33bf0b1ee867c347 /spec/frontend
parent234dc40a12a1cdaef0cdb825ca4acc3f271c6394 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/groups/components/item_stats_spec.js30
-rw-r--r--spec/frontend/merge_request_tabs_spec.js82
2 files changed, 107 insertions, 5 deletions
diff --git a/spec/frontend/groups/components/item_stats_spec.js b/spec/frontend/groups/components/item_stats_spec.js
index f350012ebed..49f3f5da43c 100644
--- a/spec/frontend/groups/components/item_stats_spec.js
+++ b/spec/frontend/groups/components/item_stats_spec.js
@@ -1,4 +1,4 @@
-import { shallowMount } from '@vue/test-utils';
+import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ItemStats from '~/groups/components/item_stats.vue';
import ItemStatsValue from '~/groups/components/item_stats_value.vue';
@@ -12,7 +12,7 @@ describe('ItemStats', () => {
};
const createComponent = (props = {}) => {
- wrapper = shallowMount(ItemStats, {
+ wrapper = shallowMountExtended(ItemStats, {
propsData: { ...defaultProps, ...props },
});
};
@@ -46,5 +46,31 @@ describe('ItemStats', () => {
expect(findItemStatsValue().props('cssClass')).toBe('project-stars');
expect(wrapper.find('.last-updated').exists()).toBe(true);
});
+
+ describe('group specific rendering', () => {
+ describe.each`
+ provided | state | data
+ ${true} | ${'displays'} | ${null}
+ ${false} | ${'does not display'} | ${{ subgroupCount: undefined, projectCount: undefined }}
+ `('when provided = $provided', ({ provided, state, data }) => {
+ beforeEach(() => {
+ const item = {
+ ...mockParentGroupItem,
+ ...data,
+ type: ITEM_TYPE.GROUP,
+ };
+
+ createComponent({ item });
+ });
+
+ it.each`
+ entity | testId
+ ${'subgroups'} | ${'subgroups-count'}
+ ${'projects'} | ${'projects-count'}
+ `(`${state} $entity count`, ({ testId }) => {
+ expect(wrapper.findByTestId(testId).exists()).toBe(provided);
+ });
+ });
+ });
});
});
diff --git a/spec/frontend/merge_request_tabs_spec.js b/spec/frontend/merge_request_tabs_spec.js
index 23e9bf8b447..ced9b71125b 100644
--- a/spec/frontend/merge_request_tabs_spec.js
+++ b/spec/frontend/merge_request_tabs_spec.js
@@ -34,6 +34,44 @@ describe('MergeRequestTabs', () => {
gl.mrWidget = {};
});
+ describe('clickTab', () => {
+ let params;
+
+ beforeEach(() => {
+ document.documentElement.scrollTop = 100;
+
+ params = {
+ metaKey: false,
+ ctrlKey: false,
+ which: 1,
+ stopImmediatePropagation() {},
+ preventDefault() {},
+ currentTarget: {
+ getAttribute(attr) {
+ return attr === 'href' ? 'a/tab/url' : null;
+ },
+ },
+ };
+ });
+
+ it("stores the current scroll position if there's an active tab", () => {
+ testContext.class.currentTab = 'someTab';
+
+ testContext.class.clickTab(params);
+
+ expect(testContext.class.scrollPositions.someTab).toBe(100);
+ });
+
+ it("doesn't store a scroll position if there's no active tab", () => {
+ // this happens on first load, and we just don't want to store empty values in the `null` property
+ testContext.class.currentTab = null;
+
+ testContext.class.clickTab(params);
+
+ expect(testContext.class.scrollPositions).toEqual({});
+ });
+ });
+
describe('opensInNewTab', () => {
const windowTarget = '_blank';
let clickTabParams;
@@ -258,6 +296,7 @@ describe('MergeRequestTabs', () => {
beforeEach(() => {
jest.spyOn(mainContent, 'getBoundingClientRect').mockReturnValue({ top: 10 });
jest.spyOn(tabContent, 'getBoundingClientRect').mockReturnValue({ top: 100 });
+ jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
jest.spyOn(document, 'querySelector').mockImplementation((selector) => {
return selector === '.content-wrapper' ? mainContent : tabContent;
});
@@ -267,8 +306,6 @@ describe('MergeRequestTabs', () => {
it('calls window scrollTo with options if document has scrollBehavior', () => {
document.documentElement.style.scrollBehavior = '';
- jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
-
testContext.class.tabShown('commits', 'foobar');
expect(window.scrollTo.mock.calls[0][0]).toEqual({ top: 39, behavior: 'smooth' });
@@ -276,11 +313,50 @@ describe('MergeRequestTabs', () => {
it('calls window scrollTo with two args if document does not have scrollBehavior', () => {
jest.spyOn(document.documentElement, 'style', 'get').mockReturnValue({});
- jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
testContext.class.tabShown('commits', 'foobar');
expect(window.scrollTo.mock.calls[0]).toEqual([0, 39]);
});
+
+ describe('when switching tabs', () => {
+ const SCROLL_TOP = 100;
+
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+
+ beforeEach(() => {
+ jest.spyOn(window, 'scrollTo').mockImplementation(() => {});
+ testContext.class.mergeRequestTabs = document.createElement('div');
+ testContext.class.mergeRequestTabPanes = document.createElement('div');
+ testContext.class.currentTab = 'tab';
+ testContext.class.scrollPositions = { newTab: SCROLL_TOP };
+ });
+
+ afterAll(() => {
+ jest.useRealTimers();
+ });
+
+ it('scrolls to the stored position, if one is stored', () => {
+ testContext.class.tabShown('newTab');
+
+ jest.advanceTimersByTime(250);
+
+ expect(window.scrollTo.mock.calls[0][0]).toEqual({
+ top: SCROLL_TOP,
+ left: 0,
+ behavior: 'auto',
+ });
+ });
+
+ it('scrolls to 0, if no position is stored', () => {
+ testContext.class.tabShown('unknownTab');
+
+ jest.advanceTimersByTime(250);
+
+ expect(window.scrollTo.mock.calls[0][0]).toEqual({ top: 0, left: 0, behavior: 'auto' });
+ });
+ });
});
});