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:
Diffstat (limited to 'spec/frontend/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal_spec.js')
-rw-r--r--spec/frontend/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal_spec.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal_spec.js b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal_spec.js
new file mode 100644
index 00000000000..6966c79b232
--- /dev/null
+++ b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal_spec.js
@@ -0,0 +1,80 @@
+import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
+import { confirmViaGlModal } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
+import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_action';
+
+jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_action');
+
+describe('confirmViaGlModal', () => {
+ let el;
+
+ afterEach(() => {
+ el = undefined;
+ resetHTMLFixture();
+ jest.resetAllMocks();
+ });
+
+ const createElement = (html) => {
+ setHTMLFixture(html);
+ return document.body.firstChild;
+ };
+
+ it('returns confirmAction result', async () => {
+ confirmAction.mockReturnValue(Promise.resolve(true));
+ el = createElement(`<div/>`);
+
+ await expect(confirmViaGlModal('', el)).resolves.toBe(true);
+ });
+
+ it('calls confirmAction with message', () => {
+ el = createElement(`<div/>`);
+
+ confirmViaGlModal('message', el);
+
+ expect(confirmAction).toHaveBeenCalledWith('message', {});
+ });
+
+ it.each(['gl-sr-only', 'sr-only'])(
+ `uses slot.%s contentText as primaryBtnText`,
+ (srOnlyClass) => {
+ el = createElement(
+ `<a href="#"><span class="${srOnlyClass}">Delete merge request</span></a>`,
+ );
+
+ confirmViaGlModal('', el);
+
+ expect(confirmAction).toHaveBeenCalledWith('', {
+ primaryBtnText: 'Delete merge request',
+ });
+ },
+ );
+
+ it('uses `aria-label` value as `primaryBtnText`', () => {
+ el = createElement(`<a aria-label="Delete merge request" href="#"></a>`);
+
+ confirmViaGlModal('', el);
+
+ expect(confirmAction).toHaveBeenCalledWith('', {
+ primaryBtnText: 'Delete merge request',
+ });
+ });
+
+ it.each([
+ ['title', 'title', 'Delete?'],
+ ['confirm-btn-variant', `primaryBtnVariant`, 'danger'],
+ ])('uses data-%s value as confirmAction config', (dataKey, configKey, value) => {
+ el = createElement(`<a data-${dataKey}="${value}" href="#"></a>`);
+
+ confirmViaGlModal('message', el);
+
+ expect(confirmAction).toHaveBeenCalledWith('message', { [configKey]: value });
+ });
+
+ it('uses message as modalHtmlMessage value when data-is-html-message is true', () => {
+ el = createElement(`<a data-is-html-message="true" href="#"></a>`);
+ const message = 'Hola mundo!';
+
+ confirmViaGlModal(message, el);
+
+ expect(confirmAction).toHaveBeenCalledWith(message, { modalHtmlMessage: message });
+ });
+});