Commit 383ead5d authored by Phil Hughes's avatar Phil Hughes

Merge branch 'Issue-33543-videos-are-not-stopped-when-submitting-comment' into 'master'

#33543 Videos are not stopped when submitting comment

See merge request gitlab-org/gitlab!19556
parents 88d19c86 181df908
...@@ -336,6 +336,7 @@ export default { ...@@ -336,6 +336,7 @@ export default {
<markdown-field <markdown-field
ref="markdownField" ref="markdownField"
:is-submitting="isSubmitting"
:markdown-preview-path="markdownPreviewPath" :markdown-preview-path="markdownPreviewPath"
:markdown-docs-path="markdownDocsPath" :markdown-docs-path="markdownDocsPath"
:quick-actions-docs-path="quickActionsDocsPath" :quick-actions-docs-path="quickActionsDocsPath"
......
...@@ -20,6 +20,11 @@ export default { ...@@ -20,6 +20,11 @@ export default {
Suggestions, Suggestions,
}, },
props: { props: {
isSubmitting: {
type: Boolean,
required: false,
default: false,
},
markdownPreviewPath: { markdownPreviewPath: {
type: String, type: String,
required: false, required: false,
...@@ -133,6 +138,20 @@ export default { ...@@ -133,6 +138,20 @@ export default {
); );
}, },
}, },
watch: {
isSubmitting(isSubmitting) {
if (!isSubmitting || !this.$refs['markdown-preview'].querySelectorAll) {
return;
}
const mediaInPreview = this.$refs['markdown-preview'].querySelectorAll('video, audio');
if (mediaInPreview) {
mediaInPreview.forEach(media => {
media.pause();
});
}
},
},
mounted() { mounted() {
/* /*
GLForm class handles all the toolbar buttons GLForm class handles all the toolbar buttons
...@@ -177,7 +196,6 @@ export default { ...@@ -177,7 +196,6 @@ export default {
this.renderMarkdown(); this.renderMarkdown();
} }
}, },
showWriteTab() { showWriteTab() {
this.markdownPreview = ''; this.markdownPreview = '';
this.previewMarkdown = false; this.previewMarkdown = false;
......
...@@ -201,7 +201,7 @@ module.exports = { ...@@ -201,7 +201,7 @@ module.exports = {
loader: 'raw-loader', loader: 'raw-loader',
}, },
{ {
test: /\.(gif|png)$/, test: /\.(gif|png|mp4)$/,
loader: 'url-loader', loader: 'url-loader',
options: { limit: 2048 }, options: { limit: 2048 },
}, },
......
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import { TEST_HOST } from 'spec/test_constants'; import fieldComponent from '~/vue_shared/components/markdown/field.vue';
import { TEST_HOST, FIXTURES_PATH } from 'spec/test_constants';
import AxiosMockAdapter from 'axios-mock-adapter'; import AxiosMockAdapter from 'axios-mock-adapter';
import $ from 'jquery'; import $ from 'jquery';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import fieldComponent from '~/vue_shared/components/markdown/field.vue';
const markdownPreviewPath = `${TEST_HOST}/preview`; const markdownPreviewPath = `${TEST_HOST}/preview`;
const markdownDocsPath = `${TEST_HOST}/docs`; const markdownDocsPath = `${TEST_HOST}/docs`;
...@@ -19,6 +19,7 @@ function createComponent() { ...@@ -19,6 +19,7 @@ function createComponent() {
propsData: { propsData: {
markdownDocsPath, markdownDocsPath,
markdownPreviewPath, markdownPreviewPath,
isSubmitting: false,
}, },
slots: { slots: {
textarea: '<textarea>testing\n123</textarea>', textarea: '<textarea>testing\n123</textarea>',
...@@ -27,6 +28,7 @@ function createComponent() { ...@@ -27,6 +28,7 @@ function createComponent() {
<field-component <field-component
markdown-preview-path="${markdownPreviewPath}" markdown-preview-path="${markdownPreviewPath}"
markdown-docs-path="${markdownDocsPath}" markdown-docs-path="${markdownDocsPath}"
:isSubmitting="false"
> >
<textarea <textarea
slot="textarea" slot="textarea"
...@@ -44,6 +46,7 @@ const getPreviewLink = wrapper => wrapper.find('.nav-links .js-preview-link'); ...@@ -44,6 +46,7 @@ const getPreviewLink = wrapper => wrapper.find('.nav-links .js-preview-link');
const getWriteLink = wrapper => wrapper.find('.nav-links .js-write-link'); const getWriteLink = wrapper => wrapper.find('.nav-links .js-write-link');
const getMarkdownButton = wrapper => wrapper.find('.js-md'); const getMarkdownButton = wrapper => wrapper.find('.js-md');
const getAllMarkdownButtons = wrapper => wrapper.findAll('.js-md'); const getAllMarkdownButtons = wrapper => wrapper.findAll('.js-md');
const getVideo = wrapper => wrapper.find('video');
describe('Markdown field component', () => { describe('Markdown field component', () => {
let axiosMock; let axiosMock;
...@@ -59,7 +62,10 @@ describe('Markdown field component', () => { ...@@ -59,7 +62,10 @@ describe('Markdown field component', () => {
describe('mounted', () => { describe('mounted', () => {
let wrapper; let wrapper;
const previewHTML = '<p>markdown preview</p>'; const previewHTML = `
<p>markdown preview</p>
<video src="${FIXTURES_PATH}/static/mock-video.mp4" muted="muted"></video>
`;
let previewLink; let previewLink;
let writeLink; let writeLink;
...@@ -112,9 +118,35 @@ describe('Markdown field component', () => { ...@@ -112,9 +118,35 @@ describe('Markdown field component', () => {
previewLink.trigger('click'); previewLink.trigger('click');
setTimeout(() => { return axios.waitFor(markdownPreviewPath).then(() => {
expect($.fn.renderGFM).toHaveBeenCalled(); expect(wrapper.find('.md-preview-holder').element.innerHTML).toContain(previewHTML);
}, 0); });
});
it('calls video.pause() on comment input when isSubmitting is changed to true', () => {
wrapper = createComponent();
previewLink = getPreviewLink(wrapper);
previewLink.trigger('click');
let callPause;
return axios
.waitFor(markdownPreviewPath)
.then(() => {
const video = getVideo(wrapper);
callPause = jest.spyOn(video.element, 'pause').mockImplementation(() => true);
wrapper.setProps({
isSubmitting: true,
markdownPreviewPath,
markdownDocsPath,
});
return wrapper.vm.$nextTick();
})
.then(() => {
expect(callPause).toHaveBeenCalled();
});
}); });
it('clicking already active write or preview link does nothing', () => { it('clicking already active write or preview link does nothing', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment