Dispatcharr/frontend/src/utils/cards/__tests__/PluginCardUtils.test.js
Nick Sandstrom 93f74c9d91 Squashed commit of the following:
commit df18a89d0562edc8fd8fb5bc4cac702aefb5272c
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sat Jan 10 19:18:23 2026 -0800

    Updated tests

commit 90240344b89717fbad0e16fe209dbf00c567b1a8
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Jan 4 03:18:41 2026 -0800

    Updated tests

commit 525b7cb32bc8d235613706d6795795a0177ea24b
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Jan 4 03:18:31 2026 -0800

    Extracted component and util logic

commit e54ea2c3173c0ce3cfb0a2d70d76fdd0a66accc8
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 31 11:55:40 2025 -0800

    Updated tests

commit 5cbe164cb9818d8eab607af037da5faee2c1556f
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 31 11:55:14 2025 -0800

    Minor changes

    Exporting UiSettingsForm as default
    Reverted admin level type check

commit f9ab0d2a06091a2eed3ee6f34268c81bfd746f1e
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 30 23:31:29 2025 -0800

    Extracted component and util logic

commit a705a4db4a32d0851d087a984111837a0a83f722
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Dec 28 00:47:29 2025 -0800

    Updated tests

commit a72c6720a3980d0f279edf050b6b51eaae11cdbd
Merge: e8dcab6f 43525ca3
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Dec 28 00:04:24 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit e8dcab6f832570cb986f114cfa574db4994b3aab
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sat Dec 27 22:35:59 2025 -0800

    Updated tests

commit 0fd230503844fba0c418ab0a03c46dc878697a55
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sat Dec 27 22:35:53 2025 -0800

    Added plugins store

commit d987f2de72272f24e26b1ed5bc04bb5c83033868
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sat Dec 27 22:35:43 2025 -0800

    Extracted component and util logic

commit 5a3138370a468a99c9f1ed0a36709a173656d809
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 24 23:13:07 2025 -0800

    Lazy-loading button modals

commit ac6945b5b55e0e16d050d4412a20c82f19250c4b
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 24 22:41:51 2025 -0800

    Extracted notification util

commit befe159fc06b67ee415f7498b5400fee0dc82528
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 24 22:28:12 2025 -0800

    Extracted component and util logic

commit ec10a3a4200a0c94cae29691a9fe06e5c4317bb7
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 24 22:22:09 2025 -0800

    Updated tests

commit c1c7214c8589c0ce7645ea24418d9dd978ac8c1f
Merge: eba6dce7 9c9cbab9
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 23 12:41:25 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit eba6dce786495e352d4696030500db41d028036e
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Dec 21 10:12:19 2025 -0800

    Updated style props

commit 2024b0b267b849a5f100e5543b9188e8ad6dd3d9
Merge: b3700956 1029eb5b
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Sun Dec 21 09:27:21 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit b3700956a4c2f473f1e977826f9537d27ea018ae
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Thu Dec 18 07:45:36 2025 -0800

    Reverted Channels change

commit 137cbb02473b7f2f41488601e3b64e5ff45ac656
Merge: 644ed001 2a0df81c
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 17 13:36:05 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit 644ed00196c41eaa44df1b98236b7e5cc3124d82
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Wed Dec 17 13:29:13 2025 -0800

    Updated tests

commit c62d1bd0534aa19be99b8f87232ba872420111a0
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 14:12:31 2025 -0800

    Updated tests

commit 0cc0ee31d5ad84c59d8eba9fc4424f118f5e0ee2
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 13:44:55 2025 -0800

    Extracted component and util logic

commit 25d1b112af250b5ccebb1006511bff8e4387fc76
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 13:44:11 2025 -0800

    Added correct import for Text component

commit d8a04c6c09edf158220d3073939c9fb60069745c
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 13:43:55 2025 -0800

    Fixed component syntax

commit 59e35d3a4d0da8ed8476560cedacadf76162ea43
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 13:43:39 2025 -0800

    Fixed cache_url fallback

commit d2a170d2efd3d2b0e6078c9eebeb8dcea237be3b
Merge: b8f7e435 6c1b0f9a
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Tue Dec 16 12:00:45 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit b8f7e4358a23f2e3a902929b57ab7a7d115241c5
Merge: 5b12c68a d97f0c90
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Mon Dec 15 07:42:06 2025 -0800

    Merge branch 'enhancement/component-cleanup' into test/component-cleanup

commit 5b12c68ab8ce429adc8d1355632aa411007d365b
Merge: eff58126 c63cb75b
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Mon Dec 8 16:56:14 2025 -0800

    Merge branch 'enhancement/unit-tests' into stage

commit eff58126fb6aba4ebe9a0c67eee65773bffb8ae9
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Mon Dec 8 16:49:43 2025 -0800

    Update .gitignore

commit c63cb75b8cad204d48a392a28d8a5bdf8c270496
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Mon Dec 8 16:28:03 2025 -0800

    Added unit tests for pages

commit 75306a6181ddeb2eaeb306387ba2b44c7fcfd5e3
Author: Nick Sandstrom <32273437+nick4810@users.noreply.github.com>
Date:   Mon Dec 8 16:27:19 2025 -0800

    Added Actions workflow
2026-01-10 19:36:23 -08:00

158 lines
4.9 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import {
getConfirmationDetails,
} from '../PluginCardUtils';
describe('PluginCardUtils', () => {
describe('getConfirmationDetails', () => {
it('requires confirmation when action.confirm is true', () => {
const action = { label: 'Test Action', confirm: true };
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result).toEqual({
requireConfirm: true,
confirmTitle: 'Run Test Action?',
confirmMessage: 'You\'re about to run "Test Action" from "Test Plugin".',
});
});
it('does not require confirmation when action.confirm is false', () => {
const action = { label: 'Test Action', confirm: false };
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(false);
});
it('uses custom title and message from action.confirm object', () => {
const action = {
label: 'Test Action',
confirm: {
required: true,
title: 'Custom Title',
message: 'Custom message',
},
};
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result).toEqual({
requireConfirm: true,
confirmTitle: 'Custom Title',
confirmMessage: 'Custom message',
});
});
it('requires confirmation when action.confirm.required is not explicitly false', () => {
const action = {
label: 'Test Action',
confirm: {
title: 'Custom Title',
},
};
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(true);
});
it('does not require confirmation when action.confirm.required is false', () => {
const action = {
label: 'Test Action',
confirm: {
required: false,
title: 'Custom Title',
},
};
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(false);
});
it('uses confirm field from plugin when action.confirm is undefined', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: true }],
};
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(true);
});
it('uses settings value over field default', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: false }],
};
const settings = { confirm: true };
const result = getConfirmationDetails(action, plugin, settings);
expect(result.requireConfirm).toBe(true);
});
it('uses field default when settings value is undefined', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: true }],
};
const settings = {};
const result = getConfirmationDetails(action, plugin, settings);
expect(result.requireConfirm).toBe(true);
});
it('does not require confirmation when no confirm configuration exists', () => {
const action = { label: 'Test Action' };
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(false);
});
it('handles plugin without fields array', () => {
const action = { label: 'Test Action' };
const plugin = { name: 'Test Plugin' };
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(false);
});
it('handles null or undefined settings', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: true }],
};
const result = getConfirmationDetails(action, plugin, null);
expect(result.requireConfirm).toBe(true);
});
it('converts truthy confirm field values to boolean', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: 1 }],
};
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(true);
});
it('handles confirm field with null default', () => {
const action = { label: 'Test Action' };
const plugin = {
name: 'Test Plugin',
fields: [{ id: 'confirm', default: null }],
};
const result = getConfirmationDetails(action, plugin, {});
expect(result.requireConfirm).toBe(false);
});
});
});