@wordpress/abilities 0.1.1-next.dc3f6d3c1.0 → 0.2.1-next.8b30e05b0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,792 +0,0 @@
1
- "use strict";
2
-
3
- // packages/abilities/src/store/tests/actions.test.ts
4
- var import_data = require("@wordpress/data");
5
- var import_actions = require("../actions");
6
- var import_constants = require("../constants");
7
- jest.mock("@wordpress/data", () => ({
8
- resolveSelect: jest.fn()
9
- }));
10
- describe("Store Actions", () => {
11
- describe("receiveAbilities", () => {
12
- it("should create an action to receive abilities", () => {
13
- const abilities = [
14
- {
15
- name: "test/ability1",
16
- label: "Test Ability 1",
17
- description: "First test ability",
18
- category: "test-category",
19
- input_schema: { type: "object" },
20
- output_schema: { type: "object" }
21
- },
22
- {
23
- name: "test/ability2",
24
- label: "Test Ability 2",
25
- description: "Second test ability",
26
- category: "test-category",
27
- input_schema: { type: "object" },
28
- output_schema: { type: "object" }
29
- }
30
- ];
31
- const action = (0, import_actions.receiveAbilities)(abilities);
32
- expect(action).toEqual({
33
- type: import_constants.RECEIVE_ABILITIES,
34
- abilities
35
- });
36
- });
37
- it("should handle empty abilities array", () => {
38
- const abilities = [];
39
- const action = (0, import_actions.receiveAbilities)(abilities);
40
- expect(action).toEqual({
41
- type: import_constants.RECEIVE_ABILITIES,
42
- abilities: []
43
- });
44
- });
45
- });
46
- describe("registerAbility", () => {
47
- let mockSelect;
48
- let mockDispatch;
49
- beforeEach(() => {
50
- jest.clearAllMocks();
51
- const defaultCategories = [
52
- {
53
- slug: "test-category",
54
- label: "Test Category",
55
- description: "Test category for testing"
56
- },
57
- {
58
- slug: "data-retrieval",
59
- label: "Data Retrieval",
60
- description: "Abilities that retrieve data"
61
- }
62
- ];
63
- mockSelect = {
64
- getAbility: jest.fn().mockReturnValue(null),
65
- getAbilityCategories: jest.fn().mockReturnValue(defaultCategories),
66
- getAbilityCategory: jest.fn().mockImplementation((slug) => {
67
- const categories = {
68
- "test-category": {
69
- slug: "test-category",
70
- label: "Test Category",
71
- description: "Test category for testing"
72
- },
73
- "data-retrieval": {
74
- slug: "data-retrieval",
75
- label: "Data Retrieval",
76
- description: "Abilities that retrieve data"
77
- }
78
- };
79
- return categories[slug] || null;
80
- })
81
- };
82
- mockDispatch = jest.fn();
83
- import_data.resolveSelect.mockReturnValue({
84
- getAbilityCategories: jest.fn().mockResolvedValue(defaultCategories)
85
- });
86
- });
87
- it("should register a valid client ability", async () => {
88
- const ability = {
89
- name: "test/ability",
90
- label: "Test Ability",
91
- description: "Test ability description",
92
- category: "test-category",
93
- input_schema: {
94
- type: "object",
95
- properties: {
96
- message: { type: "string" }
97
- }
98
- },
99
- output_schema: {
100
- type: "object",
101
- properties: {
102
- success: { type: "boolean" }
103
- }
104
- },
105
- callback: jest.fn()
106
- };
107
- const action = (0, import_actions.registerAbility)(ability);
108
- await action({ select: mockSelect, dispatch: mockDispatch });
109
- expect(mockDispatch).toHaveBeenCalledWith({
110
- type: import_constants.REGISTER_ABILITY,
111
- ability
112
- });
113
- });
114
- it("should register server-side abilities", async () => {
115
- const ability = {
116
- name: "test/server-ability",
117
- label: "Server Ability",
118
- description: "Server-side ability",
119
- category: "test-category",
120
- input_schema: { type: "object" },
121
- output_schema: { type: "object" }
122
- };
123
- const action = (0, import_actions.registerAbility)(ability);
124
- await action({ select: mockSelect, dispatch: mockDispatch });
125
- expect(mockDispatch).toHaveBeenCalledWith({
126
- type: import_constants.REGISTER_ABILITY,
127
- ability
128
- });
129
- });
130
- it("should validate and reject ability without name", async () => {
131
- const ability = {
132
- name: "",
133
- label: "Test Ability",
134
- description: "Test description",
135
- category: "test-category",
136
- callback: jest.fn()
137
- };
138
- const action = (0, import_actions.registerAbility)(ability);
139
- await expect(
140
- action({ select: mockSelect, dispatch: mockDispatch })
141
- ).rejects.toThrow("Ability name is required");
142
- expect(mockDispatch).not.toHaveBeenCalled();
143
- });
144
- it("should validate and reject ability with invalid name format", async () => {
145
- const testCases = [
146
- "invalid",
147
- // No namespace
148
- "my-plugin/feature/action",
149
- // Multiple slashes
150
- "My-Plugin/feature",
151
- // Uppercase letters
152
- "my_plugin/feature",
153
- // Underscores not allowed
154
- "my-plugin/feature!",
155
- // Special characters not allowed
156
- "my plugin/feature"
157
- // Spaces not allowed
158
- ];
159
- for (const invalidName of testCases) {
160
- const ability = {
161
- name: invalidName,
162
- label: "Test Ability",
163
- description: "Test description",
164
- category: "test-category",
165
- callback: jest.fn()
166
- };
167
- const action = (0, import_actions.registerAbility)(ability);
168
- await expect(
169
- action({ select: mockSelect, dispatch: mockDispatch })
170
- ).rejects.toThrow(
171
- "Ability name must be a string containing a namespace prefix"
172
- );
173
- expect(mockDispatch).not.toHaveBeenCalled();
174
- mockDispatch.mockClear();
175
- }
176
- });
177
- it("should validate and reject ability without label", async () => {
178
- const ability = {
179
- name: "test/ability",
180
- label: "",
181
- description: "Test description",
182
- category: "test-category",
183
- callback: jest.fn()
184
- };
185
- const action = (0, import_actions.registerAbility)(ability);
186
- await expect(
187
- action({ select: mockSelect, dispatch: mockDispatch })
188
- ).rejects.toThrow('Ability "test/ability" must have a label');
189
- expect(mockDispatch).not.toHaveBeenCalled();
190
- });
191
- it("should validate and reject ability without description", async () => {
192
- const ability = {
193
- name: "test/ability",
194
- label: "Test Ability",
195
- description: "",
196
- category: "test-category",
197
- callback: jest.fn()
198
- };
199
- const action = (0, import_actions.registerAbility)(ability);
200
- await expect(
201
- action({ select: mockSelect, dispatch: mockDispatch })
202
- ).rejects.toThrow(
203
- 'Ability "test/ability" must have a description'
204
- );
205
- expect(mockDispatch).not.toHaveBeenCalled();
206
- });
207
- it("should validate and reject ability without category", async () => {
208
- const ability = {
209
- name: "test/ability",
210
- label: "Test Ability",
211
- description: "Test description",
212
- category: "",
213
- callback: jest.fn()
214
- };
215
- const action = (0, import_actions.registerAbility)(ability);
216
- await expect(
217
- action({ select: mockSelect, dispatch: mockDispatch })
218
- ).rejects.toThrow('Ability "test/ability" must have a category');
219
- expect(mockDispatch).not.toHaveBeenCalled();
220
- });
221
- it("should validate and reject ability with invalid category format", async () => {
222
- const testCases = [
223
- "Data-Retrieval",
224
- // Uppercase letters
225
- "data_retrieval",
226
- // Underscores not allowed
227
- "data.retrieval",
228
- // Dots not allowed
229
- "data/retrieval",
230
- // Slashes not allowed
231
- "-data-retrieval",
232
- // Leading dash
233
- "data-retrieval-",
234
- // Trailing dash
235
- "data--retrieval"
236
- // Double dash
237
- ];
238
- for (const invalidCategory of testCases) {
239
- const ability = {
240
- name: "test/ability",
241
- label: "Test Ability",
242
- description: "Test description",
243
- category: invalidCategory,
244
- callback: jest.fn()
245
- };
246
- const action = (0, import_actions.registerAbility)(ability);
247
- await expect(
248
- action({ select: mockSelect, dispatch: mockDispatch })
249
- ).rejects.toThrow(
250
- 'Ability "test/ability" has an invalid category. Category must be lowercase alphanumeric with dashes only'
251
- );
252
- expect(mockDispatch).not.toHaveBeenCalled();
253
- mockDispatch.mockClear();
254
- }
255
- });
256
- it("should accept ability with valid category format", async () => {
257
- const validCategories = [
258
- "data-retrieval",
259
- "user-management",
260
- "analytics-123",
261
- "ecommerce"
262
- ];
263
- for (const validCategory of validCategories) {
264
- const ability = {
265
- name: "test/ability-" + validCategory,
266
- label: "Test Ability",
267
- description: "Test description",
268
- category: validCategory,
269
- callback: jest.fn()
270
- };
271
- const categoriesForTest = [
272
- {
273
- slug: "test-category",
274
- label: "Test Category",
275
- description: "Test category for testing"
276
- },
277
- {
278
- slug: "data-retrieval",
279
- label: "Data Retrieval",
280
- description: "Abilities that retrieve data"
281
- },
282
- {
283
- slug: validCategory,
284
- label: "Test Category",
285
- description: "Test"
286
- }
287
- ];
288
- mockSelect.getAbilityCategories.mockReturnValue(
289
- categoriesForTest
290
- );
291
- import_data.resolveSelect.mockReturnValue({
292
- getAbilityCategories: jest.fn().mockResolvedValue(categoriesForTest)
293
- });
294
- mockSelect.getAbility.mockReturnValue(null);
295
- mockDispatch.mockClear();
296
- const action = (0, import_actions.registerAbility)(ability);
297
- await action({ select: mockSelect, dispatch: mockDispatch });
298
- expect(mockDispatch).toHaveBeenCalledWith({
299
- type: import_constants.REGISTER_ABILITY,
300
- ability
301
- });
302
- }
303
- });
304
- it("should validate and reject ability with non-existent category", async () => {
305
- mockSelect.getAbilityCategories.mockReturnValue([
306
- {
307
- slug: "test-category",
308
- label: "Test Category",
309
- description: "Test category for testing"
310
- },
311
- {
312
- slug: "data-retrieval",
313
- label: "Data Retrieval",
314
- description: "Abilities that retrieve data"
315
- }
316
- ]);
317
- const ability = {
318
- name: "test/ability",
319
- label: "Test Ability",
320
- description: "Test description",
321
- category: "non-existent-category",
322
- callback: jest.fn()
323
- };
324
- const action = (0, import_actions.registerAbility)(ability);
325
- await expect(
326
- action({ select: mockSelect, dispatch: mockDispatch })
327
- ).rejects.toThrow(
328
- 'Ability "test/ability" references non-existent category "non-existent-category". Please register the category first.'
329
- );
330
- expect(mockDispatch).not.toHaveBeenCalled();
331
- });
332
- it("should accept ability with existing category", async () => {
333
- const categoriesForTest = [
334
- {
335
- slug: "test-category",
336
- label: "Test Category",
337
- description: "Test category for testing"
338
- },
339
- {
340
- slug: "data-retrieval",
341
- label: "Data Retrieval",
342
- description: "Abilities that retrieve data"
343
- }
344
- ];
345
- mockSelect.getAbilityCategories.mockReturnValue(
346
- categoriesForTest
347
- );
348
- import_data.resolveSelect.mockReturnValue({
349
- getAbilityCategories: jest.fn().mockResolvedValue(categoriesForTest)
350
- });
351
- const ability = {
352
- name: "test/ability",
353
- label: "Test Ability",
354
- description: "Test description",
355
- category: "data-retrieval",
356
- callback: jest.fn()
357
- };
358
- const action = (0, import_actions.registerAbility)(ability);
359
- await action({ select: mockSelect, dispatch: mockDispatch });
360
- expect(import_data.resolveSelect).toHaveBeenCalledWith("core/abilities");
361
- expect(mockDispatch).toHaveBeenCalledWith({
362
- type: import_constants.REGISTER_ABILITY,
363
- ability
364
- });
365
- });
366
- it("should validate and reject ability with invalid callback", async () => {
367
- const ability = {
368
- name: "test/ability",
369
- label: "Test Ability",
370
- description: "Test description",
371
- category: "test-category",
372
- callback: "not a function"
373
- };
374
- const action = (0, import_actions.registerAbility)(ability);
375
- await expect(
376
- action({ select: mockSelect, dispatch: mockDispatch })
377
- ).rejects.toThrow(
378
- 'Ability "test/ability" has an invalid callback. Callback must be a function'
379
- );
380
- expect(mockDispatch).not.toHaveBeenCalled();
381
- });
382
- it("should validate and reject already registered ability", async () => {
383
- const existingAbility = {
384
- name: "test/ability",
385
- label: "Existing Ability",
386
- description: "Already registered",
387
- category: "test-category"
388
- };
389
- mockSelect.getAbility.mockReturnValue(existingAbility);
390
- const ability = {
391
- name: "test/ability",
392
- label: "Test Ability",
393
- description: "Test description",
394
- category: "test-category",
395
- callback: jest.fn()
396
- };
397
- const action = (0, import_actions.registerAbility)(ability);
398
- await expect(
399
- action({ select: mockSelect, dispatch: mockDispatch })
400
- ).rejects.toThrow('Ability "test/ability" is already registered');
401
- expect(mockDispatch).not.toHaveBeenCalled();
402
- });
403
- it("should load categories using resolveSelect before validation", async () => {
404
- const categories = [
405
- {
406
- slug: "test-category",
407
- label: "Test Category",
408
- description: "Test category"
409
- }
410
- ];
411
- import_data.resolveSelect.mockReturnValue({
412
- getAbilityCategories: jest.fn().mockResolvedValue(categories)
413
- });
414
- const ability = {
415
- name: "test/ability",
416
- label: "Test Ability",
417
- description: "Test description",
418
- category: "test-category",
419
- callback: jest.fn()
420
- };
421
- const action = (0, import_actions.registerAbility)(ability);
422
- await action({ select: mockSelect, dispatch: mockDispatch });
423
- expect(import_data.resolveSelect).toHaveBeenCalledWith("core/abilities");
424
- expect(mockDispatch).toHaveBeenCalledWith({
425
- type: import_constants.REGISTER_ABILITY,
426
- ability
427
- });
428
- });
429
- });
430
- describe("unregisterAbility", () => {
431
- it("should create an action to unregister an ability", () => {
432
- const abilityName = "test/ability";
433
- const action = (0, import_actions.unregisterAbility)(abilityName);
434
- expect(action).toEqual({
435
- type: import_constants.UNREGISTER_ABILITY,
436
- name: abilityName
437
- });
438
- });
439
- it("should handle valid namespaced ability names", () => {
440
- const abilityName = "my-plugin/feature-action";
441
- const action = (0, import_actions.unregisterAbility)(abilityName);
442
- expect(action).toEqual({
443
- type: import_constants.UNREGISTER_ABILITY,
444
- name: abilityName
445
- });
446
- });
447
- });
448
- describe("receiveCategories", () => {
449
- it("should create an action to receive categories", () => {
450
- const categories = [
451
- {
452
- slug: "data-retrieval",
453
- label: "Data Retrieval",
454
- description: "Abilities that retrieve data"
455
- },
456
- {
457
- slug: "user-management",
458
- label: "User Management",
459
- description: "Abilities for managing users"
460
- }
461
- ];
462
- const action = (0, import_actions.receiveCategories)(categories);
463
- expect(action).toEqual({
464
- type: import_constants.RECEIVE_CATEGORIES,
465
- categories
466
- });
467
- });
468
- it("should handle empty categories array", () => {
469
- const categories = [];
470
- const action = (0, import_actions.receiveCategories)(categories);
471
- expect(action).toEqual({
472
- type: import_constants.RECEIVE_CATEGORIES,
473
- categories: []
474
- });
475
- });
476
- });
477
- describe("registerAbilityCategory", () => {
478
- let mockSelect;
479
- let mockDispatch;
480
- beforeEach(() => {
481
- jest.clearAllMocks();
482
- mockSelect = {
483
- getAbilityCategory: jest.fn().mockReturnValue(null),
484
- getAbilityCategories: jest.fn().mockReturnValue([])
485
- };
486
- mockDispatch = jest.fn();
487
- import_data.resolveSelect.mockReturnValue({
488
- getAbilityCategories: jest.fn().mockResolvedValue(void 0)
489
- });
490
- });
491
- it("should register a valid category", async () => {
492
- const slug = "test-category";
493
- const args = {
494
- label: "Test Category",
495
- description: "A test category for testing"
496
- };
497
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
498
- await action({ select: mockSelect, dispatch: mockDispatch });
499
- expect(mockDispatch).toHaveBeenCalledWith({
500
- type: import_constants.REGISTER_ABILITY_CATEGORY,
501
- category: {
502
- slug,
503
- label: args.label,
504
- description: args.description,
505
- meta: {
506
- _clientRegistered: true
507
- }
508
- }
509
- });
510
- });
511
- it("should register a category with meta", async () => {
512
- const slug = "test-category";
513
- const args = {
514
- label: "Test Category",
515
- description: "A test category",
516
- meta: { foo: "bar", nested: { key: "value" } }
517
- };
518
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
519
- await action({ select: mockSelect, dispatch: mockDispatch });
520
- expect(mockDispatch).toHaveBeenCalledWith({
521
- type: import_constants.REGISTER_ABILITY_CATEGORY,
522
- category: {
523
- slug,
524
- label: args.label,
525
- description: args.description,
526
- meta: {
527
- ...args.meta,
528
- _clientRegistered: true
529
- }
530
- }
531
- });
532
- });
533
- it("should validate and reject empty slug", async () => {
534
- const args = {
535
- label: "Test",
536
- description: "Test"
537
- };
538
- const action = (0, import_actions.registerAbilityCategory)("", args);
539
- await expect(
540
- action({ select: mockSelect, dispatch: mockDispatch })
541
- ).rejects.toThrow("Category slug is required");
542
- expect(mockDispatch).not.toHaveBeenCalled();
543
- });
544
- it("should validate and reject invalid slug formats", async () => {
545
- const testCases = [
546
- "Data-Retrieval",
547
- // Uppercase
548
- "data_retrieval",
549
- // Underscores
550
- "data.retrieval",
551
- // Dots
552
- "data/retrieval",
553
- // Slashes
554
- "-data-retrieval",
555
- // Leading dash
556
- "data-retrieval-",
557
- // Trailing dash
558
- "data--retrieval",
559
- // Double dash
560
- "data retrieval",
561
- // Spaces
562
- "data!retrieval"
563
- // Special characters
564
- ];
565
- const args = {
566
- label: "Test",
567
- description: "Test"
568
- };
569
- for (const invalidSlug of testCases) {
570
- const action = (0, import_actions.registerAbilityCategory)(invalidSlug, args);
571
- await expect(
572
- action({ select: mockSelect, dispatch: mockDispatch })
573
- ).rejects.toThrow(
574
- "Category slug must contain only lowercase alphanumeric characters and dashes"
575
- );
576
- expect(mockDispatch).not.toHaveBeenCalled();
577
- mockDispatch.mockClear();
578
- }
579
- });
580
- it("should accept valid slug formats", async () => {
581
- const validSlugs = [
582
- "data-retrieval",
583
- "user-management",
584
- "analytics-123",
585
- "ecommerce",
586
- "a",
587
- "123",
588
- "test-multiple-words-with-dashes"
589
- ];
590
- const args = {
591
- label: "Test Category",
592
- description: "Test description"
593
- };
594
- for (const validSlug of validSlugs) {
595
- mockSelect.getAbilityCategory.mockReturnValue(null);
596
- mockDispatch.mockClear();
597
- const action = (0, import_actions.registerAbilityCategory)(validSlug, args);
598
- await action({ select: mockSelect, dispatch: mockDispatch });
599
- expect(mockDispatch).toHaveBeenCalledWith({
600
- type: import_constants.REGISTER_ABILITY_CATEGORY,
601
- category: {
602
- slug: validSlug,
603
- label: args.label,
604
- description: args.description,
605
- meta: {
606
- _clientRegistered: true
607
- }
608
- }
609
- });
610
- }
611
- });
612
- it("should validate and reject missing label", async () => {
613
- const slug = "test-category";
614
- const args = {
615
- label: "",
616
- description: "Test"
617
- };
618
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
619
- await expect(
620
- action({ select: mockSelect, dispatch: mockDispatch })
621
- ).rejects.toThrow(
622
- "The category properties must contain a `label` string."
623
- );
624
- expect(mockDispatch).not.toHaveBeenCalled();
625
- });
626
- it("should validate and reject non-string label", async () => {
627
- const slug = "test-category";
628
- const args = {
629
- label: 123,
630
- description: "Test"
631
- };
632
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
633
- await expect(
634
- action({ select: mockSelect, dispatch: mockDispatch })
635
- ).rejects.toThrow(
636
- "The category properties must contain a `label` string."
637
- );
638
- expect(mockDispatch).not.toHaveBeenCalled();
639
- });
640
- it("should validate and reject missing description", async () => {
641
- const slug = "test-category";
642
- const args = {
643
- label: "Test",
644
- description: ""
645
- };
646
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
647
- await expect(
648
- action({ select: mockSelect, dispatch: mockDispatch })
649
- ).rejects.toThrow(
650
- "The category properties must contain a `description` string."
651
- );
652
- expect(mockDispatch).not.toHaveBeenCalled();
653
- });
654
- it("should validate and reject non-string description", async () => {
655
- const slug = "test-category";
656
- const args = {
657
- label: "Test",
658
- description: 123
659
- };
660
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
661
- await expect(
662
- action({ select: mockSelect, dispatch: mockDispatch })
663
- ).rejects.toThrow(
664
- "The category properties must contain a `description` string."
665
- );
666
- expect(mockDispatch).not.toHaveBeenCalled();
667
- });
668
- it("should validate and reject non-object meta", async () => {
669
- const slug = "test-category";
670
- const args = {
671
- label: "Test",
672
- description: "Test",
673
- meta: "invalid"
674
- };
675
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
676
- await expect(
677
- action({ select: mockSelect, dispatch: mockDispatch })
678
- ).rejects.toThrow(
679
- "The category properties should provide a valid `meta` object."
680
- );
681
- expect(mockDispatch).not.toHaveBeenCalled();
682
- });
683
- it("should validate and reject array as meta", async () => {
684
- const slug = "test-category";
685
- const args = {
686
- label: "Test",
687
- description: "Test",
688
- meta: ["invalid"]
689
- };
690
- const action = (0, import_actions.registerAbilityCategory)(slug, args);
691
- await expect(
692
- action({ select: mockSelect, dispatch: mockDispatch })
693
- ).rejects.toThrow(
694
- "The category properties should provide a valid `meta` object."
695
- );
696
- expect(mockDispatch).not.toHaveBeenCalled();
697
- });
698
- it("should validate and reject already registered category", async () => {
699
- const existingCategory = {
700
- slug: "test-category",
701
- label: "Existing Category",
702
- description: "Already registered"
703
- };
704
- mockSelect.getAbilityCategory.mockReturnValue(existingCategory);
705
- const args = {
706
- label: "Test",
707
- description: "Test"
708
- };
709
- const action = (0, import_actions.registerAbilityCategory)("test-category", args);
710
- await expect(
711
- action({ select: mockSelect, dispatch: mockDispatch })
712
- ).rejects.toThrow(
713
- 'Category "test-category" is already registered.'
714
- );
715
- expect(mockDispatch).not.toHaveBeenCalled();
716
- });
717
- it("should allow registering ability after registering category", async () => {
718
- const categorySlug = "new-category";
719
- const categoryArgs = {
720
- label: "New Category",
721
- description: "A newly registered category"
722
- };
723
- const categoryAction = (0, import_actions.registerAbilityCategory)(
724
- categorySlug,
725
- categoryArgs
726
- );
727
- await categoryAction({
728
- select: mockSelect,
729
- dispatch: mockDispatch
730
- });
731
- expect(mockDispatch).toHaveBeenCalledWith({
732
- type: import_constants.REGISTER_ABILITY_CATEGORY,
733
- category: {
734
- slug: categorySlug,
735
- label: categoryArgs.label,
736
- description: categoryArgs.description,
737
- meta: {
738
- _clientRegistered: true
739
- }
740
- }
741
- });
742
- const categoriesWithNew = [
743
- {
744
- slug: categorySlug,
745
- label: categoryArgs.label,
746
- description: categoryArgs.description
747
- }
748
- ];
749
- mockSelect.getAbilityCategories = jest.fn().mockReturnValue(categoriesWithNew);
750
- import_data.resolveSelect.mockReturnValue({
751
- getAbilityCategories: jest.fn().mockResolvedValue(categoriesWithNew)
752
- });
753
- mockSelect.getAbility = jest.fn().mockReturnValue(null);
754
- mockDispatch.mockClear();
755
- const ability = {
756
- name: "test/ability",
757
- label: "Test Ability",
758
- description: "Test description",
759
- category: categorySlug,
760
- callback: jest.fn()
761
- };
762
- const abilityAction = (0, import_actions.registerAbility)(ability);
763
- await abilityAction({
764
- select: mockSelect,
765
- dispatch: mockDispatch
766
- });
767
- expect(mockDispatch).toHaveBeenCalledWith({
768
- type: import_constants.REGISTER_ABILITY,
769
- ability
770
- });
771
- });
772
- });
773
- describe("unregisterAbilityCategory", () => {
774
- it("should create an action to unregister a category", () => {
775
- const slug = "test-category";
776
- const action = (0, import_actions.unregisterAbilityCategory)(slug);
777
- expect(action).toEqual({
778
- type: import_constants.UNREGISTER_ABILITY_CATEGORY,
779
- slug
780
- });
781
- });
782
- it("should handle valid category slugs", () => {
783
- const slug = "data-retrieval";
784
- const action = (0, import_actions.unregisterAbilityCategory)(slug);
785
- expect(action).toEqual({
786
- type: import_constants.UNREGISTER_ABILITY_CATEGORY,
787
- slug
788
- });
789
- });
790
- });
791
- });
792
- //# sourceMappingURL=actions.test.js.map