add screens
This commit is contained in:
73
app/lib/__tests__/settings.spec.ts
Normal file
73
app/lib/__tests__/settings.spec.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import {describe, expect, beforeEach} from '@jest/globals';
|
||||
import {Settings} from '@/app/lib/settings';
|
||||
import { getDb } from '@/app/lib/db';
|
||||
|
||||
describe('Settings', () => {
|
||||
let settings: Settings;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Initialize your Settings class here with a fresh database instance
|
||||
settings = new Settings(await getDb());
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
// Clean up the database after each test
|
||||
await settings.db.executeSql('DELETE FROM settings');
|
||||
});
|
||||
|
||||
describe('setHostLanguage', () => {
|
||||
it('should set the host language in the database', async () => {
|
||||
const value = '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.db.executeSql(
|
||||
`INSERT INTO settings (host_language) VALUES (?)`,
|
||||
[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).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('setLibretranslateBaseUrl', () => {
|
||||
it('should set the LibreTranslate base URL in the database', async () => {
|
||||
const value = 'https://example.com';
|
||||
await settings.setLibetransalteBaseUrl(value);
|
||||
|
||||
const result = await settings.getLibretranslateBaseUrl();
|
||||
expect(result).toEqual(value);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLibretranslateBaseUrl', () => {
|
||||
it('should return the LibreTranslate base URL from the database', async () => {
|
||||
const value = 'https://another-example.com';
|
||||
await settings.db.executeSql(
|
||||
`INSERT INTO settings (libetransalte_base_url) VALUES (?)`,
|
||||
[value]
|
||||
);
|
||||
|
||||
const result = await settings.getLibretranslateBaseUrl();
|
||||
expect(result).toEqual(value);
|
||||
});
|
||||
|
||||
it('should return null if the LibreTranslate base URL is not set', async () => {
|
||||
const result = await settings.getLibretranslateBaseUrl();
|
||||
expect(result).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user