diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-08 15:08:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-08 15:08:21 +0000 |
commit | 1bdb3fe3821fc3d222361d8b2e2ec2fea2915372 (patch) | |
tree | c2566a9cb9d3328bff5d816278112c97be4179fe /spec | |
parent | 996d54a81d799e6a69098b1e397a4ee7ea6d200c (diff) | |
download | gitlab-ce-1bdb3fe3821fc3d222361d8b2e2ec2fea2915372.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/registry/explorer/components/project_policy_alert_spec.js | 132 | ||||
-rw-r--r-- | spec/frontend/registry/explorer/stores/mutations_spec.js | 7 |
2 files changed, 137 insertions, 2 deletions
diff --git a/spec/frontend/registry/explorer/components/project_policy_alert_spec.js b/spec/frontend/registry/explorer/components/project_policy_alert_spec.js new file mode 100644 index 00000000000..89c37e55398 --- /dev/null +++ b/spec/frontend/registry/explorer/components/project_policy_alert_spec.js @@ -0,0 +1,132 @@ +import Vuex from 'vuex'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; +import { GlSprintf, GlAlert, GlLink } from '@gitlab/ui'; +import * as dateTimeUtils from '~/lib/utils/datetime_utility'; +import component from '~/registry/explorer/components/project_policy_alert.vue'; +import { + EXPIRATION_POLICY_ALERT_TITLE, + EXPIRATION_POLICY_ALERT_PRIMARY_BUTTON, +} from '~/registry/explorer/constants'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('Project Policy Alert', () => { + let wrapper; + let store; + + const defaultState = { + config: { + expirationPolicy: { + enabled: true, + }, + settingsPath: 'foo', + expirationPolicyHelpPagePath: 'bar', + }, + images: [], + isLoading: false, + }; + + const findAlert = () => wrapper.find(GlAlert); + const findLink = () => wrapper.find(GlLink); + + const createComponent = (state = defaultState) => { + store = new Vuex.Store({ + state, + }); + wrapper = shallowMount(component, { + localVue, + store, + stubs: { + GlSprintf, + }, + }); + }; + + const documentationExpectation = () => { + it('contain a documentation link', () => { + createComponent(); + expect(findLink().attributes('href')).toBe(defaultState.config.expirationPolicyHelpPagePath); + expect(findLink().text()).toBe('documentation'); + }); + }; + + beforeEach(() => { + jest.spyOn(dateTimeUtils, 'approximateDuration').mockReturnValue('1 day'); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('is hidden', () => { + it('when expiration policy does not exist', () => { + createComponent({ config: {} }); + expect(findAlert().exists()).toBe(false); + }); + + it('when expiration policy exist but is disabled', () => { + createComponent({ + ...defaultState, + config: { + expirationPolicy: { + enabled: false, + }, + }, + }); + expect(findAlert().exists()).toBe(false); + }); + }); + + describe('is visible', () => { + it('when expiration policy exists and is enabled', () => { + createComponent(); + expect(findAlert().exists()).toBe(true); + }); + }); + + describe('full info alert', () => { + beforeEach(() => { + createComponent({ ...defaultState, images: [1] }); + }); + + it('has a primary button', () => { + const alert = findAlert(); + expect(alert.props('primaryButtonText')).toBe(EXPIRATION_POLICY_ALERT_PRIMARY_BUTTON); + expect(alert.props('primaryButtonLink')).toBe(defaultState.config.settingsPath); + }); + + it('has a title', () => { + const alert = findAlert(); + expect(alert.props('title')).toBe(EXPIRATION_POLICY_ALERT_TITLE); + }); + + it('has the full message', () => { + expect(findAlert().html()).toContain('<strong>1 day</strong>'); + }); + + documentationExpectation(); + }); + + describe('compact info alert', () => { + beforeEach(() => { + createComponent({ ...defaultState, images: [] }); + }); + + it('does not have a button', () => { + const alert = findAlert(); + expect(alert.props('primaryButtonText')).toBe(null); + }); + + it('does not have a title', () => { + const alert = findAlert(); + expect(alert.props('title')).toBe(null); + }); + + it('has the short message', () => { + expect(findAlert().html()).not.toContain('<strong>1 day</strong>'); + }); + + documentationExpectation(); + }); +}); diff --git a/spec/frontend/registry/explorer/stores/mutations_spec.js b/spec/frontend/registry/explorer/stores/mutations_spec.js index 43f6a95db10..1d5055c02d2 100644 --- a/spec/frontend/registry/explorer/stores/mutations_spec.js +++ b/spec/frontend/registry/explorer/stores/mutations_spec.js @@ -10,9 +10,12 @@ describe('Mutations Registry Explorer Store', () => { describe('SET_INITIAL_STATE', () => { it('should set the initial state', () => { - const payload = { endpoint: 'foo', isGroupPage: true }; + const payload = { endpoint: 'foo', isGroupPage: true, expirationPolicy: { foo: 'bar' } }; const expectedState = { ...mockState, config: payload }; - mutations[types.SET_INITIAL_STATE](mockState, payload); + mutations[types.SET_INITIAL_STATE](mockState, { + ...payload, + expirationPolicy: JSON.stringify(payload.expirationPolicy), + }); expect(mockState).toEqual(expectedState); }); |