|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import type { Audit, Group } from '@code-pushup/models'; |
3 | | -import { filterAuditsBySlug, filterGroupsByAuditSlug } from './utils'; |
| 3 | +import { filterAuditsBySlug, filterGroupsByAuditSlug } from './utils.js'; |
4 | 4 |
|
5 | | -describe('utils', () => { |
6 | | - describe('filterAuditsBySlug', () => { |
7 | | - const mockAudits: Audit[] = [ |
8 | | - { slug: 'test-1', title: 'Test 1' }, |
9 | | - { slug: 'test-2', title: 'Test 2' }, |
10 | | - { slug: 'test-3', title: 'Test 3' }, |
11 | | - ]; |
| 5 | +describe('filterAuditsBySlug', () => { |
| 6 | + const mockAudits: Audit[] = [ |
| 7 | + { slug: 'test-1', title: 'Test 1' }, |
| 8 | + { slug: 'test-2', title: 'Test 2' }, |
| 9 | + { slug: 'test-3', title: 'Test 3' }, |
| 10 | + ]; |
12 | 11 |
|
13 | | - it.each([ |
14 | | - [undefined, mockAudits, [true, true, true]], |
15 | | - [[], mockAudits, [true, true, true]], |
16 | | - [['test-1', 'test-2'], mockAudits, [true, true, false]], |
17 | | - ])( |
18 | | - 'should filter audits correctly when slugs is %p', |
19 | | - (slugs, audits, expected) => { |
20 | | - const filter = filterAuditsBySlug(slugs); |
21 | | - audits.forEach((audit, index) => { |
22 | | - expect(filter(audit)).toBe(expected[index]); |
23 | | - }); |
24 | | - }, |
25 | | - ); |
26 | | - }); |
| 12 | + it.each([ |
| 13 | + [undefined, mockAudits, [true, true, true]], |
| 14 | + [[], mockAudits, [true, true, true]], |
| 15 | + [['test-1', 'test-2'], mockAudits, [true, true, false]], |
| 16 | + ])( |
| 17 | + 'should filter audits correctly when slugs is %p', |
| 18 | + (slugs, audits, expected) => { |
| 19 | + const filter = filterAuditsBySlug(slugs); |
| 20 | + audits.forEach((audit, index) => { |
| 21 | + expect(filter(audit)).toBe(expected[index]); |
| 22 | + }); |
| 23 | + }, |
| 24 | + ); |
| 25 | +}); |
27 | 26 |
|
28 | | - describe('filterGroupsByAuditSlug', () => { |
29 | | - const mockGroups: Group[] = [ |
30 | | - { |
31 | | - slug: 'group-1', |
32 | | - title: 'Group 1', |
33 | | - refs: [ |
34 | | - { slug: 'audit-1', weight: 1 }, |
35 | | - { slug: 'audit-2', weight: 1 }, |
36 | | - ], |
37 | | - }, |
38 | | - { |
39 | | - slug: 'group-2', |
40 | | - title: 'Group 2', |
41 | | - refs: [{ slug: 'audit-3', weight: 1 }], |
42 | | - }, |
43 | | - { |
44 | | - slug: 'group-3', |
45 | | - title: 'Group 3', |
46 | | - refs: [ |
47 | | - { slug: 'audit-4', weight: 1 }, |
48 | | - { slug: 'audit-5', weight: 1 }, |
49 | | - ], |
50 | | - }, |
51 | | - ]; |
| 27 | +describe('filterGroupsByAuditSlug', () => { |
| 28 | + const mockGroups: Group[] = [ |
| 29 | + { |
| 30 | + slug: 'group-1', |
| 31 | + title: 'Group 1', |
| 32 | + refs: [ |
| 33 | + { slug: 'audit-1', weight: 1 }, |
| 34 | + { slug: 'audit-2', weight: 1 }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + { |
| 38 | + slug: 'group-2', |
| 39 | + title: 'Group 2', |
| 40 | + refs: [{ slug: 'audit-3', weight: 1 }], |
| 41 | + }, |
| 42 | + { |
| 43 | + slug: 'group-3', |
| 44 | + title: 'Group 3', |
| 45 | + refs: [ |
| 46 | + { slug: 'audit-4', weight: 1 }, |
| 47 | + { slug: 'audit-5', weight: 1 }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + ]; |
52 | 51 |
|
53 | | - it.each(mockGroups)( |
54 | | - 'should return true for group %# when no slugs provided', |
55 | | - group => { |
56 | | - const filter = filterGroupsByAuditSlug(); |
57 | | - expect(filter(group)).toBe(true); |
58 | | - }, |
59 | | - ); |
| 52 | + it.each(mockGroups)( |
| 53 | + 'should return true for group %# when no slugs provided', |
| 54 | + group => { |
| 55 | + const filter = filterGroupsByAuditSlug(); |
| 56 | + expect(filter(group)).toBe(true); |
| 57 | + }, |
| 58 | + ); |
60 | 59 |
|
61 | | - it.each(mockGroups)( |
62 | | - 'should return true for group %# when empty slugs array provided', |
63 | | - group => { |
64 | | - const filter = filterGroupsByAuditSlug([]); |
65 | | - expect(filter(group)).toBe(true); |
66 | | - }, |
67 | | - ); |
| 60 | + it.each(mockGroups)( |
| 61 | + 'should return true for group %# when empty slugs array provided', |
| 62 | + group => { |
| 63 | + const filter = filterGroupsByAuditSlug([]); |
| 64 | + expect(filter(group)).toBe(true); |
| 65 | + }, |
| 66 | + ); |
68 | 67 |
|
69 | | - it.each([ |
70 | | - [mockGroups[0], true], |
71 | | - [mockGroups[1], true], |
72 | | - [mockGroups[2], false], |
73 | | - ])('should filter group %# by audit slugs', (group, expected) => { |
74 | | - const filter = filterGroupsByAuditSlug(['audit-1', 'audit-3']); |
75 | | - expect(filter(group!)).toBe(expected); |
76 | | - }); |
| 68 | + it.each([ |
| 69 | + [mockGroups[0], true], |
| 70 | + [mockGroups[1], true], |
| 71 | + [mockGroups[2], false], |
| 72 | + ])('should filter group %# by audit slugs', (group, expected) => { |
| 73 | + const filter = filterGroupsByAuditSlug(['audit-1', 'audit-3']); |
| 74 | + expect(filter(group!)).toBe(expected); |
77 | 75 | }); |
78 | 76 | }); |
0 commit comments