diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-04 15:06:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-04 15:06:14 +0300 |
commit | 0d46bf06388d485824bc2f1e736b92b2a8a397e4 (patch) | |
tree | 626a835841722463da4def7905b95e874eb77578 /spec/frontend | |
parent | 1f1bdf54e1974f89f3a6ba734ec2c42552e90639 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/releases/components/release_block_spec.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js index 5ce85a37121..1f5da093902 100644 --- a/spec/frontend/releases/components/release_block_spec.js +++ b/spec/frontend/releases/components/release_block_spec.js @@ -4,6 +4,18 @@ import timeagoMixin from '~/vue_shared/mixins/timeago'; import { first } from 'underscore'; import { release } from '../mock_data'; import Icon from '~/vue_shared/components/icon.vue'; +import { scrollToElement } from '~/lib/utils/common_utils'; + +let mockLocationHash; +jest.mock('~/lib/utils/url_utility', () => ({ + __esModule: true, + getLocationHash: jest.fn().mockImplementation(() => mockLocationHash), +})); + +jest.mock('~/lib/utils/common_utils', () => ({ + __esModule: true, + scrollToElement: jest.fn(), +})); describe('Release block', () => { let wrapper; @@ -159,4 +171,61 @@ describe('Release block', () => { expect(wrapper.text()).toContain('Upcoming Release'); }); + + it('slugifies the tag_name before setting it as the elements ID', () => { + const releaseClone = JSON.parse(JSON.stringify(release)); + releaseClone.tag_name = 'a dangerous tag name <script>alert("hello")</script>'; + + factory(releaseClone); + + expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script-'); + }); + + describe('anchor scrolling', () => { + beforeEach(() => { + scrollToElement.mockClear(); + }); + + const hasTargetBlueBackground = () => wrapper.classes('bg-line-target-blue'); + + it('does not attempt to scroll the page if no anchor tag is included in the URL', () => { + mockLocationHash = ''; + factory(release); + + expect(scrollToElement).not.toHaveBeenCalled(); + }); + + it("does not attempt to scroll the page if the anchor tag doesn't match the release's tag name", () => { + mockLocationHash = 'v0.4'; + factory(release); + + expect(scrollToElement).not.toHaveBeenCalled(); + }); + + it("attempts to scroll itself into view if the anchor tag matches the release's tag name", () => { + mockLocationHash = release.tag_name; + factory(release); + + expect(scrollToElement).toHaveBeenCalledTimes(1); + expect(scrollToElement).toHaveBeenCalledWith(wrapper.element); + }); + + it('renders with a light blue background if it is the target of the anchor', () => { + mockLocationHash = release.tag_name; + factory(release); + + return wrapper.vm.$nextTick().then(() => { + expect(hasTargetBlueBackground()).toBe(true); + }); + }); + + it('does not render with a light blue background if it is not the target of the anchor', () => { + mockLocationHash = ''; + factory(release); + + return wrapper.vm.$nextTick().then(() => { + expect(hasTargetBlueBackground()).toBe(false); + }); + }); + }); }); |