-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0ddfd50
commit 505fac2
Showing
14 changed files
with
380 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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 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
35 changes: 35 additions & 0 deletions
35
...e/draft-generation/draft-apply-progress-dialog/draft-apply-progress-dialog.component.html
This file contains 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,35 @@ | ||
<ng-container *transloco="let t; read: 'draft_apply_progress-dialog'"> | ||
<mat-dialog-content> | ||
<div class="progress-content"> | ||
@if (draftApplyProgress?.completed !== true) { | ||
<div class="progress-container"> | ||
<mat-progress-bar mode="determinate" color="primary" [value]="progress"></mat-progress-bar> | ||
<p>{{ t("add_draft_to_book", { bookName }) }}</p> | ||
</div> | ||
} @else { | ||
<div class="result-container"> | ||
@if (failedToApplyChapters != null && failedToApplyChapters.length > 0) { | ||
<div class="error-result"> | ||
<h2 class="failed-message"> | ||
<mat-icon>warning</mat-icon> | ||
<span>{{ t("some_chapters_not_applied", { bookName }) }}</span> | ||
</h2> | ||
<p>{{ t("go_to_chapter") }}</p> | ||
<span>{{ t("failed_to_apply_chapters") }}</span> | ||
<span class="failed-chapters">{{ failedToApplyChapters }}</span> | ||
</div> | ||
} @else { | ||
<h2> | ||
<span>{{ t("successfully_applied_all_chapters", { bookName }) }}</span> | ||
</h2> | ||
} | ||
</div> | ||
} | ||
</div> | ||
</mat-dialog-content> | ||
<mat-dialog-actions> | ||
@if (draftApplyProgress?.completed === true) { | ||
<button mat-flat-button (click)="close()">{{ t("close") }}</button> | ||
} | ||
</mat-dialog-actions> | ||
</ng-container> |
46 changes: 46 additions & 0 deletions
46
...e/draft-generation/draft-apply-progress-dialog/draft-apply-progress-dialog.component.scss
This file contains 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,46 @@ | ||
.progress-content { | ||
min-width: 240px; | ||
max-width: 500px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
.progress-container { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
mat-progress-bar { | ||
margin-top: 1em; | ||
} | ||
} | ||
|
||
.error-result { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.mat-icon { | ||
flex-shrink: 0; | ||
} | ||
|
||
.failed-chapters { | ||
text-indent: 1em; | ||
font-weight: bold; | ||
font-size: 2em; | ||
margin-top: 0.5em; | ||
line-height: 1em; | ||
} | ||
} | ||
|
||
.failed-message { | ||
display: flex; | ||
column-gap: 8px; | ||
align-items: center; | ||
} | ||
} | ||
|
||
.mat-mdc-dialog-actions { | ||
justify-content: flex-end; | ||
} |
82 changes: 82 additions & 0 deletions
82
...raft-generation/draft-apply-progress-dialog/draft-apply-progress-dialog.component.spec.ts
This file contains 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,82 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CommonModule } from '@angular/common'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { anything, mock, when } from 'ts-mockito'; | ||
import { I18nService } from 'xforge-common/i18n.service'; | ||
import { configureTestingModule, TestTranslocoModule } from 'xforge-common/test-utils'; | ||
import { UICommonModule } from 'xforge-common/ui-common.module'; | ||
import { DraftApplyProgress, DraftApplyProgressDialogComponent } from './draft-apply-progress-dialog.component'; | ||
|
||
const mockI18nService = mock(I18nService); | ||
const mockMatDialogRef = mock(MatDialogRef); | ||
|
||
describe('DraftApplyProgressDialogComponent', () => { | ||
let env: TestEnvironment; | ||
let progress$: BehaviorSubject<DraftApplyProgress> = new BehaviorSubject<DraftApplyProgress>({ | ||
bookNum: 1, | ||
completed: false, | ||
chapters: [1, 2, 3], | ||
chaptersApplied: [] | ||
}); | ||
|
||
configureTestingModule(() => ({ | ||
imports: [DraftApplyProgressDialogComponent, UICommonModule, CommonModule, TestTranslocoModule], | ||
providers: [ | ||
{ provide: I18nService, useMock: mockI18nService }, | ||
{ provide: MatDialogRef, useMock: mockMatDialogRef }, | ||
{ provide: MAT_DIALOG_DATA, useValue: { draftApplyProgress$: progress$ } } | ||
] | ||
})); | ||
|
||
beforeEach(async () => { | ||
env = new TestEnvironment(); | ||
}); | ||
|
||
it('shows progress', () => { | ||
progress$.next({ bookNum: 1, chapters: [1, 2], chaptersApplied: [1], completed: false }); | ||
env.fixture.detectChanges(); | ||
expect(env.progressContainer).not.toBeNull(); | ||
expect(env.resultContainer).toBeNull(); | ||
expect(env.component.progress).toBe(50); | ||
}); | ||
|
||
it('shows apply draft completed', () => { | ||
progress$.next({ bookNum: 1, chapters: [1, 2], chaptersApplied: [1, 2], completed: true }); | ||
env.fixture.detectChanges(); | ||
expect(env.progressContainer).toBeNull(); | ||
expect(env.resultContainer).not.toBeNull(); | ||
expect(env.component.failedToApplyChapters).toBeUndefined(); | ||
expect(env.resultContainer.textContent).toContain('Successfully applied all chapters'); | ||
}); | ||
|
||
it('shows chapters that failed to be applied', () => { | ||
progress$.next({ bookNum: 1, chapters: [1, 2], chaptersApplied: [1], completed: true }); | ||
env.fixture.detectChanges(); | ||
expect(env.progressContainer).toBeNull(); | ||
expect(env.resultContainer).not.toBeNull(); | ||
expect(env.component.failedToApplyChapters).toEqual('2'); | ||
expect(env.resultContainer.textContent).toContain('warning'); | ||
}); | ||
}); | ||
|
||
class TestEnvironment { | ||
component: DraftApplyProgressDialogComponent; | ||
fixture: ComponentFixture<DraftApplyProgressDialogComponent>; | ||
|
||
constructor() { | ||
this.fixture = TestBed.createComponent(DraftApplyProgressDialogComponent); | ||
this.component = this.fixture.componentInstance; | ||
this.fixture.detectChanges(); | ||
when(mockI18nService.enumerateList(anything())).thenCall((items: string[]) => items.join(', ')); | ||
} | ||
|
||
get progressContainer(): HTMLElement { | ||
return this.fixture.nativeElement.querySelector('.progress-container'); | ||
} | ||
|
||
get resultContainer(): HTMLElement { | ||
return this.fixture.nativeElement.querySelector('.result-container'); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ate/draft-generation/draft-apply-progress-dialog/draft-apply-progress-dialog.component.ts
This file contains 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,59 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, DestroyRef, Inject } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { TranslocoModule } from '@ngneat/transloco'; | ||
import { Observable } from 'rxjs'; | ||
import { I18nService } from 'xforge-common/i18n.service'; | ||
import { UICommonModule } from 'xforge-common/ui-common.module'; | ||
|
||
export interface DraftApplyProgress { | ||
bookNum: number; | ||
chapters: number[]; | ||
chaptersApplied: number[]; | ||
completed: boolean; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-draft-apply-progress', | ||
standalone: true, | ||
imports: [CommonModule, UICommonModule, TranslocoModule], | ||
templateUrl: './draft-apply-progress-dialog.component.html', | ||
styleUrl: './draft-apply-progress-dialog.component.scss' | ||
}) | ||
export class DraftApplyProgressDialogComponent { | ||
draftApplyProgress?: DraftApplyProgress; | ||
|
||
constructor( | ||
@Inject(MatDialogRef) private readonly dialogRef: MatDialogRef<DraftApplyProgressDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) data: { draftApplyProgress$: Observable<DraftApplyProgress | undefined> }, | ||
private readonly i18n: I18nService, | ||
destroyRef: DestroyRef | ||
) { | ||
data.draftApplyProgress$ | ||
.pipe(takeUntilDestroyed(destroyRef)) | ||
.subscribe(progress => (this.draftApplyProgress = progress)); | ||
} | ||
|
||
get progress(): number | undefined { | ||
if (this.draftApplyProgress == null) return undefined; | ||
return (this.draftApplyProgress.chaptersApplied.length / this.draftApplyProgress.chapters.length) * 100; | ||
} | ||
|
||
get bookName(): string { | ||
if (this.draftApplyProgress == null) return ''; | ||
return this.i18n.localizeBook(this.draftApplyProgress.bookNum); | ||
} | ||
|
||
get failedToApplyChapters(): string | undefined { | ||
if (this.draftApplyProgress == null || !this.draftApplyProgress.completed) return undefined; | ||
const chapters: string[] = this.draftApplyProgress.chapters | ||
.filter(c => !this.draftApplyProgress.chaptersApplied.includes(c)) | ||
.map(c => c.toString()); | ||
return chapters.length > 0 ? this.i18n.enumerateList(chapters) : undefined; | ||
} | ||
|
||
close(): void { | ||
this.dialogRef.close(); | ||
} | ||
} |
This file contains 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 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 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.