diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-30 09:08:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-30 09:08:07 +0000 |
commit | d08bee6aaf36fb6cd922f130f5596484c64562c0 (patch) | |
tree | 2476df6e22109ff9fa04db96a8867b2411cf7d5c /spec/frontend | |
parent | 28fd41cf28bfac77fe877b6cce83594c1f9f21a1 (diff) | |
download | gitlab-ce-d08bee6aaf36fb6cd922f130f5596484c64562c0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
5 files changed, 205 insertions, 0 deletions
diff --git a/spec/frontend/fixtures/application_settings.rb b/spec/frontend/fixtures/application_settings.rb index ebccecb32ba..b09bea56b94 100644 --- a/spec/frontend/fixtures/application_settings.rb +++ b/spec/frontend/fixtures/application_settings.rb @@ -34,4 +34,12 @@ RSpec.describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', ty expect(response).to be_successful end + + it 'application_settings/usage.html' do + stub_application_setting(usage_ping_enabled: false) + + get :metrics_and_profiling + + expect(response).to be_successful + end end diff --git a/spec/frontend/pages/admin/application_settings/metrics_and_profiling/usage_statistics_spec.js b/spec/frontend/pages/admin/application_settings/metrics_and_profiling/usage_statistics_spec.js new file mode 100644 index 00000000000..ef649e7697b --- /dev/null +++ b/spec/frontend/pages/admin/application_settings/metrics_and_profiling/usage_statistics_spec.js @@ -0,0 +1,57 @@ +import initSetHelperText, { + HELPER_TEXT_USAGE_PING_DISABLED, + HELPER_TEXT_USAGE_PING_ENABLED, +} from '~/pages/admin/application_settings/metrics_and_profiling/usage_statistics'; + +describe('UsageStatistics', () => { + const FIXTURE = 'application_settings/usage.html'; + let usagePingCheckBox; + let usagePingFeaturesCheckBox; + let usagePingFeaturesLabel; + let usagePingFeaturesHelperText; + + beforeEach(() => { + loadFixtures(FIXTURE); + initSetHelperText(); + usagePingCheckBox = document.getElementById('application_setting_usage_ping_enabled'); + usagePingFeaturesCheckBox = document.getElementById( + 'application_setting_usage_ping_features_enabled', + ); + usagePingFeaturesLabel = document.getElementById('usage_ping_features_label'); + usagePingFeaturesHelperText = document.getElementById('usage_ping_features_helper_text'); + }); + + const expectEnabledUsagePingFeaturesCheckBox = () => { + expect(usagePingFeaturesCheckBox.classList.contains('gl-cursor-not-allowed')).toBe(false); + expect(usagePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_USAGE_PING_ENABLED); + }; + + const expectDisabledUsagePingFeaturesCheckBox = () => { + expect(usagePingFeaturesLabel.classList.contains('gl-cursor-not-allowed')).toBe(true); + expect(usagePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_USAGE_PING_DISABLED); + }; + + describe('Registration Features checkbox', () => { + it('is disabled when Usage Ping checkbox is unchecked', () => { + expect(usagePingCheckBox.checked).toBe(false); + expectDisabledUsagePingFeaturesCheckBox(); + }); + + it('is enabled when Usage Ping checkbox is checked', () => { + usagePingCheckBox.click(); + expect(usagePingCheckBox.checked).toBe(true); + expectEnabledUsagePingFeaturesCheckBox(); + }); + + it('is switched to disabled when Usage Ping checkbox is unchecked ', () => { + usagePingCheckBox.click(); + usagePingFeaturesCheckBox.click(); + expectEnabledUsagePingFeaturesCheckBox(); + + usagePingCheckBox.click(); + expect(usagePingCheckBox.checked).toBe(false); + expect(usagePingFeaturesCheckBox.checked).toBe(false); + expectDisabledUsagePingFeaturesCheckBox(); + }); + }); +}); diff --git a/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js b/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js new file mode 100644 index 00000000000..f7b3fc6823c --- /dev/null +++ b/spec/frontend/sidebar/components/todo_toggle/sidebar_todo_widget_spec.js @@ -0,0 +1,86 @@ +import { shallowMount } from '@vue/test-utils'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import createFlash from '~/flash'; +import SidebarTodoWidget from '~/sidebar/components/todo_toggle/sidebar_todo_widget.vue'; +import epicTodoQuery from '~/sidebar/queries/epic_todo.query.graphql'; +import TodoButton from '~/vue_shared/components/todo_button.vue'; +import { todosResponse, noTodosResponse } from '../../mock_data'; + +jest.mock('~/flash'); + +Vue.use(VueApollo); + +describe('Sidebar Todo Widget', () => { + let wrapper; + let fakeApollo; + + const findTodoButton = () => wrapper.findComponent(TodoButton); + + const createComponent = ({ + todosQueryHandler = jest.fn().mockResolvedValue(noTodosResponse), + } = {}) => { + fakeApollo = createMockApollo([[epicTodoQuery, todosQueryHandler]]); + + wrapper = shallowMount(SidebarTodoWidget, { + apolloProvider: fakeApollo, + provide: { + canUpdate: true, + }, + propsData: { + fullPath: 'group', + issuableIid: '1', + issuableId: 'gid://gitlab/Epic/4', + issuableType: 'epic', + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + fakeApollo = null; + }); + + describe('when user does not have a todo for the issuable', () => { + beforeEach(() => { + createComponent(); + return waitForPromises(); + }); + + it('passes false isTodo prop to Todo button component', () => { + expect(findTodoButton().props('isTodo')).toBe(false); + }); + + it('emits `todoUpdated` event with a `false` payload', () => { + expect(wrapper.emitted('todoUpdated')).toEqual([[false]]); + }); + }); + + describe('when user has a todo for the issuable', () => { + beforeEach(() => { + createComponent({ + todosQueryHandler: jest.fn().mockResolvedValue(todosResponse), + }); + return waitForPromises(); + }); + + it('passes true isTodo prop to Todo button component', () => { + expect(findTodoButton().props('isTodo')).toBe(true); + }); + + it('emits `todoUpdated` event with a `true` payload', () => { + expect(wrapper.emitted('todoUpdated')).toEqual([[true]]); + }); + }); + + it('displays a flash message when query is rejected', async () => { + createComponent({ + todosQueryHandler: jest.fn().mockRejectedValue('Houston, we have a problem'), + }); + await waitForPromises(); + + expect(createFlash).toHaveBeenCalled(); + }); +}); diff --git a/spec/frontend/sidebar/mock_data.js b/spec/frontend/sidebar/mock_data.js index d6287b93fb9..6366600b0e8 100644 --- a/spec/frontend/sidebar/mock_data.js +++ b/spec/frontend/sidebar/mock_data.js @@ -609,4 +609,38 @@ export const issuableTimeTrackingResponse = { }, }; +export const todosResponse = { + data: { + workspace: { + __typename: 'Group', + issuable: { + __typename: 'Epic', + id: 'gid://gitlab/Epic/4', + currentUserTodos: { + nodes: [ + { + id: 'gid://gitlab/Todo/433', + }, + ], + }, + }, + }, + }, +}; + +export const noTodosResponse = { + data: { + workspace: { + __typename: 'Group', + issuable: { + __typename: 'Epic', + id: 'gid://gitlab/Epic/4', + currentUserTodos: { + nodes: [], + }, + }, + }, + }, +}; + export default mockData; diff --git a/spec/frontend/vue_shared/components/todo_button_spec.js b/spec/frontend/vue_shared/components/todo_button_spec.js index 8043bb7785b..3cb2911a5e5 100644 --- a/spec/frontend/vue_shared/components/todo_button_spec.js +++ b/spec/frontend/vue_shared/components/todo_button_spec.js @@ -4,6 +4,7 @@ import TodoButton from '~/vue_shared/components/todo_button.vue'; describe('Todo Button', () => { let wrapper; + let dispatchEventSpy; const createComponent = (props = {}, mountFn = shallowMount) => { wrapper = mountFn(TodoButton, { @@ -13,8 +14,17 @@ describe('Todo Button', () => { }); }; + beforeEach(() => { + dispatchEventSpy = jest.spyOn(document, 'dispatchEvent'); + jest.spyOn(document, 'querySelector').mockReturnValue({ + innerText: 2, + }); + }); + afterEach(() => { wrapper.destroy(); + dispatchEventSpy = null; + jest.clearAllMocks(); }); it('renders GlButton', () => { @@ -30,6 +40,16 @@ describe('Todo Button', () => { expect(wrapper.emitted().click).toBeTruthy(); }); + it('calls dispatchDocumentEvent to update global To-Do counter correctly', () => { + createComponent({}, mount); + wrapper.find(GlButton).trigger('click'); + const dispatchedEvent = dispatchEventSpy.mock.calls[0][0]; + + expect(dispatchEventSpy).toHaveBeenCalledTimes(1); + expect(dispatchedEvent.detail).toEqual({ count: 1 }); + expect(dispatchedEvent.type).toBe('todo:toggle'); + }); + it.each` label | isTodo ${'Mark as done'} | ${true} |