-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: update to angular 21 and adding tests [no ci] #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b55479b
refactor: update to angular 21
CyAScott 36cbf97
fix: tests
CyAScott abf66c1
refactor: test
CyAScott 2ee8b67
feat: adding test coverage script
CyAScott 1973050
feat: added navigation tab tests
CyAScott 922a104
feat: added rating section tests
CyAScott 0048e1f
feat: add unit tests for PeopleSectionComponent and TypeaheadInputCom…
CyAScott 4ed6dbd
feat: add unit tests for ReadonlyInfoSectionComponent, ThumbnailSecti…
CyAScott 7e8a47a
feat: add unit tests for MediaEditorComponent
CyAScott f10bdf5
feat: add unit tests for SearchComponent and related functionality
CyAScott d266e44
fix: ensure hideTimeout is properly cleared in PlayerComponent
CyAScott 56c46b4
refactor: update template syntax to use @for directive for better per…
CyAScott 358cf0d
test: add unit tests for MetaComponent to ensure proper functionality…
CyAScott be97985
test: add unit tests for ImportComponent to verify functionality and …
CyAScott dfe6bba
test: add unit tests for LoginComponent to verify functionality and e…
CyAScott 46df413
test: add unit tests for AddUserModalComponent, ChangePasswordModalCo…
CyAScott a98a283
refactor: update coverage exclusion patterns in vitest configuration
CyAScott 0f8d7f4
feat: adding tests to GH actions
CyAScott ff0fcec
fix: downgrade @angular/platform-browser-dynamic to match version con…
CyAScott c589999
refactor: removing ngif
CyAScott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { defineConfig, devices } from '@playwright/test'; | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './e2e', | ||
| fullyParallel: true, | ||
| forbidOnly: !!process.env.CI, | ||
| retries: process.env.CI ? 2 : 0, | ||
| workers: process.env.CI ? 1 : undefined, | ||
| reporter: 'html', | ||
| use: { | ||
| trace: 'on-first-retry', | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| { | ||
| name: 'firefox', | ||
| use: { ...devices['Desktop Firefox'] }, | ||
| }, | ||
| { | ||
| name: 'webkit', | ||
| use: { ...devices['Desktop Safari'] }, | ||
| }, | ||
| ], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,37 @@ | ||
| <div class="import-container"> | ||
| <div class="files-section" *ngIf="files.length > 0"> | ||
| <table class="files-table"> | ||
| <thead> | ||
| <tr> | ||
| <th>File Name</th> | ||
| <th>Action</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr *ngFor="let file of files"> | ||
| <td class="filename">{{file.title}}</td> | ||
| <td class="action"> | ||
| <a | ||
| class="import-btn" | ||
| title="Import this file" | ||
| [routerLink]="['/import', file.title]" | ||
| [state]="{ mediaData: file }"> | ||
| <i class="fa-solid fa-upload"></i> | ||
| </a> | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| @if (files.length > 0) { | ||
| <div class="files-section"> | ||
| <table class="files-table"> | ||
| <thead> | ||
| <tr> | ||
| <th>File Name</th> | ||
| <th>Action</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| @for (file of files; track $index) { | ||
| <tr> | ||
| <td class="filename">{{file.title}}</td> | ||
| <td class="action"> | ||
| <a | ||
| class="import-btn" | ||
| title="Import this file" | ||
| [routerLink]="['/import', file.title]" | ||
| [state]="{ mediaData: file }"> | ||
| <i class="fa-solid fa-upload"></i> | ||
| </a> | ||
| </td> | ||
| </tr> | ||
| } | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| } | ||
|
|
||
| <!-- Empty state --> | ||
| <div class="empty-state" *ngIf="files.length === 0"> | ||
| <p>No media files found in the selected directory.</p> | ||
| </div> | ||
| @if (files.length === 0) { | ||
| <div class="empty-state"> | ||
| <p>No media files found in the selected directory.</p> | ||
| </div> | ||
| } | ||
| </div> |
119 changes: 119 additions & 0 deletions
119
src/MediaBrowser.Frontend/src/app/import/import.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { provideZonelessChangeDetection } from '@angular/core'; | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { provideRouter } from '@angular/router'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { of, throwError } from 'rxjs'; | ||
| import { ImportComponent } from './import'; | ||
| import { ImportFileInfo, ImportService } from '../services/import.service'; | ||
|
|
||
| function createImportFileInfo(overrides?: Partial<ImportFileInfo>): ImportFileInfo { | ||
| return { | ||
| createdOn: new Date('2025-01-01T00:00:00.000Z'), | ||
| ctimeMs: 1735689600000, | ||
| mime: 'video/mp4', | ||
| mtimeMs: 1735776000000, | ||
| name: 'movie.mp4', | ||
| size: 1234, | ||
| updatedOn: new Date('2025-01-02T00:00:00.000Z'), | ||
| url: 'https://example.com/movie.mp4', | ||
| ...overrides | ||
| }; | ||
| } | ||
|
|
||
| describe('ImportComponent', () => { | ||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [ImportComponent], | ||
| providers: [ | ||
| provideZonelessChangeDetection(), | ||
| provideRouter([]), | ||
| { | ||
| provide: ImportService, | ||
| useValue: { | ||
| files: vi.fn() | ||
| } | ||
| } | ||
| ] | ||
| }).compileComponents(); | ||
| }); | ||
|
|
||
| it('creates the component', () => { | ||
| const fixture = TestBed.createComponent(ImportComponent); | ||
| expect(fixture.componentInstance).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('converts ImportFileInfo to MediaReadModel', () => { | ||
| const file = createImportFileInfo({ | ||
| name: 'sample.mkv', | ||
| ctimeMs: 100, | ||
| mtimeMs: 200, | ||
| mime: 'video/x-matroska' | ||
| }); | ||
|
|
||
| const model = ImportComponent.convertToMediaReadModel(file); | ||
|
|
||
| expect(model.title).toBe('sample.mkv'); | ||
| expect(model.originalTitle).toBe('sample.mkv'); | ||
| expect(model.mime).toBe('video/x-matroska'); | ||
| expect(model.ctimeMs).toBe('100'); | ||
| expect(model.mtimeMs).toBe('200'); | ||
| expect(model.url).toBe(file.url); | ||
| expect(model.cast).toEqual([]); | ||
| expect(model.directors).toEqual([]); | ||
| expect(model.genres).toEqual([]); | ||
| expect(model.producers).toEqual([]); | ||
| expect(model.writers).toEqual([]); | ||
| expect(model.ffprobe).toEqual({}); | ||
| }); | ||
|
|
||
| it('loads files on init and maps them to MediaReadModel', async () => { | ||
| const importService = TestBed.inject(ImportService) as { files: ReturnType<typeof vi.fn> }; | ||
| const file = createImportFileInfo({ name: 'loaded.mp4' }); | ||
| importService.files.mockReturnValue(of([file])); | ||
|
|
||
| const fixture = TestBed.createComponent(ImportComponent); | ||
| const component = fixture.componentInstance; | ||
| const detectChangesSpy = vi.spyOn((component as unknown as { cdr: { detectChanges: () => void } }).cdr, 'detectChanges'); | ||
|
|
||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
|
|
||
| expect(importService.files).toHaveBeenCalledTimes(1); | ||
| expect(component.files).toHaveLength(1); | ||
| expect(component.files[0].title).toBe('loaded.mp4'); | ||
| expect(component.files[0].ctimeMs).toBe(file.ctimeMs.toString()); | ||
| expect(detectChangesSpy).toHaveBeenCalled(); | ||
|
|
||
| const compiled = fixture.nativeElement as HTMLElement; | ||
| expect(compiled.querySelectorAll('tbody tr')).toHaveLength(1); | ||
| expect(compiled.querySelector('.filename')?.textContent).toContain('loaded.mp4'); | ||
| }); | ||
|
|
||
| it('handles scan errors by clearing files and logging the error', async () => { | ||
| const importService = TestBed.inject(ImportService) as { files: ReturnType<typeof vi.fn> }; | ||
| const error = new Error('scan failed'); | ||
| importService.files.mockReturnValue(throwError(() => error)); | ||
|
|
||
| const fixture = TestBed.createComponent(ImportComponent); | ||
| const component = fixture.componentInstance; | ||
| component.files = [ImportComponent.convertToMediaReadModel(createImportFileInfo())]; | ||
|
|
||
| const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
| const detectChangesSpy = vi.spyOn((component as unknown as { cdr: { detectChanges: () => void } }).cdr, 'detectChanges'); | ||
|
|
||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
|
|
||
| expect(importService.files).toHaveBeenCalledTimes(1); | ||
| expect(component.files).toEqual([]); | ||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error scanning directory:', error); | ||
| expect(detectChangesSpy).toHaveBeenCalled(); | ||
|
|
||
| const compiled = fixture.nativeElement as HTMLElement; | ||
| expect(compiled.querySelector('.empty-state p')?.textContent).toContain( | ||
| 'No media files found in the selected directory.' | ||
| ); | ||
|
|
||
| consoleErrorSpy.mockRestore(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.