-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add actions component * Add tests
- Loading branch information
Showing
9 changed files
with
105 additions
and
61 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
18 changes: 18 additions & 0 deletions
18
scilog/src/app/overview/actions-menu/actions-menu.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,18 @@ | ||
<button class="mat-fab-top-right" mat-icon-button aria-label="Actions" [matMenuTriggerFor]="menu" | ||
[disabled]="isAllowedService.tooltips.edit" matTooltip="{{ isAllowedService.tooltips.edit }}"> | ||
<mat-icon>more_vert</mat-icon> | ||
</button> | ||
<mat-menu #menu="matMenu"> | ||
<span [matTooltip]="isAllowedService.tooltips.update"> | ||
<button mat-menu-item (click)="editLogbook()" [disabled]="isAllowedService.tooltips.update"> | ||
<mat-icon>edit</mat-icon> | ||
Edit | ||
</button> | ||
</span> | ||
<span [matTooltip]="isAllowedService.tooltips.delete"> | ||
<button mat-menu-item (click)="deleteLogbook()" [disabled]="isAllowedService.tooltips.delete"> | ||
<mat-icon>delete</mat-icon> | ||
Delete | ||
</button> | ||
</span> | ||
</mat-menu> |
44 changes: 44 additions & 0 deletions
44
scilog/src/app/overview/actions-menu/actions-menu.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 { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { ActionsMenuComponent } from './actions-menu.component'; | ||
import { UserPreferencesService } from 'src/app/core/user-preferences.service'; | ||
import { MatMenuModule } from '@angular/material/menu'; | ||
|
||
class UserPreferencesMock { | ||
userInfo = { | ||
roles: ["roles"] | ||
|
||
} | ||
} | ||
|
||
describe('ActionsMenuComponent', () => { | ||
let component: ActionsMenuComponent; | ||
let fixture: ComponentFixture<ActionsMenuComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ActionsMenuComponent], | ||
imports: [MatMenuModule], | ||
providers: [ | ||
{ provide: UserPreferencesService, useClass: UserPreferencesMock }, | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ActionsMenuComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should enableActions', () => { | ||
const isAllowedSpy = spyOn(component['isAllowedService'], 'isAnyEditAllowed'); | ||
component['enableActions'](); | ||
expect(isAllowedSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
35 changes: 35 additions & 0 deletions
35
scilog/src/app/overview/actions-menu/actions-menu.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,35 @@ | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
import { IsAllowedService } from '../is-allowed.service'; | ||
import { Logbooks } from 'src/app/core/model/logbooks'; | ||
|
||
@Component({ | ||
selector: 'actions-menu', | ||
templateUrl: './actions-menu.component.html', | ||
providers: [IsAllowedService], | ||
}) | ||
export class ActionsMenuComponent implements OnInit { | ||
|
||
@Input() logbook: Logbooks; | ||
@Output() logbookEdit = new EventEmitter<Logbooks>(); | ||
@Output() logbookDelete = new EventEmitter<string>(); | ||
|
||
constructor(protected isAllowedService: IsAllowedService) {} | ||
|
||
ngOnInit(): void { | ||
this.enableActions(); | ||
} | ||
|
||
private enableActions() { | ||
this.isAllowedService.snippet = this.logbook; | ||
this.isAllowedService.isAnyEditAllowed(); | ||
} | ||
|
||
editLogbook() { | ||
this.logbookEdit.emit(this.logbook); | ||
} | ||
|
||
deleteLogbook() { | ||
this.logbookDelete.emit(this.logbook.id); | ||
} | ||
|
||
} |
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
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