-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/show-result-handle-same-id-between-sess…
…ions-and-tasks
- Loading branch information
Showing
23 changed files
with
253 additions
and
292 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
src/app/dashboard/components/add-line-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,30 @@ | ||
<h2 mat-dialog-title i18n="Dialog title">Add a line</h2> | ||
|
||
<form [formGroup]="lineForm" (ngSubmit)="onSubmit()"> | ||
<mat-dialog-content> | ||
|
||
<mat-form-field appearance="outline"> | ||
<mat-label for="name" i18n="Name of the statuses group"> Name </mat-label> | ||
<input matInput id="name" type="text" formControlName="name" i18n-placeholder="Placeholder" placeholder="Name of your line" required i18n="Input error"> | ||
<mat-error *ngIf="lineForm.get('name')?.hasError('required')"> | ||
Name is <strong>required</strong> | ||
</mat-error> | ||
</mat-form-field> | ||
|
||
<mat-form-field appearance="outline"> | ||
<mat-label for="type"> Type </mat-label> | ||
<mat-select id="type" [value]="types" formControlName="type" required> | ||
<mat-option *ngFor="let option of types; trackByType" [value]="option">{{option}}</mat-option> | ||
</mat-select> | ||
<mat-error *ngIf="lineForm.get('type')?.hasError('required')"> | ||
Type is <strong>required</strong> | ||
</mat-error> | ||
</mat-form-field> | ||
|
||
</mat-dialog-content> | ||
|
||
<mat-dialog-actions align="end"> | ||
<button mat-button (click)="onCancel()" type="button" i18n="Dialog action"> Cancel </button> | ||
<button mat-flat-button type="submit" color="primary" [disabled]="!lineForm.valid" i18n="Dialog action"> Confirm </button> | ||
</mat-dialog-actions> | ||
</form> |
56 changes: 35 additions & 21 deletions
56
src/app/dashboard/components/add-line-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 |
---|---|---|
@@ -1,35 +1,49 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { AddLineDialogResult } from '@app/types/dialog'; | ||
import { AddLineDialogComponent } from './add-line-dialog.component'; | ||
|
||
describe('AddLineDialogComponent', () => { | ||
let component: AddLineDialogComponent; | ||
|
||
const mockMatDialogRef = { | ||
describe('FormNameLineComponent', () => { | ||
const mockDialogRef = { | ||
close: jest.fn() | ||
}; | ||
} as unknown as MatDialogRef<AddLineDialogComponent, AddLineDialogResult>; | ||
|
||
beforeEach(() => { | ||
component = TestBed.configureTestingModule({ | ||
providers: [ | ||
AddLineDialogComponent, | ||
{ provide: MatDialogRef, useValue: mockMatDialogRef }, | ||
{ provide: MAT_DIALOG_DATA, useValue: {} } | ||
] | ||
}).inject(AddLineDialogComponent); | ||
const component = new AddLineDialogComponent(mockDialogRef, { | ||
name: 'line', | ||
type: 'Applications' | ||
}); | ||
component.ngOnInit(); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should close with result on submit', () => { | ||
component.onSubmit({name:'result', type: 'Tasks'}); | ||
expect(mockMatDialogRef.close).toHaveBeenCalledWith({name:'result', type: 'Tasks'}); | ||
it('should init', () => { | ||
expect(component.lineForm.value.name).toEqual('line'); | ||
expect(component.lineForm.value.type).toEqual('Applications'); | ||
}); | ||
|
||
describe('onSubmit', () => { | ||
it('should submit if there is a value', () => { | ||
component.lineForm.value.name = 'line'; | ||
component.lineForm.value.type = 'Applications'; | ||
component.onSubmit(); | ||
expect(mockDialogRef.close).toHaveBeenCalledWith({name: 'line', type: 'Applications'}); | ||
}); | ||
|
||
it('should submit empty if there no value', () => { | ||
component.lineForm.value.name = null; | ||
component.lineForm.value.type = null; | ||
component.onSubmit(); | ||
expect(mockDialogRef.close).toHaveBeenCalledWith({name:'', type: ''}); | ||
}); | ||
}); | ||
|
||
it('should cancel', () => { | ||
component.onCancel(); | ||
expect(mockDialogRef.close).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should close on "no" click', () => { | ||
component.onNoClick(); | ||
expect(mockMatDialogRef.close).toHaveBeenCalled(); | ||
it('should track by options', () => { | ||
expect(component.trackByType(0, 'Applications')).toEqual('Applications'); | ||
}); | ||
}); |
73 changes: 58 additions & 15 deletions
73
src/app/dashboard/components/add-line-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 |
---|---|---|
@@ -1,38 +1,81 @@ | ||
import { Component, Inject } from '@angular/core'; | ||
import { NgFor, NgIf } from '@angular/common'; | ||
import { Component, Inject, OnInit } from '@angular/core'; | ||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { MatSelectModule } from '@angular/material/select'; | ||
import { AddLineDialogData, AddLineDialogResult } from '@app/types/dialog'; | ||
import { FormNameLineComponent } from './form-name-line.component'; | ||
import { LineType } from '../types'; | ||
|
||
@Component({ | ||
selector: 'app-add-line-dialog', | ||
template: ` | ||
<h2 mat-dialog-title i18n="Dialog title">Add a line</h2> | ||
<app-form-name-line | ||
(cancelChange)="onNoClick()" | ||
(submitChange)="onSubmit($event)" | ||
></app-form-name-line> | ||
`, | ||
templateUrl: 'add-line-dialog.component.html', | ||
styles: [` | ||
mat-dialog-content { | ||
padding-top: 0!important; | ||
overflow: visible!important; | ||
display: grid; | ||
grid-template-columns: repeat(2, 1fr); | ||
gap: 1rem; | ||
} | ||
`], | ||
standalone: true, | ||
providers: [], | ||
imports: [ | ||
MatDialogModule, | ||
FormNameLineComponent | ||
NgIf, | ||
NgFor, | ||
MatDialogModule, | ||
MatButtonModule, | ||
MatFormFieldModule, | ||
MatInputModule, | ||
ReactiveFormsModule, | ||
MatSelectModule | ||
] | ||
}) | ||
export class AddLineDialogComponent { | ||
export class AddLineDialogComponent implements OnInit { | ||
|
||
types: LineType[] = ['CountStatus', 'Applications', 'Sessions', 'Tasks', 'Partitions', 'Results']; | ||
|
||
lineForm = new FormGroup({ | ||
name: new FormControl('', [ | ||
Validators.required, | ||
]), | ||
type: new FormControl<LineType | ''>('', [ | ||
Validators.required | ||
]) | ||
}); | ||
|
||
constructor( | ||
public _dialogRef: MatDialogRef<AddLineDialogComponent, AddLineDialogResult>, | ||
@Inject(MAT_DIALOG_DATA) public data: AddLineDialogData, | ||
@Inject(MAT_DIALOG_DATA) public data?: AddLineDialogData, | ||
) {} | ||
|
||
onSubmit(result: AddLineDialogResult) { | ||
ngOnInit(): void { | ||
if(this.data?.name && this.data?.type) { | ||
this.lineForm.setValue({ | ||
name: this.data.name, | ||
type: this.data.type | ||
}); | ||
} | ||
} | ||
|
||
onSubmit() { | ||
const result = { | ||
name: this.lineForm.value.name ?? '', | ||
type: this.lineForm.value.type ?? '' | ||
} as AddLineDialogResult; | ||
this._dialogRef.close(result); | ||
} | ||
|
||
onNoClick(): void { | ||
onCancel(): void { | ||
this._dialogRef.close(); | ||
} | ||
|
||
trackByType(_: number, item: LineType) { | ||
return item; | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
src/app/dashboard/components/edit-name-line-dialog-component.spec.ts
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/app/dashboard/components/edit-name-line-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,14 @@ | ||
<h2 mat-dialog-title i18n="Dialog title">Edit the line name</h2> | ||
|
||
<form [formGroup]="nameForm" (ngSubmit)="onSubmit()"> | ||
<mat-dialog-content> | ||
<mat-form-field subscriptSizing="dynamic" appearance="outline"> | ||
<mat-label for="name">Name</mat-label> | ||
<input matInput id="name" type="text" formControlName="name" i18n-placeholder="placeholder" placeholder="Line name"/> | ||
</mat-form-field> | ||
</mat-dialog-content> | ||
<mat-dialog-actions align="end"> | ||
<button mat-button mat-dialog-close i18n="Button to close the dialog">Cancel</button> | ||
<button mat-flat-button (click)="onSubmit()" type="button" color="primary" [disabled]="!nameForm.valid" i18n="Button to submit the dialog">Submit</button> | ||
</mat-dialog-actions> | ||
</form> |
44 changes: 44 additions & 0 deletions
44
src/app/dashboard/components/edit-name-line-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,44 @@ | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
import { EditNameLineResult } from '@app/types/dialog'; | ||
import { EditNameLineDialogComponent } from './edit-name-line-dialog.component'; | ||
|
||
describe('', () => { | ||
const mockMatDialogRef = { | ||
close: jest.fn() | ||
} as unknown as MatDialogRef<EditNameLineDialogComponent, EditNameLineResult>; | ||
|
||
const defaultName = 'Tasks'; | ||
|
||
const component = new EditNameLineDialogComponent(mockMatDialogRef, { | ||
name: defaultName | ||
}); | ||
|
||
component.ngOnInit(); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should init', () => { | ||
expect(component.nameForm).toBeDefined(); | ||
}); | ||
|
||
describe('onSubmit', () => { | ||
it('should close with result', () => { | ||
component.nameForm.setValue({name: 'result'}); | ||
component.onSubmit(); | ||
expect(mockMatDialogRef.close).toHaveBeenCalledWith('result'); | ||
}); | ||
|
||
it('should close with previous name', () => { | ||
component.nameForm.setValue({name: ''}); | ||
component.onSubmit(); | ||
expect(mockMatDialogRef.close).toHaveBeenCalledWith(defaultName); | ||
}); | ||
}); | ||
|
||
it('should close on "no" click', () => { | ||
component.onNoClick(); | ||
expect(mockMatDialogRef.close).toHaveBeenCalled(); | ||
}); | ||
}); |
38 changes: 21 additions & 17 deletions
38
src/app/dashboard/components/edit-name-line-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
Oops, something went wrong.