cosmos-explorer/test/notebooks/notebookTestUtils.ts
Srinath Narayanan c1937ca464
Added the Self Serve Data Model (#367)
* added recursion and inition decorators

* working version

* added todo comment and removed console.log

* Added Recursive add

* removed type requirement

* proper resolution of promises

* added custom element and base class

* Made selfServe standalone page

* Added custom renderer as async type

* Added overall defaults

* added inital open from data explorer

* removed landingpage

* added feature for self serve type

* renamed sqlx->example and added invalid type

* Added comments for Example

* removed unnecessary changes

* Resolved PR comments

Added tests
Moved onSubmt and initialize inside base class
Moved testExplorer to separate folder
made fields of SelfServe Class non static

* fixed lint errors

* fixed compilation errors

* Removed reactbinding changes

* renamed dropdown -> choice

* Added SelfServeComponent

* Addressed PR comments

* merged master

* added selfservetype.none for emulator and hosted experience

* fixed formatting errors

* Removed "any" type

* undid package.json changes
2021-01-19 22:42:45 -08:00

52 lines
1.9 KiB
TypeScript

import { ElementHandle, Frame } from "puppeteer";
import * as path from "path";
export const NOTEBOOK_OPERATION_DELAY = 5000;
export const RENDER_DELAY = 2500;
export const uploadNotebookIfNotExist = async (frame: Frame, notebookName: string): Promise<ElementHandle<Element>> => {
const notebookNode = await getNotebookNode(frame, notebookName);
if (notebookNode) {
return notebookNode;
}
const uploadNotebookPath = path.join(__dirname, "testNotebooks", notebookName);
const notebookResourceTree = await frame.waitForSelector(".notebookResourceTree");
const treeNodeHeadersBeforeUpload = await notebookResourceTree.$$(".treeNodeHeader");
const ellipses = await treeNodeHeadersBeforeUpload[2].$("button");
await ellipses.click();
await frame.waitFor(RENDER_DELAY);
const menuItems = await frame.$$(".ms-ContextualMenu-item");
await menuItems[4].click();
const uploadFileButton = await frame.waitForSelector("#importFileButton");
uploadFileButton.click();
const fileChooser = await page.waitForFileChooser();
fileChooser.accept([uploadNotebookPath]);
const submitButton = await frame.waitForSelector("#uploadFileButton");
await submitButton.click();
await frame.waitFor(NOTEBOOK_OPERATION_DELAY);
return await getNotebookNode(frame, notebookName);
};
export const getNotebookNode = async (frame: Frame, uploadNotebookName: string): Promise<ElementHandle<Element>> => {
const notebookResourceTree = await frame.waitForSelector(".notebookResourceTree");
let currentNotebookNode: ElementHandle<Element>;
const treeNodeHeaders = await notebookResourceTree.$$(".treeNodeHeader");
for (let i = 1; i < treeNodeHeaders.length; i++) {
currentNotebookNode = treeNodeHeaders[i];
const nodeLabel = await currentNotebookNode.$eval(".nodeLabel", element => element.textContent);
if (nodeLabel === uploadNotebookName) {
return currentNotebookNode;
}
}
return undefined;
};