diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 00:08:20 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 00:08:20 +0000 |
commit | 59accb4c4780f194554b86c7be3c4a916fb70737 (patch) | |
tree | dac53b413bbac9ba1bc2a523ec64bed2c94d6f7a /spec/javascripts | |
parent | 680d18802596089dc407b7011bcf682d24846aec (diff) | |
download | gitlab-ce-59accb4c4780f194554b86c7be3c4a916fb70737.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
10 files changed, 0 insertions, 833 deletions
diff --git a/spec/javascripts/pages/admin/application_settings/account_and_limits_spec.js b/spec/javascripts/pages/admin/application_settings/account_and_limits_spec.js deleted file mode 100644 index 6a239e307e9..00000000000 --- a/spec/javascripts/pages/admin/application_settings/account_and_limits_spec.js +++ /dev/null @@ -1,36 +0,0 @@ -import $ from 'jquery'; -import initUserInternalRegexPlaceholder, { - PLACEHOLDER_USER_EXTERNAL_DEFAULT_FALSE, - PLACEHOLDER_USER_EXTERNAL_DEFAULT_TRUE, -} from '~/pages/admin/application_settings/account_and_limits'; - -describe('AccountAndLimits', () => { - const FIXTURE = 'application_settings/accounts_and_limit.html'; - let $userDefaultExternal; - let $userInternalRegex; - preloadFixtures(FIXTURE); - - beforeEach(() => { - loadFixtures(FIXTURE); - initUserInternalRegexPlaceholder(); - $userDefaultExternal = $('#application_setting_user_default_external'); - $userInternalRegex = document.querySelector('#application_setting_user_default_internal_regex'); - }); - - describe('Changing of userInternalRegex when userDefaultExternal', () => { - it('is unchecked', () => { - expect($userDefaultExternal.prop('checked')).toBeFalsy(); - expect($userInternalRegex.placeholder).toEqual(PLACEHOLDER_USER_EXTERNAL_DEFAULT_FALSE); - expect($userInternalRegex.readOnly).toBeTruthy(); - }); - - it('is checked', done => { - if (!$userDefaultExternal.prop('checked')) $userDefaultExternal.click(); - - expect($userDefaultExternal.prop('checked')).toBeTruthy(); - expect($userInternalRegex.placeholder).toEqual(PLACEHOLDER_USER_EXTERNAL_DEFAULT_TRUE); - expect($userInternalRegex.readOnly).toBeFalsy(); - done(); - }); - }); -}); diff --git a/spec/javascripts/pages/admin/jobs/index/components/stop_jobs_modal_spec.js b/spec/javascripts/pages/admin/jobs/index/components/stop_jobs_modal_spec.js deleted file mode 100644 index 9ad72e0b043..00000000000 --- a/spec/javascripts/pages/admin/jobs/index/components/stop_jobs_modal_spec.js +++ /dev/null @@ -1,61 +0,0 @@ -import Vue from 'vue'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import axios from '~/lib/utils/axios_utils'; -import stopJobsModal from '~/pages/admin/jobs/index/components/stop_jobs_modal.vue'; - -describe('stop_jobs_modal.vue', () => { - const props = { - url: `${gl.TEST_HOST}/stop_jobs_modal.vue/stopAll`, - }; - let vm; - - afterEach(() => { - vm.$destroy(); - }); - - beforeEach(() => { - const Component = Vue.extend(stopJobsModal); - vm = mountComponent(Component, props); - }); - - describe('onSubmit', () => { - it('stops jobs and redirects to overview page', done => { - const responseURL = `${gl.TEST_HOST}/stop_jobs_modal.vue/jobs`; - const redirectSpy = spyOnDependency(stopJobsModal, 'redirectTo'); - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(props.url); - return Promise.resolve({ - request: { - responseURL, - }, - }); - }); - - vm.onSubmit() - .then(() => { - expect(redirectSpy).toHaveBeenCalledWith(responseURL); - }) - .then(done) - .catch(done.fail); - }); - - it('displays error if stopping jobs failed', done => { - const dummyError = new Error('stopping jobs failed'); - const redirectSpy = spyOnDependency(stopJobsModal, 'redirectTo'); - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(props.url); - return Promise.reject(dummyError); - }); - - vm.onSubmit() - .then(done.fail) - .catch(error => { - expect(error).toBe(dummyError); - expect(redirectSpy).not.toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - }); -}); diff --git a/spec/javascripts/pages/admin/users/new/index_spec.js b/spec/javascripts/pages/admin/users/new/index_spec.js deleted file mode 100644 index 3896323eef7..00000000000 --- a/spec/javascripts/pages/admin/users/new/index_spec.js +++ /dev/null @@ -1,43 +0,0 @@ -import $ from 'jquery'; -import UserInternalRegexHandler from '~/pages/admin/users/new/index'; - -describe('UserInternalRegexHandler', () => { - const FIXTURE = 'admin/users/new_with_internal_user_regex.html'; - let $userExternal; - let $userEmail; - let $warningMessage; - - preloadFixtures(FIXTURE); - - beforeEach(() => { - loadFixtures(FIXTURE); - // eslint-disable-next-line no-new - new UserInternalRegexHandler(); - $userExternal = $('#user_external'); - $userEmail = $('#user_email'); - $warningMessage = $('#warning_external_automatically_set'); - if (!$userExternal.prop('checked')) $userExternal.prop('checked', 'checked'); - }); - - describe('Behaviour of userExternal checkbox when', () => { - it('matches email as internal', done => { - expect($warningMessage.hasClass('hidden')).toBeTruthy(); - - $userEmail.val('test@').trigger('input'); - - expect($userExternal.prop('checked')).toBeFalsy(); - expect($warningMessage.hasClass('hidden')).toBeFalsy(); - done(); - }); - - it('matches email as external', done => { - expect($warningMessage.hasClass('hidden')).toBeTruthy(); - - $userEmail.val('test.ext@').trigger('input'); - - expect($userExternal.prop('checked')).toBeTruthy(); - expect($warningMessage.hasClass('hidden')).toBeTruthy(); - done(); - }); - }); -}); diff --git a/spec/javascripts/pages/labels/components/promote_label_modal_spec.js b/spec/javascripts/pages/labels/components/promote_label_modal_spec.js deleted file mode 100644 index 5bad13c1ef2..00000000000 --- a/spec/javascripts/pages/labels/components/promote_label_modal_spec.js +++ /dev/null @@ -1,103 +0,0 @@ -import Vue from 'vue'; -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import promoteLabelModal from '~/pages/projects/labels/components/promote_label_modal.vue'; -import eventHub from '~/pages/projects/labels/event_hub'; -import axios from '~/lib/utils/axios_utils'; - -describe('Promote label modal', () => { - let vm; - const Component = Vue.extend(promoteLabelModal); - const labelMockData = { - labelTitle: 'Documentation', - labelColor: '#5cb85c', - labelTextColor: '#ffffff', - url: `${gl.TEST_HOST}/dummy/promote/labels`, - groupName: 'group', - }; - - describe('Modal title and description', () => { - beforeEach(() => { - vm = mountComponent(Component, labelMockData); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('contains the proper description', () => { - expect(vm.text).toContain( - `Promoting ${labelMockData.labelTitle} will make it available for all projects inside ${labelMockData.groupName}`, - ); - }); - - it('contains a label span with the color', () => { - const labelFromTitle = vm.$el.querySelector('.modal-header .label.color-label'); - - expect(labelFromTitle.style.backgroundColor).not.toBe(null); - expect(labelFromTitle.textContent).toContain(vm.labelTitle); - }); - }); - - describe('When requesting a label promotion', () => { - beforeEach(() => { - vm = mountComponent(Component, { - ...labelMockData, - }); - spyOn(eventHub, '$emit'); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('redirects when a label is promoted', done => { - const responseURL = `${gl.TEST_HOST}/dummy/endpoint`; - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(labelMockData.url); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'promoteLabelModal.requestStarted', - labelMockData.url, - ); - return Promise.resolve({ - request: { - responseURL, - }, - }); - }); - - vm.onSubmit() - .then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', { - labelUrl: labelMockData.url, - successful: true, - }); - }) - .then(done) - .catch(done.fail); - }); - - it('displays an error if promoting a label failed', done => { - const dummyError = new Error('promoting label failed'); - dummyError.response = { status: 500 }; - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(labelMockData.url); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'promoteLabelModal.requestStarted', - labelMockData.url, - ); - return Promise.reject(dummyError); - }); - - vm.onSubmit() - .catch(error => { - expect(error).toBe(dummyError); - expect(eventHub.$emit).toHaveBeenCalledWith('promoteLabelModal.requestFinished', { - labelUrl: labelMockData.url, - successful: false, - }); - }) - .then(done) - .catch(done.fail); - }); - }); -}); diff --git a/spec/javascripts/pages/milestones/shared/components/delete_milestone_modal_spec.js b/spec/javascripts/pages/milestones/shared/components/delete_milestone_modal_spec.js deleted file mode 100644 index 9075c8aa97a..00000000000 --- a/spec/javascripts/pages/milestones/shared/components/delete_milestone_modal_spec.js +++ /dev/null @@ -1,106 +0,0 @@ -import Vue from 'vue'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import axios from '~/lib/utils/axios_utils'; -import deleteMilestoneModal from '~/pages/milestones/shared/components/delete_milestone_modal.vue'; -import eventHub from '~/pages/milestones/shared/event_hub'; - -describe('delete_milestone_modal.vue', () => { - const Component = Vue.extend(deleteMilestoneModal); - const props = { - issueCount: 1, - mergeRequestCount: 2, - milestoneId: 3, - milestoneTitle: 'my milestone title', - milestoneUrl: `${gl.TEST_HOST}/delete_milestone_modal.vue/milestone`, - }; - let vm; - - afterEach(() => { - vm.$destroy(); - }); - - describe('onSubmit', () => { - beforeEach(() => { - vm = mountComponent(Component, props); - spyOn(eventHub, '$emit'); - }); - - it('deletes milestone and redirects to overview page', done => { - const responseURL = `${gl.TEST_HOST}/delete_milestone_modal.vue/milestoneOverview`; - spyOn(axios, 'delete').and.callFake(url => { - expect(url).toBe(props.milestoneUrl); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'deleteMilestoneModal.requestStarted', - props.milestoneUrl, - ); - eventHub.$emit.calls.reset(); - return Promise.resolve({ - request: { - responseURL, - }, - }); - }); - const redirectSpy = spyOnDependency(deleteMilestoneModal, 'redirectTo'); - - vm.onSubmit() - .then(() => { - expect(redirectSpy).toHaveBeenCalledWith(responseURL); - expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', { - milestoneUrl: props.milestoneUrl, - successful: true, - }); - }) - .then(done) - .catch(done.fail); - }); - - it('displays error if deleting milestone failed', done => { - const dummyError = new Error('deleting milestone failed'); - dummyError.response = { status: 418 }; - spyOn(axios, 'delete').and.callFake(url => { - expect(url).toBe(props.milestoneUrl); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'deleteMilestoneModal.requestStarted', - props.milestoneUrl, - ); - eventHub.$emit.calls.reset(); - return Promise.reject(dummyError); - }); - const redirectSpy = spyOnDependency(deleteMilestoneModal, 'redirectTo'); - - vm.onSubmit() - .catch(error => { - expect(error).toBe(dummyError); - expect(redirectSpy).not.toHaveBeenCalled(); - expect(eventHub.$emit).toHaveBeenCalledWith('deleteMilestoneModal.requestFinished', { - milestoneUrl: props.milestoneUrl, - successful: false, - }); - }) - .then(done) - .catch(done.fail); - }); - }); - - describe('text', () => { - it('contains the issue and milestone count', () => { - vm = mountComponent(Component, props); - const value = vm.text; - - expect(value).toContain('remove it from 1 issue and 2 merge requests'); - }); - - it('contains neither issue nor milestone count', () => { - vm = mountComponent(Component, { - ...props, - issueCount: 0, - mergeRequestCount: 0, - }); - - const value = vm.text; - - expect(value).toContain('is not currently used'); - }); - }); -}); diff --git a/spec/javascripts/pages/milestones/shared/components/promote_milestone_modal_spec.js b/spec/javascripts/pages/milestones/shared/components/promote_milestone_modal_spec.js deleted file mode 100644 index 78c0070187c..00000000000 --- a/spec/javascripts/pages/milestones/shared/components/promote_milestone_modal_spec.js +++ /dev/null @@ -1,98 +0,0 @@ -import Vue from 'vue'; -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import promoteMilestoneModal from '~/pages/milestones/shared/components/promote_milestone_modal.vue'; -import eventHub from '~/pages/milestones/shared/event_hub'; -import axios from '~/lib/utils/axios_utils'; - -describe('Promote milestone modal', () => { - let vm; - const Component = Vue.extend(promoteMilestoneModal); - const milestoneMockData = { - milestoneTitle: 'v1.0', - url: `${gl.TEST_HOST}/dummy/promote/milestones`, - groupName: 'group', - }; - - describe('Modal title and description', () => { - beforeEach(() => { - vm = mountComponent(Component, milestoneMockData); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('contains the proper description', () => { - expect(vm.text).toContain( - `Promoting ${milestoneMockData.milestoneTitle} will make it available for all projects inside ${milestoneMockData.groupName}.`, - ); - }); - - it('contains the correct title', () => { - expect(vm.title).toEqual('Promote v1.0 to group milestone?'); - }); - }); - - describe('When requesting a milestone promotion', () => { - beforeEach(() => { - vm = mountComponent(Component, { - ...milestoneMockData, - }); - spyOn(eventHub, '$emit'); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('redirects when a milestone is promoted', done => { - const responseURL = `${gl.TEST_HOST}/dummy/endpoint`; - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(milestoneMockData.url); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'promoteMilestoneModal.requestStarted', - milestoneMockData.url, - ); - return Promise.resolve({ - request: { - responseURL, - }, - }); - }); - - vm.onSubmit() - .then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('promoteMilestoneModal.requestFinished', { - milestoneUrl: milestoneMockData.url, - successful: true, - }); - }) - .then(done) - .catch(done.fail); - }); - - it('displays an error if promoting a milestone failed', done => { - const dummyError = new Error('promoting milestone failed'); - dummyError.response = { status: 500 }; - spyOn(axios, 'post').and.callFake(url => { - expect(url).toBe(milestoneMockData.url); - expect(eventHub.$emit).toHaveBeenCalledWith( - 'promoteMilestoneModal.requestStarted', - milestoneMockData.url, - ); - return Promise.reject(dummyError); - }); - - vm.onSubmit() - .catch(error => { - expect(error).toBe(dummyError); - expect(eventHub.$emit).toHaveBeenCalledWith('promoteMilestoneModal.requestFinished', { - milestoneUrl: milestoneMockData.url, - successful: false, - }); - }) - .then(done) - .catch(done.fail); - }); - }); -}); diff --git a/spec/javascripts/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js b/spec/javascripts/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js deleted file mode 100644 index ea809e1f170..00000000000 --- a/spec/javascripts/pages/projects/pipeline_schedules/shared/components/pipeline_schedule_callout_spec.js +++ /dev/null @@ -1,106 +0,0 @@ -import Vue from 'vue'; -import Cookies from 'js-cookie'; -import PipelineSchedulesCallout from '~/pages/projects/pipeline_schedules/shared/components/pipeline_schedules_callout.vue'; - -const PipelineSchedulesCalloutComponent = Vue.extend(PipelineSchedulesCallout); -const cookieKey = 'pipeline_schedules_callout_dismissed'; -const docsUrl = 'help/ci/scheduled_pipelines'; - -describe('Pipeline Schedule Callout', function() { - beforeEach(() => { - setFixtures(` - <div id='pipeline-schedules-callout' data-docs-url=${docsUrl}></div> - `); - }); - - describe('independent of cookies', () => { - beforeEach(() => { - this.calloutComponent = new PipelineSchedulesCalloutComponent().$mount(); - }); - - it('the component can be initialized', () => { - expect(this.calloutComponent).toBeDefined(); - }); - - it('correctly sets illustrationSvg', () => { - expect(this.calloutComponent.illustrationSvg).toContain('<svg'); - }); - - it('correctly sets docsUrl', () => { - expect(this.calloutComponent.docsUrl).toContain(docsUrl); - }); - }); - - describe(`when ${cookieKey} cookie is set`, () => { - beforeEach(() => { - Cookies.set(cookieKey, true); - this.calloutComponent = new PipelineSchedulesCalloutComponent().$mount(); - }); - - it('correctly sets calloutDismissed to true', () => { - expect(this.calloutComponent.calloutDismissed).toBe(true); - }); - - it('does not render the callout', () => { - expect(this.calloutComponent.$el.childNodes.length).toBe(0); - }); - }); - - describe('when cookie is not set', () => { - beforeEach(() => { - Cookies.remove(cookieKey); - this.calloutComponent = new PipelineSchedulesCalloutComponent().$mount(); - }); - - it('correctly sets calloutDismissed to false', () => { - expect(this.calloutComponent.calloutDismissed).toBe(false); - }); - - it('renders the callout container', () => { - expect(this.calloutComponent.$el.querySelector('.bordered-box')).not.toBeNull(); - }); - - it('renders the callout svg', () => { - expect(this.calloutComponent.$el.outerHTML).toContain('<svg'); - }); - - it('renders the callout title', () => { - expect(this.calloutComponent.$el.outerHTML).toContain('Scheduling Pipelines'); - }); - - it('renders the callout text', () => { - expect(this.calloutComponent.$el.outerHTML).toContain('runs pipelines in the future'); - }); - - it('renders the documentation url', () => { - expect(this.calloutComponent.$el.outerHTML).toContain(docsUrl); - }); - - it('updates calloutDismissed when close button is clicked', done => { - this.calloutComponent.$el.querySelector('#dismiss-callout-btn').click(); - - Vue.nextTick(() => { - expect(this.calloutComponent.calloutDismissed).toBe(true); - done(); - }); - }); - - it('#dismissCallout updates calloutDismissed', done => { - this.calloutComponent.dismissCallout(); - - Vue.nextTick(() => { - expect(this.calloutComponent.calloutDismissed).toBe(true); - done(); - }); - }); - - it('is hidden when close button is clicked', done => { - this.calloutComponent.$el.querySelector('#dismiss-callout-btn').click(); - - Vue.nextTick(() => { - expect(this.calloutComponent.$el.childNodes.length).toBe(0); - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js b/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js deleted file mode 100644 index 1809e92e1d9..00000000000 --- a/spec/javascripts/pages/sessions/new/preserve_url_fragment_spec.js +++ /dev/null @@ -1,61 +0,0 @@ -import $ from 'jquery'; -import preserveUrlFragment from '~/pages/sessions/new/preserve_url_fragment'; - -describe('preserve_url_fragment', () => { - preloadFixtures('sessions/new.html'); - - beforeEach(() => { - loadFixtures('sessions/new.html'); - }); - - it('adds the url fragment to all login and sign up form actions', () => { - preserveUrlFragment('#L65'); - - expect($('#new_user').attr('action')).toBe('http://test.host/users/sign_in#L65'); - expect($('#new_new_user').attr('action')).toBe('http://test.host/users#L65'); - }); - - it('does not add an empty url fragment to login and sign up form actions', () => { - preserveUrlFragment(); - - expect($('#new_user').attr('action')).toBe('http://test.host/users/sign_in'); - expect($('#new_new_user').attr('action')).toBe('http://test.host/users'); - }); - - it('does not add an empty query parameter to OmniAuth login buttons', () => { - preserveUrlFragment(); - - expect($('#oauth-login-cas3').attr('href')).toBe('http://test.host/users/auth/cas3'); - - expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe( - 'http://test.host/users/auth/auth0', - ); - }); - - describe('adds "redirect_fragment" query parameter to OmniAuth login buttons', () => { - it('when "remember_me" is not present', () => { - preserveUrlFragment('#L65'); - - expect($('#oauth-login-cas3').attr('href')).toBe( - 'http://test.host/users/auth/cas3?redirect_fragment=L65', - ); - - expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe( - 'http://test.host/users/auth/auth0?redirect_fragment=L65', - ); - }); - - it('when "remember-me" is present', () => { - $('a.omniauth-btn').attr('href', (i, href) => `${href}?remember_me=1`); - preserveUrlFragment('#L65'); - - expect($('#oauth-login-cas3').attr('href')).toBe( - 'http://test.host/users/auth/cas3?remember_me=1&redirect_fragment=L65', - ); - - expect($('#oauth-login-auth0').attr('href')).toBe( - 'http://test.host/users/auth/auth0?remember_me=1&redirect_fragment=L65', - ); - }); - }); -}); diff --git a/spec/javascripts/prometheus_metrics/mock_data.js b/spec/javascripts/prometheus_metrics/mock_data.js deleted file mode 100644 index 3af56df92e2..00000000000 --- a/spec/javascripts/prometheus_metrics/mock_data.js +++ /dev/null @@ -1,41 +0,0 @@ -export const metrics = [ - { - group: 'Kubernetes', - priority: 1, - active_metrics: 4, - metrics_missing_requirements: 0, - }, - { - group: 'HAProxy', - priority: 2, - active_metrics: 3, - metrics_missing_requirements: 0, - }, - { - group: 'Apache', - priority: 3, - active_metrics: 5, - metrics_missing_requirements: 0, - }, -]; - -export const missingVarMetrics = [ - { - group: 'Kubernetes', - priority: 1, - active_metrics: 4, - metrics_missing_requirements: 0, - }, - { - group: 'HAProxy', - priority: 2, - active_metrics: 3, - metrics_missing_requirements: 1, - }, - { - group: 'Apache', - priority: 3, - active_metrics: 5, - metrics_missing_requirements: 3, - }, -]; diff --git a/spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js b/spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js deleted file mode 100644 index dca3e1553b9..00000000000 --- a/spec/javascripts/prometheus_metrics/prometheus_metrics_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import axios from '~/lib/utils/axios_utils'; -import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics'; -import PANEL_STATE from '~/prometheus_metrics/constants'; -import { metrics, missingVarMetrics } from './mock_data'; - -describe('PrometheusMetrics', () => { - const FIXTURE = 'services/prometheus/prometheus_service.html'; - preloadFixtures(FIXTURE); - - beforeEach(() => { - loadFixtures(FIXTURE); - }); - - describe('constructor', () => { - let prometheusMetrics; - - beforeEach(() => { - prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring'); - }); - - it('should initialize wrapper element refs on class object', () => { - expect(prometheusMetrics.$wrapper).toBeDefined(); - expect(prometheusMetrics.$monitoredMetricsPanel).toBeDefined(); - expect(prometheusMetrics.$monitoredMetricsCount).toBeDefined(); - expect(prometheusMetrics.$monitoredMetricsLoading).toBeDefined(); - expect(prometheusMetrics.$monitoredMetricsEmpty).toBeDefined(); - expect(prometheusMetrics.$monitoredMetricsList).toBeDefined(); - expect(prometheusMetrics.$missingEnvVarPanel).toBeDefined(); - expect(prometheusMetrics.$panelToggle).toBeDefined(); - expect(prometheusMetrics.$missingEnvVarMetricCount).toBeDefined(); - expect(prometheusMetrics.$missingEnvVarMetricsList).toBeDefined(); - }); - - it('should initialize metadata on class object', () => { - expect(prometheusMetrics.backOffRequestCounter).toEqual(0); - expect(prometheusMetrics.activeMetricsEndpoint).toContain('/test'); - }); - }); - - describe('showMonitoringMetricsPanelState', () => { - let prometheusMetrics; - - beforeEach(() => { - prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring'); - }); - - it('should show loading state when called with `loading`', () => { - prometheusMetrics.showMonitoringMetricsPanelState(PANEL_STATE.LOADING); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeFalsy(); - expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsList.hasClass('hidden')).toBeTruthy(); - }); - - it('should show metrics list when called with `list`', () => { - prometheusMetrics.showMonitoringMetricsPanelState(PANEL_STATE.LIST); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsList.hasClass('hidden')).toBeFalsy(); - }); - - it('should show empty state when called with `empty`', () => { - prometheusMetrics.showMonitoringMetricsPanelState(PANEL_STATE.EMPTY); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeFalsy(); - expect(prometheusMetrics.$monitoredMetricsList.hasClass('hidden')).toBeTruthy(); - }); - }); - - describe('populateActiveMetrics', () => { - let prometheusMetrics; - - beforeEach(() => { - prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring'); - }); - - it('should show monitored metrics list', () => { - prometheusMetrics.populateActiveMetrics(metrics); - - const $metricsListLi = prometheusMetrics.$monitoredMetricsList.find('li'); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsList.hasClass('hidden')).toBeFalsy(); - - expect(prometheusMetrics.$monitoredMetricsCount.text()).toEqual( - '3 exporters with 12 metrics were found', - ); - - expect($metricsListLi.length).toEqual(metrics.length); - expect( - $metricsListLi - .first() - .find('.badge') - .text(), - ).toEqual(`${metrics[0].active_metrics}`); - }); - - it('should show missing environment variables list', () => { - prometheusMetrics.populateActiveMetrics(missingVarMetrics); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$missingEnvVarPanel.hasClass('hidden')).toBeFalsy(); - - expect(prometheusMetrics.$missingEnvVarMetricCount.text()).toEqual('2'); - expect(prometheusMetrics.$missingEnvVarPanel.find('li').length).toEqual(2); - expect(prometheusMetrics.$missingEnvVarPanel.find('.flash-container')).toBeDefined(); - }); - }); - - describe('loadActiveMetrics', () => { - let prometheusMetrics; - let mock; - - function mockSuccess() { - mock.onGet(prometheusMetrics.activeMetricsEndpoint).reply(200, { - data: metrics, - success: true, - }); - } - - function mockError() { - mock.onGet(prometheusMetrics.activeMetricsEndpoint).networkError(); - } - - beforeEach(() => { - spyOn(axios, 'get').and.callThrough(); - - prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring'); - - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - }); - - it('should show loader animation while response is being loaded and hide it when request is complete', done => { - mockSuccess(); - - prometheusMetrics.loadActiveMetrics(); - - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeFalsy(); - expect(axios.get).toHaveBeenCalledWith(prometheusMetrics.activeMetricsEndpoint); - - setTimeout(() => { - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - done(); - }); - }); - - it('should show empty state if response failed to load', done => { - mockError(); - - prometheusMetrics.loadActiveMetrics(); - - setTimeout(() => { - expect(prometheusMetrics.$monitoredMetricsLoading.hasClass('hidden')).toBeTruthy(); - expect(prometheusMetrics.$monitoredMetricsEmpty.hasClass('hidden')).toBeFalsy(); - done(); - }); - }); - - it('should populate metrics list once response is loaded', done => { - spyOn(prometheusMetrics, 'populateActiveMetrics'); - mockSuccess(); - - prometheusMetrics.loadActiveMetrics(); - - setTimeout(() => { - expect(prometheusMetrics.populateActiveMetrics).toHaveBeenCalledWith(metrics); - done(); - }); - }); - }); -}); |