diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 21:08:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 21:08:06 +0300 |
commit | 30b17460a2569734cf04dae1b2841d3654b2c0ec (patch) | |
tree | 86eb199f8a21eadeff824b26a8736986266a9a31 /spec/frontend | |
parent | 87f286558de1f5790b0b1742f10548387b5d147a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
8 files changed, 146 insertions, 44 deletions
diff --git a/spec/frontend/.eslintrc.yml b/spec/frontend/.eslintrc.yml index c8aacca5ef2..8e6faa90c58 100644 --- a/spec/frontend/.eslintrc.yml +++ b/spec/frontend/.eslintrc.yml @@ -1,10 +1,6 @@ --- -env: - jest/globals: true -plugins: - - jest extends: - - 'plugin:jest/recommended' + - 'plugin:@gitlab/jest' settings: # We have to teach eslint-plugin-import what node modules we use # otherwise there is an error when it tries to resolve them @@ -20,3 +16,12 @@ globals: loadFixtures: false preloadFixtures: false setFixtures: false +rules: + jest/expect-expect: + - off + - assertFunctionNames: + - 'expect*' + - 'assert*' + - 'testAction' + jest/no-test-callback: + - off diff --git a/spec/frontend/diff_comments_store_spec.js b/spec/frontend/diff_comments_store_spec.js index 82588b1ee7b..6f25c9dd3bc 100644 --- a/spec/frontend/diff_comments_store_spec.js +++ b/spec/frontend/diff_comments_store_spec.js @@ -41,7 +41,6 @@ describe('New discussion', () => { describe('Get note', () => { beforeEach(() => { - expect(Object.keys(CommentsStore.state).length).toBe(0); createDiscussion(); }); @@ -55,7 +54,6 @@ describe('Get note', () => { describe('Delete discussion', () => { beforeEach(() => { - expect(Object.keys(CommentsStore.state).length).toBe(0); createDiscussion(); }); @@ -81,7 +79,6 @@ describe('Delete discussion', () => { describe('Update note', () => { beforeEach(() => { - expect(Object.keys(CommentsStore.state).length).toBe(0); createDiscussion(); }); @@ -96,7 +93,6 @@ describe('Update note', () => { describe('Discussion resolved', () => { beforeEach(() => { - expect(Object.keys(CommentsStore.state).length).toBe(0); createDiscussion(); }); diff --git a/spec/frontend/helpers/class_spec_helper.js b/spec/frontend/helpers/class_spec_helper.js index 7a60d33b471..b26f087f0c5 100644 --- a/spec/frontend/helpers/class_spec_helper.js +++ b/spec/frontend/helpers/class_spec_helper.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line jest/no-export export default class ClassSpecHelper { static itShouldBeAStaticMethod(base, method) { return it('should be a static method', () => { diff --git a/spec/frontend/lib/utils/axios_utils_spec.js b/spec/frontend/lib/utils/axios_utils_spec.js index d5c39567f06..1585a38ae86 100644 --- a/spec/frontend/lib/utils/axios_utils_spec.js +++ b/spec/frontend/lib/utils/axios_utils_spec.js @@ -11,6 +11,7 @@ describe('axios_utils', () => { mock = new AxiosMockAdapter(axios); mock.onAny('/ok').reply(200); mock.onAny('/err').reply(500); + // eslint-disable-next-line jest/no-standalone-expect expect(axios.countActiveRequests()).toBe(0); }); diff --git a/spec/frontend/releases/components/release_block_footer_spec.js b/spec/frontend/releases/components/release_block_footer_spec.js index c63637c4cae..b91cfb82b65 100644 --- a/spec/frontend/releases/components/release_block_footer_spec.js +++ b/spec/frontend/releases/components/release_block_footer_spec.js @@ -3,13 +3,17 @@ import { GlLink } from '@gitlab/ui'; import { trimText } from 'helpers/text_helper'; import ReleaseBlockFooter from '~/releases/components/release_block_footer.vue'; import Icon from '~/vue_shared/components/icon.vue'; -import { release } from '../mock_data'; +import { release as originalRelease } from '../mock_data'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { cloneDeep } from 'lodash'; + +const mockFutureDate = new Date(9999, 0, 0).toISOString(); +let mockIsFutureRelease = false; jest.mock('~/vue_shared/mixins/timeago', () => ({ methods: { timeFormatted() { - return '7 fortnights ago'; + return mockIsFutureRelease ? 'in 1 month' : '7 fortnights ago'; }, tooltipTitle() { return 'February 30, 2401'; @@ -19,12 +23,12 @@ jest.mock('~/vue_shared/mixins/timeago', () => ({ describe('Release block footer', () => { let wrapper; - let releaseClone; + let release; const factory = (props = {}) => { wrapper = mount(ReleaseBlockFooter, { propsData: { - ...convertObjectPropsToCamelCase(releaseClone, { deep: true }), + ...convertObjectPropsToCamelCase(release, { deep: true }), ...props, }, }); @@ -33,11 +37,13 @@ describe('Release block footer', () => { }; beforeEach(() => { - releaseClone = JSON.parse(JSON.stringify(release)); + release = cloneDeep(originalRelease); }); afterEach(() => { wrapper.destroy(); + wrapper = null; + mockIsFutureRelease = false; }); const commitInfoSection = () => wrapper.find('.js-commit-info'); @@ -60,8 +66,8 @@ describe('Release block footer', () => { const commitLink = commitInfoSectionLink(); expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(releaseClone.commit.short_id); - expect(commitLink.attributes('href')).toBe(releaseClone.commit_path); + expect(commitLink.text()).toBe(release.commit.short_id); + expect(commitLink.attributes('href')).toBe(release.commit_path); }); it('renders the tag icon', () => { @@ -75,28 +81,60 @@ describe('Release block footer', () => { const commitLink = tagInfoSection().find(GlLink); expect(commitLink.exists()).toBe(true); - expect(commitLink.text()).toBe(releaseClone.tag_name); - expect(commitLink.attributes('href')).toBe(releaseClone.tag_path); + expect(commitLink.text()).toBe(release.tag_name); + expect(commitLink.attributes('href')).toBe(release.tag_path); }); it('renders the author and creation time info', () => { expect(trimText(authorDateInfoSection().text())).toBe( - `Created 7 fortnights ago by ${releaseClone.author.username}`, + `Created 7 fortnights 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(() => { + mockIsFutureRelease = true; + 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(() => { + mockIsFutureRelease = true; + 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(releaseClone.author.avatar_url); + expect(avatarImg.attributes('src')).toBe(release.author.avatar_url); }); it("renders a link to the author's profile", () => { const authorLink = authorDateInfoSection().find(GlLink); expect(authorLink.exists()).toBe(true); - expect(authorLink.attributes('href')).toBe(releaseClone.author.web_url); + expect(authorLink.attributes('href')).toBe(release.author.web_url); }); }); @@ -113,7 +151,7 @@ describe('Release block footer', () => { it('renders the commit SHA as plain text (instead of a link)', () => { expect(commitInfoSectionLink().exists()).toBe(false); - expect(commitInfoSection().text()).toBe(releaseClone.commit.short_id); + expect(commitInfoSection().text()).toBe(release.commit.short_id); }); }); @@ -130,7 +168,7 @@ describe('Release block footer', () => { it('renders the tag name as plain text (instead of a link)', () => { expect(tagInfoSectionLink().exists()).toBe(false); - expect(tagInfoSection().text()).toBe(releaseClone.tag_name); + expect(tagInfoSection().text()).toBe(release.tag_name); }); }); @@ -138,7 +176,18 @@ describe('Release block footer', () => { beforeEach(() => factory({ author: undefined })); it('renders the release date without the author name', () => { - expect(trimText(authorDateInfoSection().text())).toBe('Created 7 fortnights ago'); + expect(trimText(authorDateInfoSection().text())).toBe(`Created 7 fortnights ago`); + }); + }); + + describe('future release without any author info', () => { + beforeEach(() => { + mockIsFutureRelease = true; + 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`); }); }); @@ -147,7 +196,7 @@ describe('Release block footer', () => { it('renders the author name without the release date', () => { expect(trimText(authorDateInfoSection().text())).toBe( - `Created by ${releaseClone.author.username}`, + `Created by ${release.author.username}`, ); }); }); diff --git a/spec/frontend/releases/components/release_block_metadata_spec.js b/spec/frontend/releases/components/release_block_metadata_spec.js new file mode 100644 index 00000000000..cbe478bfa1f --- /dev/null +++ b/spec/frontend/releases/components/release_block_metadata_spec.js @@ -0,0 +1,67 @@ +import { mount } from '@vue/test-utils'; +import { trimText } from 'helpers/text_helper'; +import ReleaseBlockMetadata from '~/releases/components/release_block_metadata.vue'; +import { release as originalRelease } from '../mock_data'; +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { cloneDeep } from 'lodash'; + +const mockFutureDate = new Date(9999, 0, 0).toISOString(); +let mockIsFutureRelease = false; + +jest.mock('~/vue_shared/mixins/timeago', () => ({ + methods: { + timeFormatted() { + return mockIsFutureRelease ? 'in 1 month' : '7 fortnights ago'; + }, + tooltipTitle() { + return 'February 30, 2401'; + }, + }, +})); + +describe('Release block metadata', () => { + let wrapper; + let release; + + const factory = (releaseUpdates = {}) => { + wrapper = mount(ReleaseBlockMetadata, { + propsData: { + release: { + ...convertObjectPropsToCamelCase(release, { deep: true }), + ...releaseUpdates, + }, + }, + }); + }; + + beforeEach(() => { + release = cloneDeep(originalRelease); + }); + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + mockIsFutureRelease = false; + }); + + const findReleaseDateInfo = () => wrapper.find('.js-release-date-info'); + + describe('with all props provided', () => { + beforeEach(() => factory()); + + it('renders the release time info', () => { + expect(trimText(findReleaseDateInfo().text())).toBe(`released 7 fortnights ago`); + }); + }); + + describe('with a future release date', () => { + beforeEach(() => { + mockIsFutureRelease = true; + factory({ releasedAt: mockFutureDate }); + }); + + it('renders the release date without the author name', () => { + expect(trimText(findReleaseDateInfo().text())).toBe(`will be released in 1 month`); + }); + }); +}); diff --git a/spec/frontend/releases/stores/modules/detail/mutations_spec.js b/spec/frontend/releases/stores/modules/detail/mutations_spec.js index 9d4f78be327..155390c2cee 100644 --- a/spec/frontend/releases/stores/modules/detail/mutations_spec.js +++ b/spec/frontend/releases/stores/modules/detail/mutations_spec.js @@ -20,7 +20,6 @@ describe('Release detail mutations', () => { release = convertObjectPropsToCamelCase(originalRelease); }); - // eslint-disable-next-line jest/valid-describe describe(types.REQUEST_RELEASE, () => { it('set state.isFetchingRelease to true', () => { mutations[types.REQUEST_RELEASE](state); @@ -29,7 +28,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.RECEIVE_RELEASE_SUCCESS, () => { it('handles a successful response from the server', () => { mutations[types.RECEIVE_RELEASE_SUCCESS](state, release); @@ -44,7 +42,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.RECEIVE_RELEASE_ERROR, () => { it('handles an unsuccessful response from the server', () => { const error = { message: 'An error occurred!' }; @@ -58,7 +55,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.UPDATE_RELEASE_TITLE, () => { it("updates the release's title", () => { state.release = release; @@ -69,7 +65,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.UPDATE_RELEASE_NOTES, () => { it("updates the release's notes", () => { state.release = release; @@ -80,7 +75,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.REQUEST_UPDATE_RELEASE, () => { it('set state.isUpdatingRelease to true', () => { mutations[types.REQUEST_UPDATE_RELEASE](state); @@ -89,7 +83,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.RECEIVE_UPDATE_RELEASE_SUCCESS, () => { it('handles a successful response from the server', () => { mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](state, release); @@ -100,7 +93,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.RECEIVE_UPDATE_RELEASE_ERROR, () => { it('handles an unsuccessful response from the server', () => { const error = { message: 'An error occurred!' }; @@ -112,7 +104,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.ADD_EMPTY_ASSET_LINK, () => { it('adds a new, empty link object to the release', () => { state.release = release; @@ -132,7 +123,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.UPDATE_ASSET_LINK_URL, () => { it('updates an asset link with a new URL', () => { state.release = release; @@ -148,7 +138,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.UPDATE_ASSET_LINK_NAME, () => { it('updates an asset link with a new name', () => { state.release = release; @@ -164,7 +153,6 @@ describe('Release detail mutations', () => { }); }); - // eslint-disable-next-line jest/valid-describe describe(types.REMOVE_ASSET_LINK, () => { it('removes an asset link from the release', () => { state.release = release; diff --git a/spec/frontend/vue_shared/components/date_time_picker/date_time_picker_lib_spec.js b/spec/frontend/vue_shared/components/date_time_picker/date_time_picker_lib_spec.js index 3a75ab2d127..98962918b49 100644 --- a/spec/frontend/vue_shared/components/date_time_picker/date_time_picker_lib_spec.js +++ b/spec/frontend/vue_shared/components/date_time_picker/date_time_picker_lib_spec.js @@ -56,13 +56,8 @@ describe('date time picker lib', () => { describe('stringToISODate', () => { ['', 'null', undefined, 'abc'].forEach(input => { - it(`throws error for invalid input like ${input}`, done => { - try { - dateTimePickerLib.stringToISODate(input); - } catch (e) { - expect(e).toBeDefined(); - done(); - } + it(`throws error for invalid input like ${input}`, () => { + expect(() => dateTimePickerLib.stringToISODate(input)).toThrow(); }); }); [ |