-
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 tasks component and call from todo with checks
- Loading branch information
Showing
8 changed files
with
226 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div> | ||
<mat-card class="task-mat-card"> | ||
<mat-card-content class="task-content"> | ||
<mat-checkbox (change)="toggleTaskIsDone()" [checked]="task.isDone" | ||
[disabled]="isActionAllowed.tooltips.update" matTooltip="{{ isActionAllowed.tooltips.update }}"> | ||
<div> | ||
|
||
</div> | ||
</mat-checkbox> | ||
<span | ||
[ngStyle]="{'text-decoration': task.isDone? 'line-through' : 'none', 'opacity': task.isDone? '0.6' : '1'}" | ||
class='task-text'> | ||
{{ task.content }} | ||
</span> | ||
<span class="flexExpand"></span> | ||
<span> | ||
<button mat-icon-button (click)="deleteTask()" [disabled]="isActionAllowed.tooltips.delete" | ||
matTooltip="{{ isActionAllowed.tooltips.delete }}"> | ||
<mat-icon>delete</mat-icon> | ||
</button> | ||
</span> | ||
</mat-card-content> | ||
</mat-card> | ||
</div> |
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,33 @@ | ||
|
||
.task-mat-card{ | ||
margin-bottom: 1px; | ||
margin-left: 20px; | ||
margin-right: 20px; | ||
margin-top: 1px; | ||
min-height: 100%; | ||
text-align: left; | ||
border-radius: 5px; | ||
padding: 4px 0px; | ||
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .2), 0 2px 8px 0 rgba(0, 0, 0, .14), 0 4px 8px -1px rgba(0, 0, 0, .12); | ||
// background-color: var(--sidenav-color); | ||
color: var(--default-text-color); | ||
|
||
} | ||
|
||
|
||
.task-content{ | ||
display: flex; | ||
align-items: center; | ||
max-width: 100%; | ||
padding-left: 15px; | ||
padding-right: 5px; | ||
} | ||
|
||
.task-text { | ||
padding-left: 20px; | ||
padding-right: 10px; | ||
} | ||
|
||
.flexExpand { | ||
flex: 1 1 auto; | ||
} |
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,68 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing"; | ||
import { TaskComponent } from "./task.component"; | ||
import { HttpClientTestingModule } from "@angular/common/http/testing"; | ||
import { AppConfigService } from "src/app/app-config.service"; | ||
import { Tasks } from "src/app/core/model/tasks"; | ||
|
||
const getConfig = () => ({}); | ||
|
||
describe('TaskComponent', () => { | ||
let component: TaskComponent; | ||
let fixture: ComponentFixture<TaskComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
{ provide: AppConfigService, useValue: { getConfig } }, | ||
], | ||
declarations: [TaskComponent] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TaskComponent); | ||
component = fixture.componentInstance; | ||
component.task = {isDone: false, id: '123'} as Tasks; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should addTask', () => { | ||
const addTaskSpy = spyOn(component['tasksService'], 'addTask'); | ||
const task = {isDone: false} as Tasks; | ||
component.addTask(task); | ||
expect(addTaskSpy).toHaveBeenCalledOnceWith(task); | ||
}); | ||
|
||
it('should toggleTaskIsDone', () => { | ||
const updateTaskSpy = spyOn(component['tasksService'], 'updateTask'); | ||
component.toggleTaskIsDone(); | ||
expect(updateTaskSpy).toHaveBeenCalledOnceWith({isDone: true}, '123'); | ||
}); | ||
|
||
it('should deleteTask', () => { | ||
const deleteTaskSpy = spyOn(component['tasksService'], 'deleteTask'); | ||
component.deleteTask(); | ||
expect(deleteTaskSpy).toHaveBeenCalledOnceWith('123'); | ||
}); | ||
|
||
it('should deleteTask', () => { | ||
const deleteTaskSpy = spyOn(component['tasksService'], 'deleteTask'); | ||
component.deleteTask(); | ||
expect(deleteTaskSpy).toHaveBeenCalledOnceWith('123'); | ||
}); | ||
|
||
it('should isAllowed', () => { | ||
const canUpdateSpy = spyOn(component['isActionAllowed'], 'canUpdate'); | ||
const canDeleteSpy = spyOn(component['isActionAllowed'], 'canDelete'); | ||
component.isAllowed(); | ||
expect(canUpdateSpy).toHaveBeenCalledTimes(1); | ||
expect(canDeleteSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
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,49 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { Tasks } from '@model/tasks'; | ||
import { TasksService } from '@shared/tasks.service'; | ||
import { IsAllowedService } from 'src/app/overview/is-allowed.service'; | ||
|
||
@Component({ | ||
selector: 'task', | ||
templateUrl: './task.component.html', | ||
styleUrls: ['./task.component.scss'], | ||
providers: [IsAllowedService], | ||
}) | ||
export class TaskComponent implements OnInit { | ||
|
||
@Input() | ||
task: Tasks; | ||
|
||
constructor( | ||
private tasksService: TasksService, | ||
protected isActionAllowed: IsAllowedService) { | ||
console.log("constructor called") | ||
} | ||
|
||
ngOnInit(): void { | ||
this.isActionAllowed.snippet = this.task; | ||
this.isAllowed(); | ||
} | ||
|
||
addTask(task: Tasks) { | ||
this.tasksService.addTask(task); | ||
} | ||
|
||
toggleTaskIsDone() { | ||
let payload = { | ||
isDone: !this.task.isDone | ||
} | ||
this.tasksService.updateTask(payload, this.task.id); | ||
} | ||
|
||
deleteTask() { | ||
console.log("deleting task"); | ||
this.tasksService.deleteTask(this.task.id); | ||
} | ||
|
||
isAllowed() { | ||
this.isActionAllowed.canDelete(); | ||
this.isActionAllowed.canUpdate(); | ||
} | ||
|
||
} |
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.