Skip to content

Commit 38b943b

Browse files
qti3episcisaureus
authored andcommitted
Update nb_test
1 parent dd2499c commit 38b943b

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/app.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ function bind(C, bindProps: BindProps) {
5252
return class extends Component<any, BindState> {
5353
state = { data: null, error: null };
5454
prevMatches = null;
55+
componentRef;
56+
57+
private onReady() {
58+
if (this.props.onReady) this.props.onReady();
59+
}
5560

5661
async loadData() {
5762
if (equal(this.props.matches, this.prevMatches)) return;
@@ -74,7 +79,8 @@ function bind(C, bindProps: BindProps) {
7479
const { data, error } = this.state;
7580
if (error) return <ErrorPage message={error} />;
7681
if (!data) return <Loading />;
77-
return <C {...this.props} {...data} />;
82+
this.onReady();
83+
return <C ref={r => (this.componentRef = r)} {...this.props} {...data} />;
7884
}
7985
};
8086
}

src/nb_test.ts

+18-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
import { h, render, rerender } from "preact";
22
import { testBrowser } from "../tools/tester";
3+
import { NotebookPage, ProfilePage } from "./app";
34
import { cellExecuteQueue } from "./components/cell";
45
import { Notebook } from "./components/notebook";
56
import * as db from "./db";
6-
import * as nb from "./notebook_root";
77
import { assert, assertEqual, createResolvable, delay } from "./util";
88

99
const DOC_TITLE = "Anonymous Notebook";
1010

11-
testBrowser(async function notebook_NotebookRoot() {
12-
const mdb = db.enableMock();
13-
resetPage();
14-
const el = h(nb.NotebookRoot, {});
15-
render(el, document.body);
16-
await flush();
17-
assertEqual(mdb.counts, { queryLatest: 1 });
18-
const c = document.body.getElementsByTagName("div")[0];
19-
assertEqual(c.className, "notebook");
20-
});
21-
2211
testBrowser(async function notebook_Notebook() {
2312
const mdb = db.enableMock();
2413
await renderAnonNotebook();
@@ -140,7 +129,7 @@ testBrowser(async function notebook_profile() {
140129
});
141130

142131
testBrowser(async function notebook_executeQueue() {
143-
const { notebookRef } = await renderAnonNotebook();
132+
const notebookRef = await renderAnonNotebook();
144133
// All the cells must be executed now.
145134
assertEqual(cellExecuteQueue.length, 0);
146135
const cell1 = await notebookRef.insertCell(2, "a = 0");
@@ -163,7 +152,7 @@ testBrowser(async function notebook_executeQueue() {
163152

164153
testBrowser(async function notebook_urlImport() {
165154
db.enableMock();
166-
const { notebookRef } = await renderAnonNotebook();
155+
const notebookRef = await renderAnonNotebook();
167156
const testdataUrl = `${location.origin}/repo/src/testdata`;
168157

169158
const cell1 = await notebookRef.insertCell(1, `
@@ -196,27 +185,32 @@ function resetPage() {
196185
function renderProfile(profileUid: string) {
197186
const promise = createResolvable();
198187
resetPage();
199-
const el = h(nb.NotebookRoot, {
200-
onReady: promise.resolve,
201-
profileUid
188+
const el = h(ProfilePage, {
189+
matches: {
190+
userId: profileUid
191+
},
192+
onReady: promise.resolve
202193
});
203194
render(el, document.body);
204195
return promise;
205196
}
206197

207-
async function renderAnonNotebook(): Promise<nb.NotebookRoot> {
198+
async function renderAnonNotebook(): Promise<Notebook> {
208199
const promise = createResolvable();
209200
resetPage();
210-
let notebookRoot: nb.NotebookRoot;
211-
const el = h(nb.NotebookRoot, {
212-
nbId: "default",
201+
let notebookRoot;
202+
const el = h(NotebookPage, {
203+
matches: {
204+
nbId: "default"
205+
},
213206
onReady: promise.resolve,
214-
ref: n => (notebookRoot = n)
207+
ref: ref => (notebookRoot = ref)
215208
});
216209
render(el, document.body);
217210
await promise;
218-
await notebookRoot.notebookRef.isReady;
219-
return notebookRoot;
211+
const notebookRef = notebookRoot.componentRef;
212+
await notebookRef.isReady;
213+
return notebookRef;
220214
}
221215

222216
async function renderNotebook(): Promise<Notebook> {

0 commit comments

Comments
 (0)