diff options
Diffstat (limited to 'spec/frontend/static_site_editor')
3 files changed, 77 insertions, 1 deletions
diff --git a/spec/frontend/static_site_editor/components/edit_area_spec.js b/spec/frontend/static_site_editor/components/edit_area_spec.js index 247aff57c1a..ed33f93ec51 100644 --- a/spec/frontend/static_site_editor/components/edit_area_spec.js +++ b/spec/frontend/static_site_editor/components/edit_area_spec.js @@ -250,4 +250,17 @@ describe('~/static_site_editor/components/edit_area.vue', () => { expect(wrapper.emitted('submit').length).toBe(1); }); }); + + describe('when RichContentEditor component triggers load event', () => { + it('stores formatted markdown provided in the event data', () => { + const data = { formattedMarkdown: 'formatted markdown' }; + + findRichContentEditor().vm.$emit('load', data); + + // We can access the formatted markdown when submitting changes + findPublishToolbar().vm.$emit('submit'); + + expect(wrapper.emitted('submit')[0][0]).toMatchObject(data); + }); + }); }); diff --git a/spec/frontend/static_site_editor/pages/home_spec.js b/spec/frontend/static_site_editor/pages/home_spec.js index d0b72ad0cf0..3e488a950dc 100644 --- a/spec/frontend/static_site_editor/pages/home_spec.js +++ b/spec/frontend/static_site_editor/pages/home_spec.js @@ -235,6 +235,7 @@ describe('static_site_editor/pages/home', () => { describe('when submitting changes succeeds', () => { const newContent = `new ${content}`; + const formattedMarkdown = `formatted ${content}`; beforeEach(() => { mutateMock.mockResolvedValueOnce(hasSubmittedChangesMutationPayload).mockResolvedValueOnce({ @@ -243,7 +244,12 @@ describe('static_site_editor/pages/home', () => { }, }); - buildWrapper({ content: newContent, images }); + buildWrapper(); + + findEditMetaModal().vm.show = jest.fn(); + + findEditArea().vm.$emit('submit', { content: newContent, images, formattedMarkdown }); + findEditMetaModal().vm.$emit('primary', mergeRequestMeta); return wrapper.vm.$nextTick(); @@ -266,6 +272,7 @@ describe('static_site_editor/pages/home', () => { variables: { input: { content: newContent, + formattedMarkdown, project, sourcePath, username, diff --git a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js index 5018da7300b..6c2bff6740a 100644 --- a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js +++ b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js @@ -9,6 +9,10 @@ import { SUBMIT_CHANGES_MERGE_REQUEST_ERROR, TRACKING_ACTION_CREATE_COMMIT, TRACKING_ACTION_CREATE_MERGE_REQUEST, + USAGE_PING_TRACKING_ACTION_CREATE_COMMIT, + USAGE_PING_TRACKING_ACTION_CREATE_MERGE_REQUEST, + DEFAULT_FORMATTING_CHANGES_COMMIT_MESSAGE, + DEFAULT_FORMATTING_CHANGES_COMMIT_DESCRIPTION, } from '~/static_site_editor/constants'; import generateBranchName from '~/static_site_editor/services/generate_branch_name'; import submitContentChanges from '~/static_site_editor/services/submit_content_changes'; @@ -79,6 +83,36 @@ describe('submitContentChanges', () => { ); }); + describe('committing markdown formatting changes', () => { + const formattedMarkdown = `formatted ${content}`; + const commitPayload = { + branch, + commit_message: `${DEFAULT_FORMATTING_CHANGES_COMMIT_MESSAGE}\n\n${DEFAULT_FORMATTING_CHANGES_COMMIT_DESCRIPTION}`, + actions: [ + { + action: 'update', + file_path: sourcePath, + content: formattedMarkdown, + }, + ], + }; + + it('commits markdown formatting changes in a separate commit', () => { + return submitContentChanges(buildPayload({ formattedMarkdown })).then(() => { + expect(Api.commitMultiple).toHaveBeenCalledWith(projectId, commitPayload); + }); + }); + + it('does not commit markdown formatting changes when there are none', () => { + return submitContentChanges(buildPayload()).then(() => { + expect(Api.commitMultiple.mock.calls).toHaveLength(1); + expect(Api.commitMultiple.mock.calls[0][1]).not.toMatchObject({ + actions: commitPayload.actions, + }); + }); + }); + }); + it('commits the content changes to the branch when creating branch succeeds', () => { return submitContentChanges(buildPayload()).then(() => { expect(Api.commitMultiple).toHaveBeenCalledWith(projectId, { @@ -201,4 +235,26 @@ describe('submitContentChanges', () => { ); }); }); + + describe('sends the correct Usage Ping tracking event', () => { + beforeEach(() => { + jest.spyOn(Api, 'trackRedisCounterEvent').mockResolvedValue({ data: '' }); + }); + + it('for commiting changes', () => { + return submitContentChanges(buildPayload()).then(() => { + expect(Api.trackRedisCounterEvent).toHaveBeenCalledWith( + USAGE_PING_TRACKING_ACTION_CREATE_COMMIT, + ); + }); + }); + + it('for creating a merge request', () => { + return submitContentChanges(buildPayload()).then(() => { + expect(Api.trackRedisCounterEvent).toHaveBeenCalledWith( + USAGE_PING_TRACKING_ACTION_CREATE_MERGE_REQUEST, + ); + }); + }); + }); }); |