File size: 2,307 Bytes
64011fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// toolCategories.test.ts

import { categories } from '@/js/config/tools';
import { describe, it, expect } from 'vitest';

describe('Tool Categories Configuration', () => {
  // 1. Basic Structure and Type Checking
  it('should be an array of category objects', () => {
    expect(Array.isArray(categories)).toBe(true);
    expect(categories.length).toBeGreaterThan(0);
  });

  // 2. Loop through each category to perform specific checks
  describe.each(categories)('Category: "$name"', (category) => {
    // Check that the category object itself is well-formed
    it('should have a non-empty "name" string and a non-empty "tools" array', () => {
      expect(typeof category.name).toBe('string');
      expect(category.name.length).toBeGreaterThan(0);
      expect(Array.isArray(category.tools)).toBe(true);
      expect(category.tools.length).toBeGreaterThan(0);
    });

    // **KEY CHANGE**: This test now ensures IDs are unique only WITHIN this specific category.
    it('should not contain any duplicate tool IDs within its own list', () => {
      const toolIds = category.tools.map((tool) => {
        if ('id' in tool) return (tool as any).id;
        if ('href' in tool) {
          const match = (tool as any).href.match(/\/([^/]+)\.html$/);
          return match ? match[1] : (tool as any).href;
        }
        return 'unknown';
      });
      const uniqueToolIds = new Set(toolIds);

      // This assertion checks for duplicates inside THIS category only.
      expect(uniqueToolIds.size).toBe(toolIds.length);
    });

    // 3. Loop through each tool inside the category to validate its schema
    describe.each(category.tools)('Tool: "$name"', (tool) => {
      it('should have the correct properties with non-empty string values', () => {
        // Check for property existence
        expect(tool).toHaveProperty('id');
        expect(tool).toHaveProperty('name');
        expect(tool).toHaveProperty('icon');
        expect(tool).toHaveProperty('subtitle');

        // Check for non-empty string types for each property
        for (const key of ['id', 'name', 'icon', 'subtitle']) {
          const value = tool[key as keyof typeof tool];
          expect(typeof value).toBe('string');
          expect(value.length).toBeGreaterThan(0);
        }
      });
    });
  });
});