forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.test.ts
More file actions
140 lines (110 loc) · 3.48 KB
/
Copy pathexport.test.ts
File metadata and controls
140 lines (110 loc) · 3.48 KB
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
import './dom-parser.js'
import { cleanStores } from 'nanostores'
import { deepStrictEqual, equal } from 'node:assert'
import { readFile } from 'node:fs/promises'
import { afterEach, beforeEach, test } from 'node:test'
import { setTimeout } from 'node:timers/promises'
import {
clearExportingSelections,
exporting,
exportingCategories,
exportingFeeds,
exportingFeedsByCategory,
getInternalBlob,
getOPMLBlob,
handleImportFile,
importedCategories,
importedFeeds,
importedFeedsByCategory,
selectAllExportingFeeds,
submitImport,
submiting,
toggleExportingCategory,
toggleExportingFeed
} from '../index.js'
import { cleanClientTest, enableClientTest } from './utils.js'
async function loadFile(filePath: string): Promise<string> {
let jsonContent = await readFile(filePath, 'utf8')
let jsonFile = new File([jsonContent], 'feeds.json', {
type: 'application/json'
})
handleImportFile(jsonFile)
await setTimeout(100)
return jsonContent
}
beforeEach(async () => {
enableClientTest()
await loadFile('test/export-internal-example.json')
await submitImport()
})
afterEach(async () => {
cleanStores(
importedFeedsByCategory,
importedCategories,
importedFeeds,
submiting,
exportingFeedsByCategory,
exporting,
exportingCategories,
exportingFeeds
)
await setTimeout(10)
await cleanClientTest()
})
test('should initialize with empty states', () => {
deepStrictEqual(exportingFeedsByCategory.get(), [])
deepStrictEqual(exportingCategories.get(), [])
deepStrictEqual(exportingFeeds.get(), [])
equal(exporting.get(), false)
})
test('should select all exporting feeds', async () => {
selectAllExportingFeeds()
let categories = exportingCategories.get()
let feeds = exportingFeeds.get()
equal(categories.length > 0, true)
equal(feeds.length > 0, true)
})
test('should clear export selections', async () => {
selectAllExportingFeeds()
clearExportingSelections()
equal(exportingCategories.get().length, 0)
equal(exportingFeeds.get().length, 0)
})
test('should toggle exporting category', async () => {
let categoryId = 'general'
clearExportingSelections()
toggleExportingCategory(categoryId)
let selectedCategories = exportingCategories.get()
let selectedFeeds = exportingFeeds.get()
equal(selectedCategories.includes(categoryId), true)
equal(selectedFeeds.length > 0, true)
toggleExportingCategory(categoryId)
selectedCategories = exportingCategories.get()
equal(selectedCategories.includes(categoryId), false)
})
test('should toggle exporting feed', async () => {
let feedId = 'H4RZpnXPjlj_Hzl08ipBw'
let categoryId = 'general'
clearExportingSelections()
toggleExportingFeed(feedId, categoryId)
let selectedFeeds = exportingFeeds.get()
let selectedCategories = exportingCategories.get()
equal(selectedFeeds.includes(feedId), true)
equal(selectedCategories.includes(categoryId), true)
toggleExportingFeed(feedId, categoryId)
selectedFeeds = exportingFeeds.get()
selectedCategories = exportingCategories.get()
equal(selectedFeeds.includes(feedId), false)
equal(selectedCategories.includes(categoryId), false)
})
test('should generate OPML blob', async () => {
selectAllExportingFeeds()
let blob = getOPMLBlob()
equal(blob.type, 'application/xml')
let text = await blob.text()
equal(text.includes('https://blog.appsignal.com/feed.xml'), true)
})
test('should generate internal JSON blob', async () => {
let blob = await getInternalBlob(true)
equal(blob.type, 'application/json')
})