-
-
Notifications
You must be signed in to change notification settings - Fork 553
/
ipywidgets.spec.ts
106 lines (102 loc) · 2.99 KB
/
ipywidgets.spec.ts
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
import { toArray } from "rxjs/operators";
import Immutable from "immutable";
import { emptyCodeCell, appendCellToNotebook } from "@nteract/commutable";
import { actions, createContentRef, makeDocumentRecord } from "@nteract/core";
import { fixtureCommutable } from "@nteract/fixtures";
import { ipywidgetsModel$ } from "../src/ipywidgets";
import { from } from "rxjs";
const monocellDocument = makeDocumentRecord({
notebook: appendCellToNotebook(fixtureCommutable, emptyCodeCell)
});
describe("ipywidgetsModel$", () => {
test("emits AppendOutput if comm_open for LinkModel is sent", done => {
const contentRef = createContentRef();
const comm_id = "a_comm_id";
const messages = [
{
header: { msg_type: "comm_open" },
content: {
comm_id,
data: {
state: {
_model_name: "LinkModel"
}
}
}
}
];
const kernel = { channels: from(messages) };
const resultingActions = [];
ipywidgetsModel$(kernel, monocellDocument, contentRef).subscribe(x =>
resultingActions.push(x)
);
expect(resultingActions[1]).toEqual(
actions.appendOutput({
id: monocellDocument.getIn(["notebook", "cellOrder"]).first(),
contentRef,
output: {
output_type: "display_data",
data: {
"application/vnd.jupyter.widget-view+json": {
model_id: comm_id,
version_major: 2,
version_minor: 0
}
},
metadata: {},
transient: {}
}
})
);
expect(resultingActions).toHaveLength(2);
done();
});
test("does not emit anything for non-comm open messages", done => {
const contentRef = createContentRef();
const comm_id = "a_comm_id";
const messages = [
{
header: { msg_type: "display_data" },
content: {
comm_id,
data: {
state: {
_model_name: "LinkModel"
}
}
}
}
];
const kernel = { channels: from(messages) };
const resultingActions = [];
ipywidgetsModel$(kernel, monocellDocument, contentRef).subscribe(x =>
resultingActions.push(x)
);
expect(resultingActions).toHaveLength(0);
done();
});
test("does not emit an appendOutput for non-notebook types", done => {
const contentRef = createContentRef();
const comm_id = "a_comm_id";
const messages = [
{
header: { msg_type: "comm_open" },
content: {
comm_id,
data: {
state: {
_model_name: "LinkModel"
}
}
}
}
];
const kernel = { channels: from(messages) };
const resultingActions = [];
ipywidgetsModel$(kernel, null, contentRef).subscribe(x =>
resultingActions.push(x)
);
expect(resultingActions[1]).toBeNull();
done();
});
});