11import { h , render , rerender } from "preact" ;
22import { testBrowser } from "../tools/tester" ;
3+ import { NotebookPage , ProfilePage } from "./app" ;
34import { cellExecuteQueue } from "./components/cell" ;
45import { Notebook } from "./components/notebook" ;
56import * as db from "./db" ;
6- import * as nb from "./notebook_root" ;
77import { assert , assertEqual , createResolvable } from "./util" ;
88
99const 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-
2211testBrowser ( async function notebook_Notebook ( ) {
2312 const mdb = db . enableMock ( ) ;
2413 await renderAnonNotebook ( ) ;
@@ -125,21 +114,21 @@ testBrowser(async function notebook_profile() {
125114 await renderProfile ( "non-existant" ) ;
126115 let avatars = document . querySelectorAll ( ".avatar" ) ;
127116 assert ( avatars . length === 0 ) ;
128- let notebooks = document . querySelectorAll ( ".most-recent ol li" ) ;
117+ let notebooks = document . querySelectorAll ( ".nb-listing ol li" ) ;
129118 assert ( notebooks . length === 0 ) ;
130119 assertEqual ( mdb . counts , { queryProfile : 1 } ) ;
131120
132121 // Try again with a real uid.
133122 await renderProfile ( db . defaultOwner . uid ) ;
134123 avatars = document . querySelectorAll ( ".avatar" ) ;
135124 assert ( avatars . length === 1 ) ;
136- notebooks = document . querySelectorAll ( ".most-recent ol li" ) ;
125+ notebooks = document . querySelectorAll ( ".nb-listing ol li" ) ;
137126 assert ( notebooks . length === 1 ) ;
138127 assertEqual ( mdb . counts , { queryProfile : 2 } ) ;
139128} ) ;
140129
141130testBrowser ( async function notebook_executeQueue ( ) {
142- const { notebookRef } = await renderAnonNotebook ( ) ;
131+ const notebookRef = await renderAnonNotebook ( ) ;
143132 // All the cells must be executed now.
144133 assertEqual ( cellExecuteQueue . length , 0 ) ;
145134 const cell1 = await notebookRef . insertCell ( 2 , "a = 0" ) ;
@@ -162,7 +151,7 @@ testBrowser(async function notebook_executeQueue() {
162151
163152testBrowser ( async function notebook_urlImport ( ) {
164153 db . enableMock ( ) ;
165- const { notebookRef } = await renderAnonNotebook ( ) ;
154+ const notebookRef = await renderAnonNotebook ( ) ;
166155 const testdataUrl = `${ location . origin } /static/testdata` ;
167156
168157 const cell1 = await notebookRef . insertCell (
@@ -201,27 +190,32 @@ function resetPage() {
201190function renderProfile ( profileUid : string ) {
202191 const promise = createResolvable ( ) ;
203192 resetPage ( ) ;
204- const el = h ( nb . NotebookRoot , {
205- onReady : promise . resolve ,
206- profileUid
193+ const el = h ( ProfilePage , {
194+ matches : {
195+ userId : profileUid
196+ } ,
197+ onReady : promise . resolve
207198 } ) ;
208199 render ( el , document . body ) ;
209200 return promise ;
210201}
211202
212- async function renderAnonNotebook ( ) : Promise < nb . NotebookRoot > {
203+ async function renderAnonNotebook ( ) : Promise < Notebook > {
213204 const promise = createResolvable ( ) ;
214205 resetPage ( ) ;
215- let notebookRoot : nb . NotebookRoot ;
216- const el = h ( nb . NotebookRoot , {
217- nbId : "default" ,
206+ let notebookRoot ;
207+ const el = h ( NotebookPage , {
208+ matches : {
209+ nbId : "default"
210+ } ,
218211 onReady : promise . resolve ,
219- ref : n => ( notebookRoot = n )
212+ ref : ref => ( notebookRoot = ref )
220213 } ) ;
221214 render ( el , document . body ) ;
222215 await promise ;
223- await notebookRoot . notebookRef . isReady ;
224- return notebookRoot ;
216+ const notebookRef = notebookRoot . componentRef ;
217+ await notebookRef . isReady ;
218+ return notebookRef ;
225219}
226220
227221async function renderNotebook ( ) : Promise < Notebook > {
0 commit comments