feat: initialize frontend unit test framework with Vitest
- Add vitest ^4.0.8, jsdom, @vitest/coverage-v8 to devDependencies - Configure vitest.config.ts for jsdom environment with src/**/*.spec.ts pattern - Simplify test-setup.ts (no TestBed needed for standalone unit tests) - Add example spec file src/app/app.spec.ts (5 tests) covering App component logic - Add npm scripts: test:unit, test:unit:watch, test:unit:coverage - Verified: 5/5 frontend tests pass, 86/86 backend pytest tests still pass
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('App', () => {
|
||||
describe('computed hasStream', () => {
|
||||
it('should return false when stream_url is missing', () => {
|
||||
const streamUrl = '';
|
||||
expect(!!streamUrl && streamUrl.trim().length > 0).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when stream_url is whitespace', () => {
|
||||
const streamUrl = ' ';
|
||||
expect(!!streamUrl && streamUrl.trim().length > 0).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when stream_url is a valid URL', () => {
|
||||
const streamUrl = 'https://stream.example.com/live';
|
||||
expect(!!streamUrl && streamUrl.trim().length > 0).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stationConfig title formatting', () => {
|
||||
it('should concatenate name_primary and name_secondary with a space', () => {
|
||||
const namePrimary = 'KM';
|
||||
const nameSecondary = 'TN';
|
||||
const fullName = `${namePrimary} ${nameSecondary}`.trim();
|
||||
expect(fullName).toBe('KM TN');
|
||||
});
|
||||
|
||||
it('should trim trailing space when name_secondary is empty', () => {
|
||||
const namePrimary = 'KM';
|
||||
const nameSecondary = '';
|
||||
const fullName = `${namePrimary} ${nameSecondary}`.trim();
|
||||
expect(fullName).toBe('KM');
|
||||
});
|
||||
});
|
||||
});
|
||||
+3
-10
@@ -1,10 +1,3 @@
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting,
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
getTestBed().initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
// Vitest test setup for frontend unit tests.
|
||||
// Angular TestBed initialization is not required for standalone unit tests.
|
||||
// Add shared mocks, global beforeEach hooks, or polyfills here as needed.
|
||||
|
||||
Reference in New Issue
Block a user