-
Notifications
You must be signed in to change notification settings - Fork 8
/
schemaValidation.test.js
110 lines (100 loc) · 4.6 KB
/
schemaValidation.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
// Copyright 2018 Stanford University see Apache2.txt for license
import pupExpect from 'expect-puppeteer'
describe('Editor', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:8080/editor')
})
describe('importing a profile/template', () => {
beforeAll(async() => {
page.waitForSelector('button#ImportProfile')
await page.click('button#ImportProfile')
await pupExpect(page).toMatch('Loaded resource template file')
})
// TODO: show ajv.validate was called
// can't easily show because puppeteer is between this test and jest mocks
// it('runs validation', () => {
// })
// TODO: show it only fetches and loads any individual schema once
describe('schema valid', () => {
describe('schema url in JSON', () => {
it('displays resource template passing validation', async () => {
pupExpect(page).not.toMatch('LC Classification Number')
const fileInput = await page.$('.DropZone input[type="file"]')
await fileInput.uploadFile("__tests__/__fixtures__/lcc_v0.1.0.json")
await pupExpect(page).toMatch('LC Classification Number')
})
it('displays profile passing validation', async () => {
pupExpect(page).not.toMatch('Place Associated with a Work')
const fileInput = await page.$('.DropZone input[type="file"]')
await fileInput.uploadFile("__tests__/__fixtures__/place_profile_v0.1.0.json")
await pupExpect(page).toMatch('Place Associated with a Work')
})
})
describe('schema url not in JSON - v0.0.2 schemas used', () => {
it('displays resource template passing validation', async () => {
pupExpect(page).not.toMatch('LC Classification Number')
const fileInput = await page.$('.DropZone input[type="file"]')
await fileInput.uploadFile("__tests__/__fixtures__/lcc_v0.0.2.json")
await pupExpect(page).toMatch('LC Classification Number')
})
it('displays profile passing validation', async () => {
pupExpect(page).not.toMatch('Place Associated with a Work')
const fileInput = await page.$('.DropZone input[type="file"]')
await fileInput.uploadFile("__tests__/__fixtures__/place_profile_v0.0.2.json")
await pupExpect(page).toMatch('Place Associated with a Work')
})
})
})
describe('not schema valid', () => {
let dialog
beforeAll(async() => {
const fileInput = await page.$('.DropZone input[type="file"]')
dialog = await pupExpect(page).toDisplayDialog(() => {
fileInput.uploadFile("__tests__/__fixtures__/lcc_v0.1.0_invalid.json")
})
})
it('displays dialog', async () => {
const exp_msg = "ERROR - CANNOT USE PROFILE/RESOURCE TEMPLATE: problem validating template: Error: [ { keyword: 'required'"
await expect(dialog.message()).toMatch(exp_msg)
})
it('does not populate form from loaded file', async () => {
await dialog.dismiss()
await pupExpect(page).not.toMatch('Invalid Resource Template')
})
})
describe('unfindable schema', () => {
let dialog
beforeAll(async() => {
const fileInput = await page.$('.DropZone input[type="file"]')
dialog = await pupExpect(page).toDisplayDialog(async () => {
await fileInput.uploadFile("__tests__/__fixtures__/edition_bad_schema.json")
})
})
it('displays dialog', async () => {
const exp_msg = "ERROR - CANNOT USE PROFILE/RESOURCE TEMPLATE: problem validating template: Error: error getting json schemas TypeError: Cannot read property '1' of null"
await expect(dialog.message()).toMatch(exp_msg)
})
it('does not populate form from loaded file', async () => {
await dialog.dismiss()
await pupExpect(page).not.toMatch('Edition Bad Schema')
})
})
describe('bad JSON', async () => {
let dialog
beforeAll(async() => {
const fileInput = await page.$('.DropZone input[type="file"]')
dialog = await pupExpect(page).toDisplayDialog(async () => {
await fileInput.uploadFile("__tests__/__fixtures__/ddc_bad_json.json")
})
})
it('displays dialog', async () => {
const exp_msg = "ERROR - CANNOT USE PROFILE/RESOURCE TEMPLATE: problem parsing JSON template: SyntaxError: Unexpected token } in JSON at position"
await expect(dialog.message()).toMatch(exp_msg)
})
it('does not populate form from loaded file', async () => {
await dialog.dismiss()
await pupExpect(page).not.toMatch('DDC Bad JSON')
})
})
})
})