63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import {describe, expect, beforeEach} from '@jest/globals';
|
|
import {Settings} from '@/app/lib/settings';
|
|
import { getDb, migrateDb } from '@/app/lib/db';
|
|
|
|
describe('Settings', () => {
|
|
let settings: Settings;
|
|
|
|
beforeEach(async () => {
|
|
// Initialize your Settings class here with a fresh database instance
|
|
await migrateDb();
|
|
const db = await getDb();
|
|
if (!db) throw new Error("Could not get db");
|
|
settings = new Settings(db);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
// Clean up the database after each test
|
|
settings && await settings.db.executeSql('DELETE FROM settings');
|
|
});
|
|
|
|
describe('setHostLanguage', () => {
|
|
it('should set the host language in the database', async () => {
|
|
const value = 'en';
|
|
await settings.db.runAsync("REPLACE INTO settings (host_language) VALUES (?)", "en");
|
|
await settings.setHostLanguage(value);
|
|
|
|
const result = await settings.getHostLanguage();
|
|
expect(result).toEqual(value);
|
|
});
|
|
});
|
|
|
|
describe('getHostLanguage', () => {
|
|
it('should return the host language from the database', async () => {
|
|
const value = 'fr';
|
|
await settings.setHostLanguage(value);
|
|
|
|
const result = await settings.getHostLanguage();
|
|
expect(result).toEqual(value);
|
|
});
|
|
|
|
it('should return null if the host language is not set', async () => {
|
|
const result = await settings.getHostLanguage();
|
|
expect(result).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('setLibretranslateBaseUrl', () => {
|
|
it('should set the LibreTranslate base URL in the database', async () => {
|
|
const value = 'https://example.com';
|
|
await settings.setLibretranslateBaseUrl(value);
|
|
|
|
const result = await settings.getLibretranslateBaseUrl();
|
|
expect(result).toEqual(value);
|
|
});
|
|
});
|
|
|
|
describe('getLibretranslateBaseUrl', () => {
|
|
it('should return null if the LibreTranslate base URL is not set', async () => {
|
|
const result = await settings.getLibretranslateBaseUrl();
|
|
expect(result).toBeNull();
|
|
});
|
|
});
|
|
}); |