diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/frontend/releases/components | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/frontend/releases/components')
-rw-r--r-- | spec/frontend/releases/components/release_block_footer_spec.js | 231 | ||||
-rw-r--r-- | spec/frontend/releases/components/release_block_spec.js | 7 |
2 files changed, 117 insertions, 121 deletions
diff --git a/spec/frontend/releases/components/release_block_footer_spec.js b/spec/frontend/releases/components/release_block_footer_spec.js index 8f4efad197f..19b41d05a44 100644 --- a/spec/frontend/releases/components/release_block_footer_spec.js +++ b/spec/frontend/releases/components/release_block_footer_spec.js @@ -4,6 +4,7 @@ import { cloneDeep } from 'lodash'; import { nextTick } from 'vue'; import originalOneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json'; import { convertOneReleaseGraphQLResponse } from '~/releases/util'; +import { RELEASED_AT_ASC, RELEASED_AT_DESC, CREATED_ASC, CREATED_DESC } from '~/releases/constants'; import { trimText } from 'helpers/text_helper'; import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue'; @@ -43,88 +44,118 @@ describe('Release block footer', () => { const tagInfoSectionLink = () => tagInfoSection().findComponent(GlLink); const authorDateInfoSection = () => wrapper.find('.js-author-date-info'); - describe('with all props provided', () => { - beforeEach(() => factory()); - - it('renders the commit icon', () => { - const commitIcon = commitInfoSection().findComponent(GlIcon); - - expect(commitIcon.exists()).toBe(true); - expect(commitIcon.props('name')).toBe('commit'); - }); - - it('renders the commit SHA with a link', () => { - const commitLink = commitInfoSectionLink(); - - expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(release.commit.shortId); - expect(commitLink.attributes('href')).toBe(release.commitPath); - }); - - it('renders the tag icon', () => { - const commitIcon = tagInfoSection().findComponent(GlIcon); - - expect(commitIcon.exists()).toBe(true); - expect(commitIcon.props('name')).toBe('tag'); - }); - - it('renders the tag name with a link', () => { - const commitLink = tagInfoSection().findComponent(GlLink); - - expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(release.tagName); - expect(commitLink.attributes('href')).toBe(release.tagPath); - }); - - it('renders the author and creation time info', () => { - expect(trimText(authorDateInfoSection().text())).toBe( - `Created 1 year ago by ${release.author.username}`, - ); - }); - - describe('when the release date is in the past', () => { - it('prefixes the creation info with "Created"', () => { - expect(trimText(authorDateInfoSection().text())).toEqual(expect.stringMatching(/^Created/)); - }); - }); - - describe('renders the author and creation time info with future release date', () => { - beforeEach(() => { - factory({ releasedAt: mockFutureDate }); - }); - - it('renders the release date without the author name', () => { - expect(trimText(authorDateInfoSection().text())).toBe( - `Will be created in 1 month by ${release.author.username}`, - ); - }); - }); - - describe('when the release date is in the future', () => { - beforeEach(() => { - factory({ releasedAt: mockFutureDate }); - }); - - it('prefixes the creation info with "Will be created"', () => { - expect(trimText(authorDateInfoSection().text())).toEqual( - expect.stringMatching(/^Will be created/), - ); - }); - }); - - it("renders the author's avatar image", () => { - const avatarImg = authorDateInfoSection().find('img'); - - expect(avatarImg.exists()).toBe(true); - expect(avatarImg.attributes('src')).toBe(release.author.avatarUrl); - }); - - it("renders a link to the author's profile", () => { - const authorLink = authorDateInfoSection().findComponent(GlLink); - - expect(authorLink.exists()).toBe(true); - expect(authorLink.attributes('href')).toBe(release.author.webUrl); - }); + describe.each` + sortFlag | expectedInfoString + ${null} | ${'Created'} + ${CREATED_ASC} | ${'Created'} + ${CREATED_DESC} | ${'Created'} + ${RELEASED_AT_ASC} | ${'Released'} + ${RELEASED_AT_DESC} | ${'Released'} + `('with sorting set to $sortFlag', ({ sortFlag, expectedInfoString }) => { + const dateAt = + expectedInfoString === 'Created' ? originalRelease.createdAt : originalRelease.releasedAt; + + describe.each` + dateType | dateFlag | expectedInfoStringPrefix | expectedDateString + ${'empty'} | ${undefined} | ${null} | ${null} + ${'in the past'} | ${dateAt} | ${null} | ${'1 year ago'} + ${'in the future'} | ${mockFutureDate} | ${'Will be'} | ${'in 1 month'} + `( + 'with date set to $dateType', + ({ dateFlag, expectedInfoStringPrefix, expectedDateString }) => { + describe.each` + authorType | authorFlag | expectedAuthorString + ${'empty'} | ${undefined} | ${null} + ${'present'} | ${originalRelease.author} | ${'by user1'} + `('with author set to $authorType', ({ authorFlag, expectedAuthorString }) => { + const propsData = { sort: sortFlag, author: authorFlag }; + if (dateFlag !== '') { + propsData.createdAt = dateFlag; + propsData.releasedAt = dateFlag; + } + + beforeEach(() => { + factory({ ...propsData }); + }); + + const expectedString = [ + expectedInfoStringPrefix, + expectedInfoStringPrefix ? expectedInfoString.toLowerCase() : expectedInfoString, + expectedDateString, + expectedAuthorString, + ]; + + if (authorFlag || dateFlag) { + it('renders the author and creation time info', () => { + expect(trimText(authorDateInfoSection().text())).toBe( + expectedString.filter((n) => n).join(' '), + ); + }); + if (authorFlag) { + it("renders the author's avatar image", () => { + const avatarImg = authorDateInfoSection().find('img'); + + expect(avatarImg.exists()).toBe(true); + expect(avatarImg.attributes('src')).toBe(release.author.avatarUrl); + }); + + it("renders a link to the author's profile", () => { + const authorLink = authorDateInfoSection().findComponent(GlLink); + + expect(authorLink.exists()).toBe(true); + expect(authorLink.attributes('href')).toBe(release.author.webUrl); + }); + } else { + it("does not render the author's avatar image", () => { + const avatarImg = authorDateInfoSection().find('img'); + + expect(avatarImg.exists()).toBe(false); + }); + + it("does not render a link to the author's profile", () => { + const authorLink = authorDateInfoSection().findComponent(GlLink); + + expect(authorLink.exists()).toBe(false); + }); + } + } else { + it('does not render the author and creation time info', () => { + expect(authorDateInfoSection().exists()).toBe(false); + }); + } + + it('renders the commit icon', () => { + const commitIcon = commitInfoSection().findComponent(GlIcon); + + expect(commitIcon.exists()).toBe(true); + expect(commitIcon.props('name')).toBe('commit'); + }); + + it('renders the commit SHA with a link', () => { + const commitLink = commitInfoSectionLink(); + + expect(commitLink.exists()).toBe(true); + expect(commitLink.text()).toBe(release.commit.shortId); + expect(commitLink.attributes('href')).toBe(release.commitPath); + }); + + it('renders the tag icon', () => { + const commitIcon = tagInfoSection().findComponent(GlIcon); + + expect(commitIcon.exists()).toBe(true); + expect(commitIcon.props('name')).toBe('tag'); + }); + + it('renders the tag name with a link', () => { + const commitLink = tagInfoSection().findComponent(GlLink); + + expect(commitLink.exists()).toBe(true); + expect(commitLink.text()).toBe(release.tagName); + expect(commitLink.attributes('href')).toBe(release.tagPath); + }); + }); + }, + ); }); describe('without any commit info', () => { @@ -160,40 +191,4 @@ describe('Release block footer', () => { expect(tagInfoSection().text()).toBe(release.tagName); }); }); - - describe('without any author info', () => { - beforeEach(() => factory({ author: undefined })); - - it('renders the release date without the author name', () => { - expect(trimText(authorDateInfoSection().text())).toBe(`Created 1 year ago`); - }); - }); - - describe('future release without any author info', () => { - beforeEach(() => { - factory({ author: undefined, releasedAt: mockFutureDate }); - }); - - it('renders the release date without the author name', () => { - expect(trimText(authorDateInfoSection().text())).toBe(`Will be created in 1 month`); - }); - }); - - describe('without a released at date', () => { - beforeEach(() => factory({ releasedAt: undefined })); - - it('renders the author name without the release date', () => { - expect(trimText(authorDateInfoSection().text())).toBe( - `Created by ${release.author.username}`, - ); - }); - }); - - describe('without a release date or author info', () => { - beforeEach(() => factory({ author: undefined, releasedAt: undefined })); - - it('does not render any author or release date info', () => { - expect(authorDateInfoSection().exists()).toBe(false); - }); - }); }); diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js index 096c3db8902..f1b8554fbc3 100644 --- a/spec/frontend/releases/components/release_block_spec.js +++ b/spec/frontend/releases/components/release_block_spec.js @@ -1,5 +1,4 @@ import { mount } from '@vue/test-utils'; -import $ from 'jquery'; import { nextTick } from 'vue'; import originalOneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json'; import { convertOneReleaseGraphQLResponse } from '~/releases/util'; @@ -10,6 +9,9 @@ import ReleaseBlock from '~/releases/components/release_block.vue'; import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue'; import { BACK_URL_PARAM } from '~/releases/constants'; import timeagoMixin from '~/vue_shared/mixins/timeago'; +import { renderGFM } from '~/behaviors/markdown/render_gfm'; + +jest.mock('~/behaviors/markdown/render_gfm'); describe('Release block', () => { let wrapper; @@ -34,7 +36,6 @@ describe('Release block', () => { const editButton = () => wrapper.find('.js-edit-button'); beforeEach(() => { - jest.spyOn($.fn, 'renderGFM'); release = convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse).data; }); @@ -62,7 +63,7 @@ describe('Release block', () => { it('renders release description', () => { expect(wrapper.vm.$refs['gfm-content']).toBeDefined(); - expect($.fn.renderGFM).toHaveBeenCalledTimes(1); + expect(renderGFM).toHaveBeenCalledTimes(1); }); it('renders release date', () => { |