Commit cca1fd2a authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Update frontend specs

Adds additional tests for the new vue
js modal.

Minor test fixes

Fix broken jest tests

Minor rebase cleanup and some fixes
for broken tests.
parent 0a7d47df
...@@ -29,7 +29,6 @@ export default { ...@@ -29,7 +29,6 @@ export default {
primary: { primary: {
text: __('Fork project'), text: __('Fork project'),
attributes: { attributes: {
type: 'submit',
href: this.forkPath, href: this.forkPath,
variant: 'confirm', variant: 'confirm',
'data-qa-selector': 'fork_project_button', 'data-qa-selector': 'fork_project_button',
...@@ -54,6 +53,7 @@ export default { ...@@ -54,6 +53,7 @@ export default {
</script> </script>
<template> <template>
<gl-modal <gl-modal
data-qa-selector="confirm_fork_modal"
:visible="isVisible" :visible="isVisible"
:modal-id="modalId" :modal-id="modalId"
:title="$options.i18n.title" :title="$options.i18n.title"
......
...@@ -119,7 +119,7 @@ export default { ...@@ -119,7 +119,7 @@ export default {
return { return {
selection: KEY_WEB_IDE, selection: KEY_WEB_IDE,
showEnableGitpodModal: false, showEnableGitpodModal: false,
isForkModalOpen: false, showForkModal: false,
}; };
}, },
computed: { computed: {
...@@ -140,7 +140,7 @@ export default { ...@@ -140,7 +140,7 @@ export default {
return; return;
} }
this.showForkModal(true); this.showModal('showForkModal');
}, },
} }
: { href: this.editUrl }; : { href: this.editUrl };
...@@ -183,7 +183,7 @@ export default { ...@@ -183,7 +183,7 @@ export default {
return; return;
} }
this.showForkModal(true); this.showModal('showForkModal');
}, },
} }
: { href: this.webIdeUrl }; : { href: this.webIdeUrl };
...@@ -259,16 +259,12 @@ export default { ...@@ -259,16 +259,12 @@ export default {
select(key) { select(key) {
this.selection = key; this.selection = key;
}, },
showForkModal(isOpen) {
this.isForkModalOpen = isOpen;
},
showModal(dataKey) { showModal(dataKey) {
this[dataKey] = true; this[dataKey] = true;
}, },
}, },
}; };
</script> </script>
<template> <template>
<div class="gl-sm-ml-3"> <div class="gl-sm-ml-3">
<actions-button <actions-button
...@@ -283,7 +279,6 @@ export default { ...@@ -283,7 +279,6 @@ export default {
:value="selection" :value="selection"
@input="select" @input="select"
/> />
<gl-modal <gl-modal
v-if="computedShowGitpodButton && !gitpodEnabled" v-if="computedShowGitpodButton && !gitpodEnabled"
v-model="showEnableGitpodModal" v-model="showEnableGitpodModal"
...@@ -297,10 +292,10 @@ export default { ...@@ -297,10 +292,10 @@ export default {
</gl-modal> </gl-modal>
<confirm-fork-modal <confirm-fork-modal
v-if="showWebIdeButton || showEditButton" v-if="showWebIdeButton || showEditButton"
:is-visible="isForkModalOpen" :is-visible="showForkModal"
:modal-id="forkModalId" :modal-id="forkModalId"
:fork-path="forkPath" :fork-path="forkPath"
@hide="showForkModal(false)" @hide="showForkModal = false"
/> />
</div> </div>
</template> </template>
...@@ -177,14 +177,19 @@ module TreeHelper ...@@ -177,14 +177,19 @@ module TreeHelper
def fork_modal_options(project, ref, path, blob) def fork_modal_options(project, ref, path, blob)
if show_edit_button?({ blob: blob }) if show_edit_button?({ blob: blob })
return { fork_path: fork_and_edit_path(project, ref, path), fork_modal_id: "modal-confirm-fork-edit" } fork_path = fork_and_edit_path(project, ref, path)
fork_modal_id = "modal-confirm-fork-edit"
end end
if show_web_ide_button? if show_web_ide_button?
return { fork_path: ide_fork_and_edit_path(project, ref, path), fork_modal_id: "modal-confirm-fork-webide" } fork_path = ide_fork_and_edit_path(project, ref, path)
fork_modal_id = "modal-confirm-fork-webide"
end end
{} {
fork_path: fork_path,
fork_modal_id: fork_modal_id
}
end end
def web_ide_button_data(options = {}) def web_ide_button_data(options = {})
......
...@@ -41453,9 +41453,6 @@ msgstr "" ...@@ -41453,9 +41453,6 @@ msgstr ""
msgid "You cannot write to this read-only GitLab instance." msgid "You cannot write to this read-only GitLab instance."
msgstr "" msgstr ""
msgid "You can’t %{tag_start}edit%{tag_end} files directly in this project. Fork this project and submit a merge request with your changes."
msgstr ""
msgid "You can’t edit files directly in this project. Fork this project and submit a merge request with your changes." msgid "You can’t edit files directly in this project. Fork this project and submit a merge request with your changes."
msgstr "" msgstr ""
......
...@@ -68,7 +68,7 @@ module QA ...@@ -68,7 +68,7 @@ module QA
element :delete_button element :delete_button
end end
view 'app/views/shared/_confirm_fork_modal.html.haml' do view 'app/assets/javascripts/vue_shared/components/confirm_fork_modal.vue' do
element :fork_project_button element :fork_project_button
element :confirm_fork_modal element :confirm_fork_modal
end end
......
...@@ -4,6 +4,7 @@ import { nextTick } from 'vue'; ...@@ -4,6 +4,7 @@ import { nextTick } from 'vue';
import ActionsButton from '~/vue_shared/components/actions_button.vue'; import ActionsButton from '~/vue_shared/components/actions_button.vue';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import WebIdeLink from '~/vue_shared/components/web_ide_link.vue'; import WebIdeLink from '~/vue_shared/components/web_ide_link.vue';
import ConfirmForkModal from '~/vue_shared/components/confirm_fork_modal.vue';
import { stubComponent } from 'helpers/stub_component'; import { stubComponent } from 'helpers/stub_component';
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
...@@ -13,6 +14,7 @@ const TEST_WEB_IDE_URL = '/-/ide/project/gitlab-test/test/edit/main/-/'; ...@@ -13,6 +14,7 @@ const TEST_WEB_IDE_URL = '/-/ide/project/gitlab-test/test/edit/main/-/';
const TEST_GITPOD_URL = 'https://gitpod.test/'; const TEST_GITPOD_URL = 'https://gitpod.test/';
const TEST_USER_PREFERENCES_GITPOD_PATH = '/-/profile/preferences#user_gitpod_enabled'; const TEST_USER_PREFERENCES_GITPOD_PATH = '/-/profile/preferences#user_gitpod_enabled';
const TEST_USER_PROFILE_ENABLE_GITPOD_PATH = '/-/profile?user%5Bgitpod_enabled%5D=true'; const TEST_USER_PROFILE_ENABLE_GITPOD_PATH = '/-/profile?user%5Bgitpod_enabled%5D=true';
const forkPath = '/some/fork/path';
const ACTION_EDIT = { const ACTION_EDIT = {
href: TEST_EDIT_URL, href: TEST_EDIT_URL,
...@@ -74,6 +76,7 @@ describe('Web IDE link component', () => { ...@@ -74,6 +76,7 @@ describe('Web IDE link component', () => {
editUrl: TEST_EDIT_URL, editUrl: TEST_EDIT_URL,
webIdeUrl: TEST_WEB_IDE_URL, webIdeUrl: TEST_WEB_IDE_URL,
gitpodUrl: TEST_GITPOD_URL, gitpodUrl: TEST_GITPOD_URL,
forkPath,
...props, ...props,
}, },
stubs: { stubs: {
...@@ -96,6 +99,7 @@ describe('Web IDE link component', () => { ...@@ -96,6 +99,7 @@ describe('Web IDE link component', () => {
const findActionsButton = () => wrapper.find(ActionsButton); const findActionsButton = () => wrapper.find(ActionsButton);
const findLocalStorageSync = () => wrapper.find(LocalStorageSync); const findLocalStorageSync = () => wrapper.find(LocalStorageSync);
const findModal = () => wrapper.findComponent(GlModal); const findModal = () => wrapper.findComponent(GlModal);
const findForkConfirmModal = () => wrapper.findComponent(ConfirmForkModal);
it.each([ it.each([
{ {
...@@ -231,16 +235,28 @@ describe('Web IDE link component', () => { ...@@ -231,16 +235,28 @@ describe('Web IDE link component', () => {
}); });
describe('edit actions', () => { describe('edit actions', () => {
it.each([ const testActions = [
{ {
props: { showWebIdeButton: true, showEditButton: false }, props: {
showWebIdeButton: true,
showEditButton: false,
forkPath,
forkModalId: 'edit-modal',
},
expectedEventPayload: 'ide', expectedEventPayload: 'ide',
}, },
{ {
props: { showWebIdeButton: false, showEditButton: true }, props: {
showWebIdeButton: false,
showEditButton: true,
forkPath,
forkModalId: 'webide-modal',
},
expectedEventPayload: 'simple', expectedEventPayload: 'simple',
}, },
])( ];
it.each(testActions)(
'emits the correct event when an action handler is called', 'emits the correct event when an action handler is called',
async ({ props, expectedEventPayload }) => { async ({ props, expectedEventPayload }) => {
createComponent({ ...props, needsToFork: true, disableForkModal: true }); createComponent({ ...props, needsToFork: true, disableForkModal: true });
...@@ -250,6 +266,29 @@ describe('Web IDE link component', () => { ...@@ -250,6 +266,29 @@ describe('Web IDE link component', () => {
expect(wrapper.emitted('edit')).toEqual([[expectedEventPayload]]); expect(wrapper.emitted('edit')).toEqual([[expectedEventPayload]]);
}, },
); );
it.each(testActions)('renders the fork confirmation modal', async ({ props }) => {
createComponent({ ...props, needsToFork: true });
expect(findForkConfirmModal().exists()).toBe(true);
expect(findForkConfirmModal().props()).toEqual({
isVisible: false,
forkPath,
modalId: props.forkModalId,
});
});
it.each(testActions)('opens the modal when the button is clicked', async ({ props }) => {
createComponent({ ...props, needsToFork: true }, mountExtended);
await findActionsButton().trigger('click');
expect(findForkConfirmModal().props()).toEqual({
isVisible: true,
forkPath,
modalId: props.forkModalId,
});
});
}); });
describe('when Gitpod is not enabled', () => { describe('when Gitpod is not enabled', () => {
......
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