forked from jonathangomz/notion_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.dart
180 lines (154 loc) · 6.45 KB
/
utils_test.dart
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import 'package:notion_api/notion/general/types/notion_types.dart';
import 'package:notion_api/utils/utils.dart';
import 'package:test/test.dart';
void main() {
group('Utils tests (General)', () {
test('Check if a dynamic field is a list (List)', () {
dynamic field = [1, 2, 3];
bool isList = fieldIsList(field);
expect(isList, true);
});
test('Check if a dynamic field is a list (Map)', () {
dynamic field = {1: 'A', 2: 'B'};
bool isList = fieldIsList(field);
expect(isList, false);
});
test('Check if a dynamic field is a list (String)', () {
dynamic field = 'ABC';
bool isList = fieldIsList(field);
expect(isList, false);
});
test('Get the property type (with type)', () {
Map<String, dynamic> titleField = {
'type': 'title',
'title': {'text': []}
};
Map<String, dynamic> richTextField = {
'type': 'rich_text',
'rich_text': {'text': []}
};
Map<String, dynamic> multiSelectField = {
'type': 'multi_select',
'multi_select': []
};
PropertiesTypes titleType = extractPropertyType(titleField);
PropertiesTypes richTextType = extractPropertyType(richTextField);
PropertiesTypes multiSelectType = extractPropertyType(multiSelectField);
expect(titleType, PropertiesTypes.Title);
expect(richTextType, PropertiesTypes.RichText);
expect(multiSelectType, PropertiesTypes.MultiSelect);
});
test('Get the property type (without type)', () {
Map<String, dynamic> titleField = {
'title': {'text': []}
};
Map<String, dynamic> richTextField = {
'rich_text': {'text': []}
};
Map<String, dynamic> multiSelectField = {'multi_select': []};
PropertiesTypes titleType = extractPropertyType(titleField);
PropertiesTypes richTextType = extractPropertyType(richTextField);
PropertiesTypes multiSelectType = extractPropertyType(multiSelectField);
expect(titleType, PropertiesTypes.Title);
expect(richTextType, PropertiesTypes.RichText);
expect(multiSelectType, PropertiesTypes.MultiSelect);
});
test('Get the property type (no type)', () {
Map<String, dynamic> field = {};
PropertiesTypes type = extractPropertyType(field);
expect(type, PropertiesTypes.None);
});
});
group('Utils tests (ObjectTypes) =>', () {
test('Return an ObjectTypes type', () {
ObjectTypes type1 = stringToObjectType('invali_string');
ObjectTypes type2 = stringToObjectType('database');
ObjectTypes type3 = stringToObjectType('block');
ObjectTypes type4 = stringToObjectType('error');
ObjectTypes type5 = stringToObjectType('page');
expect([type1, type2, type3, type4, type5],
everyElement(isA<ObjectTypes>()));
expect(type1, ObjectTypes.None);
expect(type2, ObjectTypes.Database);
expect(type3, ObjectTypes.Block);
expect(type4, ObjectTypes.Error);
expect(type5, ObjectTypes.Page);
});
test('Invalid string return None type', () {
ObjectTypes type1 = stringToObjectType('invali_string');
ObjectTypes type2 = stringToObjectType('asdlfknasdkjl');
ObjectTypes type3 = stringToObjectType('');
expect([type1, type2, type3], everyElement(ObjectTypes.None));
});
});
group('Utils tests (BlockTypes) =>', () {
test('Return an ObjectTypes type', () {
BlockTypes type1 = stringToBlockType('invalid_string');
BlockTypes type2 = stringToBlockType('heading_2');
BlockTypes type3 = stringToBlockType('paragraph');
BlockTypes type4 = stringToBlockType('to_do');
BlockTypes type5 = stringToBlockType('toogle');
expect(
[type1, type2, type3, type4, type5], everyElement(isA<BlockTypes>()));
expect(type1, BlockTypes.None);
expect(type2, BlockTypes.H2);
expect(type3, BlockTypes.Paragraph);
expect(type4, BlockTypes.ToDo);
expect(type5, BlockTypes.Toggle);
});
test('Invalid string return None type', () {
BlockTypes type1 = stringToBlockType('invalid_string');
BlockTypes type2 = stringToBlockType('asdlfknasdkjl');
BlockTypes type3 = stringToBlockType('');
expect([type1, type2, type3], everyElement(BlockTypes.None));
});
});
group('Utils tests (PropertiesTypes) =>', () {
test('Return an ObjectTypes type', () {
PropertiesTypes type1 = stringToPropertyType('invalid_string');
PropertiesTypes type2 = stringToPropertyType('title');
PropertiesTypes type3 = stringToPropertyType('rich_text');
PropertiesTypes type4 = stringToPropertyType('number');
PropertiesTypes type5 = stringToPropertyType('select');
expect([type1, type2, type3, type4, type5],
everyElement(isA<PropertiesTypes>()));
expect(type1, PropertiesTypes.None);
expect(type2, PropertiesTypes.Title);
expect(type3, PropertiesTypes.RichText);
expect(type4, PropertiesTypes.Number);
expect(type5, PropertiesTypes.Select);
});
test('Invalid string return None type', () {
PropertiesTypes type1 = stringToPropertyType('invalid_string');
PropertiesTypes type2 = stringToPropertyType('asdlfknasdkjl');
PropertiesTypes type3 = stringToPropertyType('');
expect([type1, type2, type3], everyElement(PropertiesTypes.None));
});
});
group('(Types to String) || (String to Type tests) =>', () {
test('Block types', () {
String strParagraph = blockTypeToString(BlockTypes.Paragraph);
String strBulleted = blockTypeToString(BlockTypes.BulletedListItem);
String strNumbered = blockTypeToString(BlockTypes.NumberedListItem);
String strToogle = blockTypeToString(BlockTypes.Toggle);
String strChild = blockTypeToString(BlockTypes.Child);
expect(strParagraph, 'paragraph');
expect(strBulleted, 'bulleted_list_item');
expect(strNumbered, 'numbered_list_item');
expect(strToogle, 'toggle');
expect(strChild, 'child_page');
});
test('None types', () {
String propertyType = propertyTypeToString(PropertiesTypes.None);
String blockType = blockTypeToString(BlockTypes.None);
String objectType = objectTypeToString(ObjectTypes.None);
String parentType = parentTypeToString(ParentType.None);
expect([propertyType, blockType, objectType, parentType],
everyElement(isEmpty));
});
test('Page types', () {
String page = parentTypeToString(ParentType.Page);
expect(page, 'page_id');
});
});
}