๐Ÿ“ฆ amake / orgro

๐Ÿ“„ capture_test.dart ยท 108 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108import 'package:flutter_test/flutter_test.dart';
import 'package:org_flutter/org_flutter.dart';
import 'package:orgro/src/capture.dart';

void main() {
  group('Capture URI', () {
    final now = DateTime(2024, 6, 1, 12, 0, 0);
    test('URL, title, body', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&url=http://example.com/foo&title=Foo+Bar&body=baz+buzz',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* [[http://example.com/foo][Foo Bar]]
  Captured On: [2024-06-01 Sat 12:00]

  baz buzz
''');
    });
    test('URL, body', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&url=http://example.com/foo&body=baz+buzz',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* [[http://example.com/foo]]
  Captured On: [2024-06-01 Sat 12:00]

  baz buzz
''');
    });
    test('Title, body', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&title=Foo+Bar&body=baz+buzz',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* Foo Bar
  Captured On: [2024-06-01 Sat 12:00]

  baz buzz
''');
    });
    test('URL, title', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&url=http://example.com/foo&title=Foo+Bar',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* [[http://example.com/foo][Foo Bar]]
  Captured On: [2024-06-01 Sat 12:00]
''');
    });
    test('URL only', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&url=http://example.com/foo',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* [[http://example.com/foo]]
  Captured On: [2024-06-01 Sat 12:00]
''');
    });
    test('Title only', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&title=Foo+Bar',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* Foo Bar
  Captured On: [2024-06-01 Sat 12:00]
''');
    });
    test('Body only', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&body=baz+buzz',
      );
      final doc = OrgDocument.parse('');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* Captured On: [2024-06-01 Sat 12:00]

  baz buzz
''');
    });
    test('With existing content', () {
      final uri = Uri.parse(
        'org-protocol://capture?template=foo&url=http://example.com/foo&title=Foo+Bar&body=baz+buzz',
      );
      final doc = OrgDocument.parse('* foo bar');
      final (newDoc, newSection) = captureUriToSection(doc, uri, now);
      expect(newDoc.toMarkup(), '''
* foo bar
* [[http://example.com/foo][Foo Bar]]
  Captured On: [2024-06-01 Sat 12:00]

  baz buzz
''');
    });
  });
}