Skip to content

Commit

Permalink
add some unit tests for applicationManager
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 22, 2024
1 parent 4bec89b commit 3f2c1ef
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/backend/src/managers/applicationManager.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { expect, test, vi } from 'vitest';
import { ApplicationManager } from './applicationManager';
import { RecipeStatusRegistry } from '../registries/RecipeStatusRegistry';

Check failure on line 3 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

All imports in the declaration are only used as types. Use `import type`

Check failure on line 3 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

All imports in the declaration are only used as types. Use `import type`

Check failure on line 3 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

All imports in the declaration are only used as types. Use `import type`
import { ExtensionContext } from '@podman-desktop/api';

Check failure on line 4 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

All imports in the declaration are only used as types. Use `import type`

Check failure on line 4 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

All imports in the declaration are only used as types. Use `import type`

Check failure on line 4 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

All imports in the declaration are only used as types. Use `import type`
import { GitManager } from './gitManager';

Check failure on line 5 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

All imports in the declaration are only used as types. Use `import type`

Check failure on line 5 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

All imports in the declaration are only used as types. Use `import type`

Check failure on line 5 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

All imports in the declaration are only used as types. Use `import type`
import os from 'os';
import fs, { Dirent } from 'fs';

Check failure on line 7 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

Import "Dirent" is only used as types

Check failure on line 7 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

Import "Dirent" is only used as types

Check failure on line 7 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

Import "Dirent" is only used as types
import path from 'path';

test('appUserDirectory should be under home directory', () => {
vi.spyOn(os, 'homedir').mockReturnValue('/home/user');
const manager = new ApplicationManager({} as GitManager, {} as RecipeStatusRegistry, {} as ExtensionContext);
expect(manager.appUserDirectory).toMatch(/^\/home\/user/);
});

test('getLocalModels should return models in local directory', () => {
vi.spyOn(os, 'homedir').mockReturnValue('/home/user');
vi.spyOn(fs, 'readdirSync').mockImplementation((dir: string): any => {

Check failure on line 18 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / windows-2022

Unexpected any. Specify a different type

Check failure on line 18 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / ubuntu-22.04

Unexpected any. Specify a different type

Check failure on line 18 in packages/backend/src/managers/applicationManager.spec.ts

View workflow job for this annotation

GitHub Actions / linter, formatters and unit tests / macos-12

Unexpected any. Specify a different type
if (dir.endsWith('model-id-1') || dir.endsWith('model-id-2')) {
const base = path.basename(dir);
return [base + '-model'];
} else {
return [
{
isDirectory: () => true,
path: '/home/user/appstudio-dir',
name: 'model-id-1',
},
{
isDirectory: () => true,
path: '/home/user/appstudio-dir',
name: 'model-id-2',
},
{
isDirectory: () => false,
path: '/home/user/appstudio-dir',
name: 'other-file-should-be-ignored.txt',
},
] as Dirent[];
}
});
const manager = new ApplicationManager({} as GitManager, {} as RecipeStatusRegistry, {} as ExtensionContext);
const models = manager.getLocalModels();
expect(models).toEqual([
{
id: 'model-id-1',
file: 'model-id-1-model',
},
{
id: 'model-id-2',
file: 'model-id-2-model',
},
]);
});

0 comments on commit 3f2c1ef

Please sign in to comment.