diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 00:08:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 00:08:11 +0000 |
commit | 93dcf45d441bc884b167f4338380c8c888e9b86f (patch) | |
tree | f55e8c1d39013380d1ff7d2a4e3cca537a35192a /spec/frontend | |
parent | 0e68afab211a172b862a7acc774e1eda5da8e471 (diff) | |
download | gitlab-ce-93dcf45d441bc884b167f4338380c8c888e9b86f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap | 2 | ||||
-rw-r--r-- | spec/frontend/prometheus_alerts/components/reset_key_spec.js | 105 |
2 files changed, 107 insertions, 0 deletions
diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap index b8bda533072..c61ac0fb175 100644 --- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap +++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap @@ -19,6 +19,7 @@ exports[`Dashboard template matches the default snapshot 1`] = ` > <dashboards-dropdown-stub class="mb-0 d-flex" + data-qa-selector="dashboards_filter_dropdown" defaultbranch="master" id="monitor-dashboards-dropdown" selecteddashboard="[object Object]" @@ -74,6 +75,7 @@ exports[`Dashboard template matches the default snapshot 1`] = ` <gl-form-group-stub class="col-sm-auto col-md-auto col-lg-auto" + data-qa-selector="show_last_dropdown" label="Show last" label-for="monitor-time-window-dropdown" label-size="sm" diff --git a/spec/frontend/prometheus_alerts/components/reset_key_spec.js b/spec/frontend/prometheus_alerts/components/reset_key_spec.js new file mode 100644 index 00000000000..df52baafa29 --- /dev/null +++ b/spec/frontend/prometheus_alerts/components/reset_key_spec.js @@ -0,0 +1,105 @@ +import { shallowMount } from '@vue/test-utils'; +import MockAdapter from 'axios-mock-adapter'; +import ResetKey from '~/prometheus_alerts/components/reset_key.vue'; +import { GlModal } from '@gitlab/ui'; +import waitForPromises from 'helpers/wait_for_promises'; +import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; +import axios from '~/lib/utils/axios_utils'; + +describe('ResetKey', () => { + let mock; + let vm; + + const propsData = { + initialAuthorizationKey: 'abcd1234', + changeKeyUrl: '/updateKeyUrl', + notifyUrl: '/root/autodevops-deploy/prometheus/alerts/notify.json', + learnMoreUrl: '/learnMore', + }; + + beforeEach(() => { + mock = new MockAdapter(axios); + setFixtures('<div class="flash-container"></div><div id="reset-key"></div>'); + }); + + afterEach(() => { + mock.restore(); + vm.destroy(); + }); + + describe('authorization key exists', () => { + beforeEach(() => { + propsData.initialAuthorizationKey = 'abcd1234'; + vm = shallowMount(ResetKey, { + propsData, + }); + }); + + it('shows fields and buttons', () => { + expect(vm.find('#notify-url').attributes('value')).toEqual(propsData.notifyUrl); + expect(vm.find('#authorization-key').attributes('value')).toEqual( + propsData.initialAuthorizationKey, + ); + + expect(vm.findAll(ClipboardButton).length).toBe(2); + expect(vm.find('.js-reset-auth-key').text()).toEqual('Reset key'); + }); + + it('reset updates key', () => { + mock.onPost(propsData.changeKeyUrl).replyOnce(200, { token: 'newToken' }); + + vm.find(GlModal).vm.$emit('ok'); + + return vm.vm + .$nextTick() + .then(waitForPromises) + .then(() => { + expect(vm.vm.authorizationKey).toEqual('newToken'); + expect(vm.find('#authorization-key').attributes('value')).toEqual('newToken'); + }); + }); + + it('reset key failure shows error', () => { + mock.onPost(propsData.changeKeyUrl).replyOnce(500); + + vm.find(GlModal).vm.$emit('ok'); + + return vm.vm + .$nextTick() + .then(waitForPromises) + .then(() => { + expect(vm.find('#authorization-key').attributes('value')).toEqual( + propsData.initialAuthorizationKey, + ); + + expect(document.querySelector('.flash-container').innerText.trim()).toEqual( + 'Failed to reset key. Please try again.', + ); + }); + }); + }); + + describe('authorization key has not been set', () => { + beforeEach(() => { + propsData.initialAuthorizationKey = ''; + vm = shallowMount(ResetKey, { + propsData, + }); + }); + + it('shows Generate Key button', () => { + expect(vm.find('.js-reset-auth-key').text()).toEqual('Generate key'); + expect(vm.find('#authorization-key').attributes('value')).toEqual(''); + }); + + it('Generate key button triggers key change', () => { + mock.onPost(propsData.changeKeyUrl).replyOnce(200, { token: 'newToken' }); + + vm.find('.js-reset-auth-key').vm.$emit('click'); + + return waitForPromises().then(() => { + expect(vm.find('#authorization-key').attributes('value')).toEqual('newToken'); + }); + }); + }); +}); |