data-loader.integration.test.tsā¢4.02 kB
import { describe, it, expect } from 'vitest';
import { loadShortcutData } from './data-loader.js';
describe('loadShortcutData Integration Tests', () => {
it('should load all real shortcut data from data/ directory', () => {
const dataStore = loadShortcutData();
// Should load all 30 JSON files from data/ubuntu/
expect(dataStore.shortcuts.length).toBeGreaterThan(0);
// All shortcuts should have required fields
dataStore.shortcuts.forEach(shortcut => {
expect(shortcut).toHaveProperty('os');
expect(shortcut).toHaveProperty('file');
expect(shortcut).toHaveProperty('categories');
expect(Array.isArray(shortcut.categories)).toBe(true);
});
});
it('should filter real data by OS', () => {
const dataStore = loadShortcutData();
const ubuntuShortcuts = dataStore.getByFilters({ os: 'ubuntu' });
expect(ubuntuShortcuts.length).toBeGreaterThan(0);
// All filtered shortcuts should be ubuntu
ubuntuShortcuts.forEach(shortcut => {
expect(shortcut.os).toBe('ubuntu');
});
});
it('should filter real data by desktop environment', () => {
const dataStore = loadShortcutData();
const gnomeShortcuts = dataStore.getByFilters({ os: 'ubuntu', desktop: 'gnome' });
// Should find GNOME-specific shortcuts
expect(gnomeShortcuts.length).toBeGreaterThan(0);
gnomeShortcuts.forEach(shortcut => {
expect(shortcut.os).toBe('ubuntu');
expect(shortcut.desktop).toBe('gnome');
});
});
it('should filter real data by application', () => {
const dataStore = loadShortcutData();
const tmuxShortcuts = dataStore.getByFilters({ os: 'ubuntu', application: 'tmux' });
expect(tmuxShortcuts.length).toBe(1);
expect(tmuxShortcuts[0].application).toBe('tmux');
expect(tmuxShortcuts[0].desktop).toBeNull();
});
it('should load shortcuts with valid category structure', () => {
const dataStore = loadShortcutData();
const firefoxShortcuts = dataStore.getByFilters({ os: 'ubuntu', application: 'firefox' });
expect(firefoxShortcuts.length).toBe(1);
const firefox = firefoxShortcuts[0];
expect(firefox.categories.length).toBeGreaterThan(0);
// Check first category has proper structure
const firstCategory = firefox.categories[0];
expect(firstCategory).toHaveProperty('name');
expect(firstCategory).toHaveProperty('shortcuts');
expect(Array.isArray(firstCategory.shortcuts)).toBe(true);
if (firstCategory.shortcuts.length > 0) {
const firstShortcut = firstCategory.shortcuts[0];
expect(firstShortcut).toHaveProperty('keys');
expect(firstShortcut).toHaveProperty('description');
}
});
it('should distinguish between desktop shortcuts and CLI tools', () => {
const dataStore = loadShortcutData();
// GNOME shortcuts should have desktop set
const gnomeShortcuts = dataStore.getByFilters({ os: 'ubuntu', desktop: 'gnome' });
gnomeShortcuts.forEach(shortcut => {
expect(shortcut.desktop).toBe('gnome');
expect(shortcut.application).toBeNull();
});
// CLI tools should have null desktop
const tmuxShortcuts = dataStore.getByFilters({ os: 'ubuntu', application: 'tmux' });
tmuxShortcuts.forEach(shortcut => {
expect(shortcut.desktop).toBeNull();
expect(shortcut.application).toBe('tmux');
});
});
it('should load shortcuts from nested directories', () => {
const dataStore = loadShortcutData();
// Apps are in nested directories like apps/browser/, apps/editor/, etc.
const firefoxShortcuts = dataStore.getByFilters({ os: 'ubuntu', application: 'firefox' });
const vscodeShortcuts = dataStore.getByFilters({ os: 'ubuntu', application: 'vscode' });
expect(firefoxShortcuts.length).toBe(1);
expect(vscodeShortcuts.length).toBe(1);
// Desktop shortcuts are in desktops/gnome/
const gnomeShortcuts = dataStore.getByFilters({ os: 'ubuntu', desktop: 'gnome' });
expect(gnomeShortcuts.length).toBeGreaterThan(0);
});
});