Skip to content
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

fix: don't set percent to 0 for NEEDS-ACTION #2365

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
* Update linked calendar of this task
*
* @param {object} calendar the calendar
* @memberof Contact

Check warning on line 146 in src/models/task.js

View workflow job for this annotation

GitHub Actions / eslint

The type 'Contact' is undefined
*/
updateCalendar(calendar) {
this.calendar = calendar
Expand Down Expand Up @@ -346,8 +346,10 @@
this.setComplete(1)
}
} else if (status === 'NEEDS-ACTION' || status === null) {
this.setComplete(0)
this.setCompleted(false)
if (this.complete === 100) {
this.setComplete(99)
}
}
}

Expand Down
20 changes: 15 additions & 5 deletions tests/javascript/unit/models/task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ describe('task', () => {
expect(task.completedDate).not.toEqual(null)
})

it('Should set complete to 0 when status is "NEEDS-ACTION".', () => {
it('Should set complete to <100 when status is "NEEDS-ACTION".', () => {
const task = new Task(loadICS('vcalendars/vcalendar-default'), {})
task.complete = 100
task.status = 'NEEDS-ACTION'
expect(task.complete).toEqual(0)
// Check that property gets removed instead of being set to zero
expect(task.complete).toBeLessThan(100)
const complete = task.vtodo.getFirstPropertyValue('percent-complete')
expect(complete).toEqual(null)
expect(complete).toEqual(99)
expect(task.completed).toEqual(false)
expect(task.completedDate).toEqual(null)
})

it('Should not adjust complete when not completed and status is "NEEDS-ACTION".', () => {
const task = new Task(loadICS('vcalendars/vcalendar-default'), {})
task.complete = 90
task.status = 'NEEDS-ACTION'
expect(task.complete).toBeLessThan(100)
const complete = task.vtodo.getFirstPropertyValue('percent-complete')
expect(complete).toEqual(90)
expect(task.completed).toEqual(false)
expect(task.completedDate).toEqual(null)
})
Expand Down Expand Up @@ -213,7 +223,7 @@ describe('task', () => {
expect(complete).toEqual(null)
})

it('Indicates cloesed when completed or cancelled', () => {
it('Indicates closed when completed or cancelled', () => {
const task = new Task(loadICS('vcalendars/vcalendar-default'), {})
task.status = 'CANCELLED'
expect(task.closed).toEqual(true)
Expand Down
Loading