-
Notifications
You must be signed in to change notification settings - Fork 115
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
Manage tasks by statuses #130
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
40100df
build: fix angular.json to allow wallaby to run correctly
2bc4d21
feat(tasks): allow to mark task as done
f620123
feat(tasks): sort tasks by status
f3ae733
feat(tasks): add ability to remove all done tasks
c04863e
feat(tasks): add deleteAll method to remove tasks bulk
a637cfa
feat(tasks): support additional statuses
a20eb12
test(tasks): add tests for task sorting
93c7d40
test(tasks): cover task status changes
67b001a
feat(tasks): allow to reopen finished tasks
647da8d
refactor(tasks): introduce local variable to prevent duplicated calcu…
41ae596
refactor: enable strict mode
63a7778
feat(tasks): add animation for addition and removal of items
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {TinyLetDirective} from 'app/shared/tiny-let/tiny-let.directive'; | ||
|
||
@NgModule({ | ||
exports: [ | ||
TinyLetDirective | ||
], | ||
declarations: [ | ||
TinyLetDirective | ||
] | ||
}) | ||
export class SharedModule { } |
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,25 @@ | ||
import { Directive, Input, TemplateRef, ViewContainerRef, Inject } from '@angular/core'; | ||
|
||
export class LetContext<T> { | ||
constructor( | ||
private readonly directive: TinyLetDirective<T> | ||
) { } | ||
|
||
get tinyLet(): T | null { | ||
return this.directive.tinyLet; | ||
} | ||
} | ||
|
||
@Directive({ | ||
selector: '[tinyLet]' | ||
}) | ||
export class TinyLetDirective<T> { | ||
@Input() tinyLet: T | null = null; | ||
|
||
constructor( | ||
@Inject(ViewContainerRef) viewContainer: ViewContainerRef, | ||
@Inject(TemplateRef) templateRef: TemplateRef<LetContext<T>> | ||
) { | ||
viewContainer.createEmbeddedView(templateRef, new LetContext<T>(this)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { LocalTaskService } from 'app/tasks/local-task.service'; | ||
import { Observable } from 'rxjs'; | ||
import { Task } from './task'; | ||
import {TestBed} from '@angular/core/testing'; | ||
import {LocalTaskService} from 'app/tasks/local-task.service'; | ||
import {EMPTY, Observable} from 'rxjs'; | ||
import {Task, TaskStatus} from './task'; | ||
|
||
describe('LocalTaskService', () => { | ||
const id = 'de4f576e-d1b5-488a-8c77-63d4c8726909'; | ||
const name = 'Doing the do!'; | ||
const mockTask = `{"id":"${id}","name":"${name}"}`; | ||
|
||
let taskService: LocalTaskService; | ||
|
||
beforeEach(() => { | ||
|
@@ -16,40 +12,100 @@ describe('LocalTaskService', () => { | |
}); | ||
|
||
taskService = TestBed.inject(LocalTaskService); | ||
spyOn(localStorage, 'getItem').and.callFake(() => `[${mockTask}]`); | ||
spyOn(localStorage, 'setItem').and.callFake(() => {}); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(taskService).toBeTruthy(); | ||
}); | ||
describe('single task in store', () => { | ||
beforeEach(() => { | ||
spyOn(localStorage, 'getItem').and.callFake(() => `[${mockTask}]`); | ||
spyOn(localStorage, 'setItem').and.callFake(() => { }); | ||
}); | ||
|
||
it('should return tasks from local storage', () => { | ||
// when | ||
const taskList$: Observable<Task[]> = taskService.getAll(); | ||
const id = 'de4f576e-d1b5-488a-8c77-63d4c8726909'; | ||
const name = 'Doing the do!'; | ||
const status = String(TaskStatus.Todo); | ||
const mockTask = `{"id":"${id}","name":"${name}","status":"${status}"}`; | ||
it('should be created', () => { | ||
expect(taskService).toBeTruthy(); | ||
}); | ||
|
||
it('should return tasks from local storage', () => { | ||
// when | ||
const taskList$: Observable<Task[]> = taskService.getAll(); | ||
|
||
// then | ||
expect(localStorage.getItem).toHaveBeenCalled(); | ||
taskList$.subscribe(taskList => { | ||
expect(taskList.length).toBe(1); | ||
expect(taskList[0].name).toEqual(name); | ||
// then | ||
expect(localStorage.getItem).toHaveBeenCalled(); | ||
taskList$.subscribe(taskList => { | ||
expect(taskList.length).toBe(1); | ||
expect(taskList[0].name).toEqual(name); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should write task to local storage', () => { | ||
// when | ||
taskService.create('Drinking the drink!'); | ||
it('should write task to local storage', () => { | ||
// when | ||
taskService.create('Drinking the drink!'); | ||
|
||
// then | ||
expect(localStorage.setItem).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should delete task from local storage', () => { | ||
// when | ||
taskService.delete(id); | ||
|
||
// then | ||
expect(localStorage.getItem).toHaveBeenCalled(); | ||
expect(localStorage.setItem).toHaveBeenCalled(); | ||
}); | ||
|
||
// then | ||
expect(localStorage.setItem).toHaveBeenCalled(); | ||
it('should set new status for task', () => { | ||
// when | ||
taskService.setStatus(id, TaskStatus.Done); | ||
|
||
// then | ||
expect(localStorage.setItem).toHaveBeenCalledWith('tiny.tasks', JSON.stringify([ | ||
{id, name, status: TaskStatus.Done} | ||
])); | ||
}); | ||
|
||
it('should return updated task', () => { | ||
// when | ||
const result = taskService.setStatus(id, TaskStatus.Done); | ||
|
||
// then | ||
const subscription = result.subscribe(value => { | ||
expect(value).toEqual({id, name, status: TaskStatus.Done}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this case it could be that the expect is not even called but the test would not fail. Better use done function for tests like that |
||
}); | ||
subscription.unsubscribe(); | ||
}); | ||
|
||
it('should return completed observable if no task was found to update', () => { | ||
// when | ||
const result = taskService.setStatus('id123', TaskStatus.Done); | ||
|
||
// then | ||
expect(result).toEqual(EMPTY); | ||
}); | ||
}); | ||
describe('multiple tasks', () => { | ||
beforeEach(() => { | ||
spyOn(localStorage, 'getItem').and.callFake(() => JSON.stringify([ | ||
{ id: 'id007', name: 'bang', status: TaskStatus.Todo }, | ||
{ id: 'id123', name: 'say hello', status: TaskStatus.Todo }, | ||
{ id: 'id1234', name: 'say goodbye', status: TaskStatus.Cancelled }, | ||
{ id: 'id000', name: 'todo not todo', status: TaskStatus.Todo }, | ||
])); | ||
spyOn(localStorage, 'setItem').and.callFake(() => { }); | ||
}); | ||
|
||
it('should delete task from local storage', () => { | ||
// when | ||
taskService.delete(id); | ||
it('should delete a list of tasks from local storage', () => { | ||
// when | ||
taskService.deleteAll(['id123', 'id1234']); | ||
|
||
// then | ||
expect(localStorage.getItem).toHaveBeenCalled(); | ||
expect(localStorage.setItem).toHaveBeenCalled(); | ||
// then | ||
expect(localStorage.setItem).toHaveBeenCalledWith('tiny.tasks', JSON.stringify([ | ||
{id: 'id007', name: 'bang', status: TaskStatus.Todo}, | ||
{id: 'id000', name: 'todo not todo', status: TaskStatus.Todo} | ||
])); | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know its already broken without your changes (#brokenWindow) but i would go for an "update" function which is just called in any case because every function is doing the same right now.