-
Notifications
You must be signed in to change notification settings - Fork 10
/
ViewStore.test.js
63 lines (54 loc) · 1.92 KB
/
ViewStore.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
import test from "tape"
import { when } from "mobx"
import ViewStore from "./ViewStore"
import { readFileSync } from "fs"
function stubFetch(path) {
return new Promise((resolve, reject) => {
resolve(JSON.parse(readFileSync(__dirname + "/../../dist" + path)))
})
}
test("it should be possible to open the documents overview", t => {
const viewStore = new ViewStore(stubFetch)
viewStore.showOverview()
t.equal(viewStore.currentView.name, "overview")
when(
() => viewStore.currentView.documents.state !== "pending",
() => {
t.equal(viewStore.currentView.documents.state, "fulfilled")
t.equal(viewStore.currentView.documents.value.length, 2)
t.end()
}
)
})
test("it should not be possible to read documents without login", t => {
const viewStore = new ViewStore(stubFetch)
viewStore.showDocument(1)
t.equal(viewStore.currentView.name, "document")
t.equal(viewStore.isAuthenticated, false)
when(
() => viewStore.currentView.document.state !== "pending",
() => {
t.equal(viewStore.currentView.document.state, "rejected")
t.notOk(viewStore.currentView.document.value)
t.end()
}
)
})
test("it should be possible to read documents with login", t => {
const viewStore = new ViewStore(stubFetch)
viewStore.performLogin("user", "1234", result => {
t.equal(result, true)
t.equal(viewStore.isAuthenticated, true)
t.equal(viewStore.currentUser.name, "Test user")
viewStore.showDocument(1)
t.equal(viewStore.currentView.name, "document")
when(
() => viewStore.currentView.document.state !== "pending",
() => {
t.equal(viewStore.currentView.document.state, "fulfilled")
t.equal(viewStore.currentView.document.value.text, "fun")
t.end()
}
)
})
})