Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/projects/components/shared
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/projects/components/shared')
-rw-r--r--spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap113
-rw-r--r--spec/frontend/projects/components/shared/delete_button_spec.js83
2 files changed, 196 insertions, 0 deletions
diff --git a/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap b/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap
new file mode 100644
index 00000000000..a43acc8c002
--- /dev/null
+++ b/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap
@@ -0,0 +1,113 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Project remove modal intialized matches the snapshot 1`] = `
+<form
+ action="some/path"
+ method="post"
+>
+ <input
+ name="_method"
+ type="hidden"
+ value="delete"
+ />
+
+ <input
+ name="authenticity_token"
+ type="hidden"
+ value="test-csrf-token"
+ />
+
+ <gl-button-stub
+ category="primary"
+ icon=""
+ role="button"
+ size="medium"
+ tabindex="0"
+ variant="danger"
+ >
+ Delete project
+ </gl-button-stub>
+
+ <b-modal-stub
+ canceltitle="Cancel"
+ cancelvariant="secondary"
+ footerclass="gl-bg-gray-10 gl-p-5"
+ headerclosecontent="&times;"
+ headercloselabel="Close"
+ id="delete-project-modal-2"
+ ignoreenforcefocusselector=""
+ lazy="true"
+ modalclass="gl-modal,"
+ oktitle="OK"
+ okvariant="danger"
+ size="sm"
+ title=""
+ titleclass="gl-text-red-500"
+ titletag="h4"
+ >
+
+ <div>
+
+ <p
+ class="gl-mb-1"
+ >
+ Please type the following to confirm:
+ </p>
+
+ <p>
+ <code>
+ foo
+ </code>
+ </p>
+
+ <gl-form-input-stub
+ id="confirm_name_input"
+ name="confirm_name_input"
+ type="text"
+ />
+
+ </div>
+
+ <template />
+
+ <template>
+ Delete project. Are you ABSOLUTELY SURE?
+ </template>
+
+ <template />
+
+ <template />
+
+ <template />
+
+ <template>
+ <gl-button-stub
+ category="primary"
+ class="js-modal-action-cancel"
+ icon=""
+ size="medium"
+ variant="default"
+ >
+
+ Cancel, keep project
+
+ </gl-button-stub>
+
+ <!---->
+
+ <gl-button-stub
+ category="primary"
+ class="js-modal-action-primary"
+ disabled="true"
+ icon=""
+ size="medium"
+ variant="danger"
+ >
+
+ Yes, delete project
+
+ </gl-button-stub>
+ </template>
+ </b-modal-stub>
+</form>
+`;
diff --git a/spec/frontend/projects/components/shared/delete_button_spec.js b/spec/frontend/projects/components/shared/delete_button_spec.js
new file mode 100644
index 00000000000..a6394a50011
--- /dev/null
+++ b/spec/frontend/projects/components/shared/delete_button_spec.js
@@ -0,0 +1,83 @@
+import { shallowMount } from '@vue/test-utils';
+import { GlModal } from '@gitlab/ui';
+import SharedDeleteButton from '~/projects/components/shared/delete_button.vue';
+
+jest.mock('~/lib/utils/csrf', () => ({ token: 'test-csrf-token' }));
+
+describe('Project remove modal', () => {
+ let wrapper;
+
+ const findFormElement = () => wrapper.find('form');
+ const findConfirmButton = () => wrapper.find('.js-modal-action-primary');
+ const findAuthenticityTokenInput = () => findFormElement().find('input[name=authenticity_token]');
+ const findModal = () => wrapper.find(GlModal);
+
+ const defaultProps = {
+ confirmPhrase: 'foo',
+ formPath: 'some/path',
+ };
+
+ const createComponent = (data = {}) => {
+ wrapper = shallowMount(SharedDeleteButton, {
+ propsData: defaultProps,
+ data: () => data,
+ stubs: {
+ GlModal,
+ },
+ });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ describe('intialized', () => {
+ beforeEach(() => {
+ createComponent();
+ });
+
+ it('matches the snapshot', () => {
+ expect(wrapper.element).toMatchSnapshot();
+ });
+
+ it('sets a csrf token on the authenticity form input', () => {
+ expect(findAuthenticityTokenInput().element.value).toEqual('test-csrf-token');
+ });
+
+ it('sets the form action to the provided path', () => {
+ expect(findFormElement().attributes('action')).toEqual(defaultProps.formPath);
+ });
+ });
+
+ describe('when the user input does not match the confirmPhrase', () => {
+ beforeEach(() => {
+ createComponent({ userInput: 'bar' });
+ });
+
+ it('the confirm button is disabled', () => {
+ expect(findConfirmButton().attributes('disabled')).toBe('true');
+ });
+ });
+
+ describe('when the user input matches the confirmPhrase', () => {
+ beforeEach(() => {
+ createComponent({ userInput: defaultProps.confirmPhrase });
+ });
+
+ it('the confirm button is not disabled', () => {
+ expect(findConfirmButton().attributes('disabled')).toBe(undefined);
+ });
+ });
+
+ describe('when the modal is confirmed', () => {
+ beforeEach(() => {
+ createComponent();
+ findModal().vm.$emit('ok');
+ });
+
+ it('submits the form element', () => {
+ expect(findFormElement().element.submit).toHaveBeenCalled();
+ });
+ });
+});