-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): Task to Markdown Conversion (#442)
* fix(frontend): Correctly convert tasks to markdown Closes: #441 * fix(frontend): Don't collapse tasks by default * test(frontend): Add test for parsing task lists
- Loading branch information
Showing
2 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
frontend/src/app/assignment/modules/edit-assignment/task-markdown.service.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 {TestBed} from '@angular/core/testing'; | ||
import {TaskMarkdownService} from './task-markdown.service'; | ||
import Task from '../../model/task'; | ||
import {TaskService} from '../../services/task.service'; | ||
|
||
describe(TaskMarkdownService.name, () => { | ||
let md: TaskMarkdownService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [TaskService, TaskMarkdownService], | ||
}); | ||
md = TestBed.inject(TaskMarkdownService); | ||
}); | ||
|
||
const tasks: Task[] = [ | ||
{ | ||
_id: 'A', description: 'A', points: 1, children: [ | ||
{_id: 'A.1', description: 'A.1', points: 2, children: []}, | ||
], | ||
}, | ||
// See https://github.com/fujaba/fulib.org/issues/441. | ||
// This must output as a ## headline. | ||
{_id: 'B', description: 'B', points: -1, children: []}, | ||
// And to avoid C becoming a child of B, it must also output as a ## headline. | ||
{_id: 'C', description: 'C', points: 3, children: []}, | ||
]; | ||
const markdown = `\ | ||
## A (1P)<!--{"_id":"A"}--> | ||
- A.1 (2P)<!--{"_id":"A.1"}--> | ||
## B (-1P)<!--{"_id":"B"}--> | ||
## C (3P)<!--{"_id":"C"}--> | ||
`; | ||
|
||
it('should render markdown', () => { | ||
const actual = md.renderTasks(tasks); | ||
expect(actual).toBe(markdown); | ||
}); | ||
|
||
it('should parse markdown', () => { | ||
const actual = md.parseTasks(markdown); | ||
expect(actual).toEqual(tasks); | ||
}); | ||
}); |
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