How to use loadPromise method in storybook-root

Best JavaScript code snippet using storybook-root

TileLoaderTest.ts

Source:TileLoaderTest.ts Github

copy

Full Screen

1/*2 * Copyright (C) 2019-2021 HERE Europe B.V.3 * Licensed under Apache 2.0, see full license in LICENSE4 * SPDX-License-Identifier: Apache-2.05 */6// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions7import { DecodedTile, Geometry, ITileDecoder, TileInfo } from "@here/harp-datasource-protocol";8import {9 Projection,10 TileKey,11 TilingScheme,12 webMercatorProjection,13 webMercatorTilingScheme14} from "@here/harp-geoutils";15import { DataSource, MapView, Statistics, Tile, TileLoaderState } from "@here/harp-mapview";16import { LoggerManager } from "@here/harp-utils";17import * as chai from "chai";18import * as chaiAsPromised from "chai-as-promised";19import * as sinon from "sinon";20import { DataProvider } from "../lib/DataProvider";21import { TileLoader } from "../lib/TileLoader";22chai.use(chaiAsPromised);23// Needed for using expect(...).true for example24const { expect } = chai;25class MockDataSource extends DataSource {26 /** @override */27 getTilingScheme(): TilingScheme {28 return webMercatorTilingScheme;29 }30 /** @override */31 getTile(tileKey: TileKey): Tile | undefined {32 return undefined;33 }34}35class MockDataProvider extends DataProvider {36 async connect() {37 // empty implementation38 }39 ready(): boolean {40 return true;41 }42 async getTile(): Promise<ArrayBufferLike | {}> {43 return await Promise.resolve(new ArrayBuffer(5));44 }45 /** @override */ dispose() {46 // Nothing to be done here.47 }48}49const fakeGeometry = {};50const fakeEmptyGeometry = {51 foo: "bar",52 geometries: [fakeGeometry as Geometry],53 techniques: []54};55class MockTileDecoder implements ITileDecoder {56 async connect() {57 // connect is not used58 }59 dispose() {60 // dispose is not used61 }62 async decodeTile(): Promise<DecodedTile> {63 return await Promise.resolve(fakeEmptyGeometry);64 }65 async getTileInfo(66 _data: ArrayBufferLike,67 _tileKey: TileKey,68 _projection: Projection69 ): Promise<TileInfo | undefined> {70 return await Promise.resolve(undefined);71 }72 configure() {73 // no configuration needed for mock74 }75}76function createMockMapView() {77 return ({78 projection: webMercatorProjection,79 getDataSourceByName() {},80 statistics: new Statistics()81 } as any) as MapView;82}83describe("TileLoader", function () {84 let tileKey: TileKey;85 let mapView: MapView;86 let dataSource: DataSource;87 let dataProvider: MockDataProvider;88 let loggerWasEnabled = true;89 before(function () {90 tileKey = TileKey.fromRowColumnLevel(0, 0, 0);91 mapView = createMockMapView();92 dataSource = new MockDataSource();93 dataSource.attach(mapView);94 const logger = LoggerManager.instance.getLogger("BaseTileLoader");95 if (logger) {96 loggerWasEnabled = logger.enabled;97 logger.enabled = false;98 }99 });100 beforeEach(function () {101 dataProvider = new MockDataProvider();102 });103 after(function () {104 LoggerManager.instance.enable("BaseTileLoader", loggerWasEnabled);105 });106 describe("loadAndDecode()", function () {107 it("should load tiles", function () {108 const tileLoader = new TileLoader(109 dataSource,110 tileKey,111 dataProvider,112 new MockTileDecoder()113 );114 const loadPromise = tileLoader.loadAndDecode();115 expect(loadPromise).to.not.be.undefined;116 return expect(loadPromise).to.eventually.be.fulfilled;117 });118 it("should not reload already requested tile", function () {119 const tileLoader = new TileLoader(120 dataSource,121 tileKey,122 dataProvider,123 new MockTileDecoder()124 );125 const loadPromise = tileLoader.loadAndDecode();126 expect(loadPromise).to.not.be.undefined;127 const secondLoadPromise = tileLoader.loadAndDecode();128 expect(secondLoadPromise).to.not.be.undefined;129 expect(secondLoadPromise).to.equal(loadPromise);130 return expect(loadPromise).to.eventually.be.fulfilled;131 });132 it("should handle empty payloads", function () {133 const tileDecoder = new MockTileDecoder();134 const decodeTileSpy = sinon.spy(tileDecoder, "decodeTile");135 const tileLoader = new TileLoader(dataSource, tileKey, dataProvider, tileDecoder);136 const getTileStub = sinon.stub(dataProvider, "getTile").resolves(new ArrayBuffer(0));137 let loadPromise = tileLoader.loadAndDecode();138 expect(loadPromise).to.not.be.undefined;139 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {140 expect(tileLoader.state).to.equal(TileLoaderState.Ready);141 expect(decodeTileSpy.notCalled).to.be.true;142 getTileStub.resolves({});143 loadPromise = tileLoader.loadAndDecode();144 expect(loadPromise).to.not.be.undefined;145 expect(tileLoader.decodedTile!.geometries.length).eq(0);146 expect(tileLoader.decodedTile?.techniques.length).eq(0);147 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {148 expect(decodeTileSpy.notCalled).to.be.true;149 });150 });151 });152 describe("loadAndDecode()", function () {153 let tileLoader: TileLoader;154 this.beforeEach(() => {155 tileLoader = new TileLoader(156 dataSource,157 tileKey,158 dataProvider,159 new MockTileDecoder()160 );161 LoggerManager.instance.update("TileLoader", { enabled: false });162 });163 this.afterEach(() => {164 LoggerManager.instance.update("TileLoader", { enabled: false });165 });166 it("should recover from losing internet connection", function () {167 // This test writes an error to the console, so we disable it.168 LoggerManager.instance.update("TileLoader", { enabled: false });169 const getTileStub = sinon170 .stub(dataProvider, "getTile")171 .rejects(new Error("No connection."));172 const loadPromise = tileLoader.loadAndDecode();173 expect(loadPromise).to.not.be.undefined;174 // Chai.PromisedAssertion doesn't have .finally unfortunately.175 return expect(loadPromise).to.eventually.be.rejected.then(() => {176 expect(tileLoader.state).to.equal(TileLoaderState.Failed);177 getTileStub.restore();178 const loadPromise = tileLoader.loadAndDecode();179 expect(loadPromise).to.not.be.undefined;180 return expect(loadPromise).to.eventually.be.fulfilled;181 });182 });183 });184 });185 describe("cancel()", function () {186 it("should cancel running requests", function () {187 const tileLoader = new TileLoader(188 dataSource,189 tileKey,190 dataProvider,191 new MockTileDecoder()192 );193 const loadPromise = tileLoader.loadAndDecode();194 expect(loadPromise).to.not.be.undefined;195 tileLoader.cancel();196 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);197 return expect(loadPromise).to.eventually.be.rejected;198 });199 it("should cancel during decoding", function () {200 const tileLoader = new TileLoader(201 dataSource,202 tileKey,203 dataProvider,204 new MockTileDecoder()205 );206 const loadPromise = tileLoader.loadAndDecode();207 expect(loadPromise).to.not.be.undefined;208 // mock loaded data state209 (tileLoader as any).payload = new ArrayBuffer(5);210 tileLoader.state = TileLoaderState.Loaded;211 (tileLoader as any).startDecodeTile();212 tileLoader.cancel();213 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);214 return expect(loadPromise).to.eventually.be.rejected;215 });216 });217 describe("tile load", function () {218 // Note, this test can't be in TileTest.ts because the TileLoader is not part of the219 // @here/harp-mapview package, and trying to add package which contains the TileLoader220 // as a dependency causes a loop which isn't allowed.221 it("tile load sets dependencies from decoded tile", async function () {222 const dependencies: number[] = [0, 1];223 const decodedTile: DecodedTile = {224 techniques: [],225 geometries: [],226 dependencies227 };228 const tileLoader = sinon.createStubInstance(TileLoader);229 tileLoader.decodedTile = decodedTile;230 tileLoader.loadAndDecode.returns(Promise.resolve(TileLoaderState.Ready));231 const tile = new Tile(dataSource, tileKey);232 tile.tileLoader = tileLoader;233 await tile.load();234 expect(tile.dependencies).to.be.deep.eq(235 dependencies.map(morton => TileKey.fromMortonCode(morton))236 );237 });238 });...

Full Screen

Full Screen

WebTileLoaderTest.ts

Source:WebTileLoaderTest.ts Github

copy

Full Screen

1/*2 * Copyright (C) 2020-2021 HERE Europe B.V.3 * Licensed under Apache 2.0, see full license in LICENSE4 * SPDX-License-Identifier: Apache-2.05 */6// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions7import { TileKey, webMercatorProjection } from "@here/harp-geoutils";8import { CopyrightInfo, MapView, Tile, TileLoaderState } from "@here/harp-mapview";9import { LoggerManager } from "@here/harp-utils";10import * as chai from "chai";11import * as chaiAsPromised from "chai-as-promised";12import * as sinon from "sinon";13import * as THREE from "three";14import { WebTileDataProvider, WebTileDataSource } from "../lib/WebTileDataSource";15import { WebTileLoader } from "../lib/WebTileLoader";16chai.use(chaiAsPromised);17const { expect } = chai;18describe("WebTileLoader", function () {19 const tileKey: TileKey = TileKey.fromRowColumnLevel(0, 0, 0);20 const mapView = ({21 projection: webMercatorProjection22 } as any) as MapView;23 const texture = new THREE.Texture();24 const copyRightInfo: CopyrightInfo[] = [];25 const renderOrder: number = 42;26 const opacity: number = 1;27 const getTextureStub = sinon.stub();28 const dataProvider: WebTileDataProvider = { getTexture: getTextureStub } as any;29 let dataSource: WebTileDataSource;30 let tile: Tile;31 let loggerWasEnabled = true;32 before(function () {33 const logger = LoggerManager.instance.getLogger("BaseTileLoader");34 if (logger) {35 loggerWasEnabled = logger.enabled;36 logger.enabled = false;37 }38 });39 beforeEach(function () {40 dataSource = new WebTileDataSource({41 dataProvider,42 renderingOptions: {43 opacity,44 renderOrder45 }46 });47 dataSource.attach(mapView);48 tile = new Tile(dataSource, tileKey);49 getTextureStub.resolves([texture, copyRightInfo]);50 });51 after(function () {52 LoggerManager.instance.enable("BaseTileLoader", loggerWasEnabled);53 });54 describe("loadAndDecode()", function () {55 it("should load textured mesh and copyright info", function () {56 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);57 const loadPromise = tileLoader.loadAndDecode();58 expect(loadPromise).to.not.be.undefined;59 expect(tileLoader.isFinished).to.be.false;60 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {61 expect(tileLoader.isFinished).to.be.true;62 expect(tile.shouldDisposeTexture(texture)).to.be.true;63 expect(tile.objects).has.lengthOf(1);64 expect(tile.objects[0]).instanceOf(THREE.Mesh);65 const mesh = tile.objects[0] as THREE.Mesh;66 expect(mesh.renderOrder).equal(renderOrder);67 expect(mesh.material).has.property("map").equal(texture);68 expect(mesh.material).has.property("opacity").equal(opacity);69 expect(tile.copyrightInfo).to.equal(copyRightInfo);70 });71 });72 it("should not enforce blending if data source is fully opaque", function () {73 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);74 const loadPromise = tileLoader.loadAndDecode();75 expect(loadPromise).to.not.be.undefined;76 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {77 expect(tileLoader.isFinished).to.be.true;78 expect(tile.objects).has.lengthOf(1);79 expect(tile.objects[0]).instanceOf(THREE.Mesh);80 const mesh = tile.objects[0] as THREE.Mesh;81 expect(mesh.material).has.property("blending").that.equals(THREE.NormalBlending);82 });83 });84 it("should enable custom blending if data source is transparent", function () {85 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);86 dataSource.opacity = 0.5;87 const loadPromise = tileLoader.loadAndDecode();88 expect(loadPromise).to.not.be.undefined;89 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {90 expect(tileLoader.isFinished).to.be.true;91 expect(tile.objects).has.lengthOf(1);92 expect(tile.objects[0]).instanceOf(THREE.Mesh);93 const mesh = tile.objects[0] as THREE.Mesh;94 expect(mesh.material).has.property("blending").that.equals(THREE.CustomBlending);95 });96 });97 it("should not reload already requested tile", function () {98 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);99 const loadPromise = tileLoader.loadAndDecode();100 expect(loadPromise).to.not.be.undefined;101 const secondLoadPromise = tileLoader.loadAndDecode();102 expect(secondLoadPromise).to.not.be.undefined;103 expect(secondLoadPromise).to.equal(loadPromise);104 return expect(loadPromise).to.eventually.be.fulfilled;105 });106 it("should forceHasGeometry on tile on empty payload", function () {107 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);108 getTextureStub.resolves(undefined);109 const loadPromise = tileLoader.loadAndDecode();110 expect(loadPromise).to.not.be.undefined;111 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {112 expect(tileLoader.isFinished).to.be.true;113 expect(tileLoader.state).to.equal(TileLoaderState.Ready);114 expect(loadPromise).to.not.be.undefined;115 expect(tile.hasGeometry).to.be.true;116 expect(tile.objects).to.be.empty;117 });118 });119 it("should forceHasGeometry on tile on empty texture", function () {120 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);121 getTextureStub.resolves([undefined, []]);122 const loadPromise = tileLoader.loadAndDecode();123 expect(loadPromise).to.not.be.undefined;124 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {125 expect(tileLoader.isFinished).to.be.true;126 expect(tileLoader.state).to.equal(TileLoaderState.Ready);127 expect(loadPromise).to.not.be.undefined;128 expect(tile.hasGeometry).to.be.true;129 expect(tile.objects).to.be.empty;130 });131 });132 it("should finish loading on retry", function () {133 getTextureStub.rejects(new Error("No connection."));134 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);135 const loadPromise = tileLoader.loadAndDecode();136 expect(loadPromise).to.not.be.undefined;137 return expect(loadPromise).to.eventually.be.rejected.then(() => {138 expect(tileLoader.isFinished).to.be.true;139 expect(tileLoader.state).to.equal(TileLoaderState.Failed);140 getTextureStub.resolves([{}, []]);141 const loadPromise = tileLoader.loadAndDecode();142 expect(loadPromise).to.not.be.undefined;143 return expect(loadPromise).to.eventually.be.fulfilled;144 });145 });146 });147 describe("cancel()", function () {148 it("should cancel running requests", function () {149 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);150 const loadPromise = tileLoader.loadAndDecode();151 expect(loadPromise).to.not.be.undefined;152 tileLoader.cancel();153 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);154 return expect(loadPromise).to.eventually.be.rejected;155 });156 });...

Full Screen

Full Screen

rakuten.js

Source:rakuten.js Github

copy

Full Screen

1const functions = require('firebase-functions');2const puppeteer = require('puppeteer');3const admin = require('firebase-admin');4const config = require('./data.json');5let page, browser;6async function getBrowserPage () {7 const isDebug = process.env.NODE_ENV !== 'production'8 const launchOptions = {9 headless: isDebug ? false : true,10 args: ['--no-sandbox']11 }12 browser = await puppeteer.launch(launchOptions)13 return browser.newPage()14}15exports.pointRakuten = functions.runWith({16 memory: '1GB',17 timeoutSeconds: 260,18})19.region('asia-northeast1')20.pubsub.schedule('every day 12:00')21.timeZone('Asia/Tokyo')22.onRun(async (context) => {23 await runRakuten(context);24});25exports.runRakuten=runRakuten;26async function runRakuten(context){27 if (!page) {28 page = await getBrowserPage();29 }30 // rakuten keiba31 await page.goto('https://bet.keiba.rakuten.co.jp/bank/deposit/');32 await page.type('#loginInner_u', config.rakuten.id);33 await page.type('#loginInner_p', config.rakuten.pw);34 loadPromise = page.waitForNavigation();35 await page.click('[value="ログイン"]');36 await loadPromise;37 await page.type('#depositingInputPrice', "1000");38 loadPromise = page.waitForNavigation();39 await page.click('#depositingInputButton');40 await loadPromise;41 await page.type('[name="pin"]', config.rakutenkeiba.pw);42 loadPromise = page.waitForNavigation();43 await page.click('#depositingConfirmButton');44 await loadPromise;45 // e-shinbun bet46 await page.goto('https://www.e-shinbun.net/account/?ref=ebet&path=http%3A%2F%2Fbet.e-shinbun.net%2F');47 loadPromise = page.waitForNavigation();48 await page.click("[type=image]");49 await loadPromise;50 loadPromise = page.waitForNavigation();51 await page.click("[alt=続ける]");52 await loadPromise;53 loadPromise = page.waitForNavigation();54 await page.click("[alt=入金]");55 await loadPromise;56 await page.type('#StatementAmount', "100");57 loadPromise = page.waitForNavigation();58 await page.click(".std_btn");59 await loadPromise;60 await page.type('#UserPassword', config.eshinbun.pw);61 loadPromise = page.waitForNavigation();62 await page.click('[onclick="hasTransacted();"]');63 await loadPromise;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { loadPromise } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { withA11y } from '@storybook/addon-a11y';6import { withRootDecorator } from 'storybook-root-decorator';

Full Screen

Using AI Code Generation

copy

Full Screen

1const { loadPromise } = require('storybook-root-cause');2const { default: initStoryshots } = require('@storybook/addon-storyshots');3initStoryshots({4});5const { load } = require('storybook-root-cause');6const { default: initStoryshots } = require('@storybook/addon-storyshots');7initStoryshots({8});9const { load } = require('storybook-root-cause');10const { default: initStoryshots } = require('@storybook/addon-storyshots');11initStoryshots({12});13const { load } = require('storybook-root-cause');14const { default: initStoryshots } = require('@storybook/addon-storyshots');15initStoryshots({16});17const { load } = require('storybook-root-cause');18const { default: initStoryshots } = require('@storybook/addon-storyshots');19initStoryshots({20});21const { load } = require('storybook-root-cause');22const { default: initStoryshots } = require('@storybook/addon-storyshots');23initStoryshots({24});25const { load } = require('storybook-root-cause');26const {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { loadPromise } from "storybook-root-decorator";2import MyComponent from "./MyComponent";3storiesOf("MyComponent", module)4 .addDecorator(withKnobs)5 .add("MyComponent", () => {6 return loadPromise(MyComponent);7 });8import { loadPromise } from "storybook-root-decorator";9import MyComponent from "./MyComponent";10storiesOf("MyComponent", module)11 .addDecorator(withKnobs)12 .add("MyComponent", () => {13 return loadPromise(MyComponent, { name: "John" });14 });15import { loadPromise } from "storybook-root-decorator";16import MyComponent from "./MyComponent";17storiesOf("MyComponent", module)18 .addDecorator(withKnobs)19 .add("MyComponent", () => {20 return loadPromise(MyComponent, { name: "John" }, { name: "John" });21 });22import { loadPromise } from "storybook-root-decorator";23import MyComponent from "./MyComponent";24storiesOf("MyComponent", module)25 .addDecorator(withKnobs)26 .add("MyComponent", () => {27 return loadPromise(MyComponent, { name: "John" }, { name: "John" });28 });

Full Screen

Using AI Code Generation

copy

Full Screen

1import { loadPromise } from '@storybook/react';2loadPromise.then(() => {3});4loadPromise.then(() => {5});6loadPromise.then(() => {7});8import { loadPromise } from '@storybook/react';9loadPromise.then(() => {10});11loadPromise.then(() => {12});13loadPromise.then(() => {14});15import { loadPromise } from '@storybook/react';16loadPromise.then(() => {17});18loadPromise.then(() => {19});20loadPromise.then(() => {21});22import { loadPromise } from '@storybook/react';23loadPromise.then(() => {24});25loadPromise.then(() => {26});27loadPromise.then(() => {28});29import { loadPromise } from '@storybook/react';30loadPromise.then(() => {31});32loadPromise.then(() => {33});34loadPromise.then(() => {35});36import { loadPromise } from '@storybook/react';37loadPromise.then(() => {38});39loadPromise.then(() => {40});41loadPromise.then(() => {42});43import { loadPromise } from '@storybook/react';44loadPromise.then(() => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const loadPromise = require('storybook-root').loadPromise;2const { storiesOf } = require('@storybook/react');3const { action } = require('@storybook/addon-actions');4storiesOf('Test', module)5 .add('test', () => {6 loadPromise.then(() => {7 action('loadPromise resolved')();8 });9 return <div>test</div>;10 });11const loadPromise = require('storybook-root').loadPromise;12const { configure } = require('@storybook/react');13loadPromise.then(() => {14});15configure(() => {16 require('../test.js');17}, module);18const loadPromise = require('storybook-root').loadPromise;19const { setAddon } = require('@storybook/react');20const { action } = require('@storybook/addon-actions');21loadPromise.then(() => {22});23setAddon({24});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { loadPromise } from 'storybook-root';2loadPromise.then(() => {3});4import { loadPromise } from 'storybook-root';5loadPromise.then(() => {6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const storybookPort = 9001;3const storybookRootDecorator = require('storybook-root-decorator');4describe('storybook stories', () => {5 let browser;6 let page;7 beforeAll(async () => {8 browser = await puppeteer.launch();9 page = await browser.newPage();10 await page.goto(storybookUrl);11 await storybookRootDecorator.loadPromise(page);12 });13 afterAll(() => {14 browser.close();15 });16 test('should load', () => {17 expect(storybookRootDecorator.loaded).toBe(true);18 });19});20import { configure } from '@storybook/react';21import storybookRootDecorator from 'storybook-root-decorator';22storybookRootDecorator.set({23});24function loadStories() {25 require('../stories');26}27configure(loadStories, module);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful