/
test.js
127 lines (114 loc) · 3.11 KB
/
test.js
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
import test from 'ava'
import weft from './index'
test.before(() => {
if (!process.env.API_KEY) {
throw new Error('Need an API Key')
}
})
weft.apiKey(process.env.API_KEY)
test('Api Key is set', t => {
const apiKey = weft.apiKey()
t.not(apiKey, '')
})
const list = weft.list()
test('List of fonts request should be succeed', async t => {
await list.then(result => {
t.true(Array.isArray(result))
t.true(result.length > 0)
result.forEach(item => {
t.is(typeof item.family, 'string')
})
})
})
const trendingFonts = weft.list({}, weft.sortBy.TRENDING)
test('List of trending fonts request should be succeed', async t => {
await trendingFonts.then(result => {
t.true(Array.isArray(result))
t.true(result.length > 0)
})
})
const listWithFields = weft.list({
category: true,
files: true,
lastModified: true,
subsets: true,
variants: true,
version: true
})
test('List of fonts request with complete fields should be succeed', async t => {
await listWithFields.then(result => {
result.forEach(item => {
t.true(Array.isArray(item.variants))
t.true(Array.isArray(item.subsets))
t.is(typeof item.family, 'string')
t.is(typeof item.category, 'string')
t.is(typeof item.lastModified, 'string')
t.is(typeof item.files, 'object')
})
})
})
const viewFonts = weft.view('Open Sans')
test('"Open Sans" properties font should be valid', async t => {
await viewFonts.then(result => {
t.is(result.family, 'Open Sans')
t.is(result.category, 'sans-serif')
t.true(result.variants.includes('italic'))
t.true(result.subsets.includes('greek-ext'))
})
})
const searchFonts = weft.search('open')
test('Search "Open Sans" should be exists', async t => {
await searchFonts.then(result => {
let found = false
result.forEach(item => {
if (item.family.toLowerCase() === 'open sans') {
found = true
}
})
t.true(found)
})
})
const searchFontsWithOptions = weft.search('mont', {
fields: {
subsets: true,
variants: true
},
sortBy: weft.sortBy.TRENDING,
subsets: {
vietnamese: true
},
variants: {
black: true
}
})
test('Search "Montserrat" with search criteria subset: vietnamese, variant: black should be exists', async t => {
await searchFontsWithOptions.then(result => {
let found = false
let hasSubset = false
let hasVariant = false
result.forEach(item => {
if (item.family.toLowerCase() === 'montserrat') {
found = true
hasSubset = item.subsets.includes('vietnamese')
hasVariant = item.variants.includes('900')
}
})
t.true(found)
t.true(hasSubset)
t.true(hasVariant)
})
})
test('Embed url should be valid', t => {
t.is(weft.embedUrl('Montserrat', {
subsets: {
vietnamese: true
},
variants: {
italic: true,
bold: true
}
}), '//fonts.googleapis.com/css?family=Montserrat:400i,700&subset=vietnamese')
})
test('Embed url with string should be valid', t => {
t.is(weft.embedUrl('Montserrat', '400i,700', 'vietnamese'), '//fonts.googleapis.com/css?family=Montserrat:400i,700&subset=vietnamese')
})