mirror of
https://github.com/abusoww/tuxmate.git
synced 2026-04-17 15:53:24 +02:00
test: implement unit testing suite for bash script generators
This commit is contained in:
77
src/__tests__/scripts.test.ts
Normal file
77
src/__tests__/scripts.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateArchScript } from '@/lib/scripts/arch';
|
||||
import { generateUbuntuScript } from '@/lib/scripts/ubuntu';
|
||||
import { generateFlatpakScript } from '@/lib/scripts/flatpak';
|
||||
import type { PackageInfo } from '@/lib/scripts/shared';
|
||||
import type { AppData } from '@/lib/data';
|
||||
|
||||
// Mock AppData objects
|
||||
const mockAppOfficial: AppData = {
|
||||
id: 'mock-official',
|
||||
name: 'Mock Official App',
|
||||
description: 'A mock app from official repos',
|
||||
category: 'System',
|
||||
icon: { type: 'iconify', set: 'mdi', name: 'test' },
|
||||
targets: { arch: 'mock-pkg', ubuntu: 'mock-pkg', flatpak: 'org.mock.App' }
|
||||
};
|
||||
|
||||
const mockAppAur: AppData = {
|
||||
id: 'mock-aur',
|
||||
name: 'Mock AUR App',
|
||||
description: 'A mock app from AUR',
|
||||
category: 'System',
|
||||
icon: { type: 'iconify', set: 'mdi', name: 'test' },
|
||||
targets: { arch: 'mock-aur-bin' }
|
||||
};
|
||||
|
||||
describe('Script Generators', () => {
|
||||
describe('Arch Linux Generator', () => {
|
||||
const officialPkg: PackageInfo = { app: mockAppOfficial, pkg: 'mock-pkg' };
|
||||
const aurPkg: PackageInfo = { app: mockAppAur, pkg: 'mock-aur-bin' };
|
||||
|
||||
it('should generate script for official packages only', () => {
|
||||
const script = generateArchScript([officialPkg]);
|
||||
expect(script).toContain('sudo pacman');
|
||||
expect(script).toContain('install_pkg "Mock Official App" "mock-pkg" "sudo pacman"');
|
||||
expect(script).not.toContain('yay');
|
||||
expect(script).not.toContain('paru');
|
||||
});
|
||||
|
||||
it('should include AUR helper logic if AUR packages are present', () => {
|
||||
const scriptWithYay = generateArchScript([officialPkg, aurPkg], 'yay');
|
||||
expect(scriptWithYay).toContain('command -v yay');
|
||||
expect(scriptWithYay).toContain('install_pkg "Mock AUR App" "mock-aur-bin" "yay"');
|
||||
|
||||
const scriptWithParu = generateArchScript([officialPkg, aurPkg], 'paru');
|
||||
expect(scriptWithParu).toContain('command -v paru');
|
||||
expect(scriptWithParu).toContain('install_pkg "Mock AUR App" "mock-aur-bin" "paru"');
|
||||
});
|
||||
|
||||
it('should contain standard bash boilerplates', () => {
|
||||
const script = generateArchScript([officialPkg]);
|
||||
expect(script).toContain('#!/bin/bash');
|
||||
expect(script).toContain('set -euo pipefail');
|
||||
expect(script).toContain('wait_for_lock');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ubuntu/Debian Generator', () => {
|
||||
const pkg: PackageInfo = { app: mockAppOfficial, pkg: 'mock-pkg' };
|
||||
|
||||
it('should generate apt install commands', () => {
|
||||
const script = generateUbuntuScript([pkg]);
|
||||
expect(script).toContain('sudo apt-get update');
|
||||
expect(script).toContain('install_pkg "Mock Official App" "mock-pkg"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Flatpak Generator', () => {
|
||||
const pkg: PackageInfo = { app: mockAppOfficial, pkg: 'org.mock.App' };
|
||||
|
||||
it('should add flathub remote and install app', () => {
|
||||
const script = generateFlatpakScript([pkg]);
|
||||
expect(script).toContain('flatpak remote-add --if-not-exists flathub');
|
||||
expect(script).toContain('install_pkg "Mock Official App" "org.mock.App"');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user