How to use baseCommands method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

BaseExtension.ts

Source:BaseExtension.ts Github

copy

Full Screen

1import BaseCommands = require("./BaseCommands");2import BaseProvider = require("./BaseProvider");3import BootStrapper = require("../../Bootstrapper");4import BootstrapParams = require("../../BootstrapParams");5import ClickThroughDialogue = require("../../modules/uv-dialogues-module/ClickThroughDialogue");6import RestrictedDialogue = require("../../modules/uv-dialogues-module/RestrictedDialogue");7import ExternalResource = require("./ExternalResource");8import IExtension = require("./IExtension");9import Information = require("./Information");10import InformationAction = require("./InformationAction");11import InformationArgs = require("./InformationArgs");12import InformationType = require("./InformationType");13import IProvider = require("./IProvider");14import LoginDialogue = require("../../modules/uv-dialogues-module/LoginDialogue");15import Params = require("../../Params");16import Shell = require("./Shell");17import IAccessToken = Manifesto.IAccessToken;18import ILoginDialogueOptions = require("./ILoginDialogueOptions");19import LoginWarningMessages = require("./LoginWarningMessages");20class BaseExtension implements IExtension {21 $clickThroughDialogue: JQuery;22 $restrictedDialogue: JQuery;23 $element: JQuery;24 $loginDialogue: JQuery;25 bootstrapper: BootStrapper;26 canvasIndex: number;27 clickThroughDialogue: ClickThroughDialogue;28 restrictedDialogue: RestrictedDialogue;29 embedHeight: number;30 embedWidth: number;31 extensions: any;32 loginDialogue: LoginDialogue;33 mouseX: number;34 mouseY: number;35 name: string;36 provider: IProvider;37 shell: Shell;38 shifted: boolean = false;39 tabbing: boolean = false;40 constructor(bootstrapper: BootStrapper) {41 this.bootstrapper = bootstrapper;42 }43 public create(overrideDependencies?: any): void {44 var that = this;45 this.$element = $('#app');46 this.$element.data("bootstrapper", this.bootstrapper);47 // initial sizing.48 var $win = $(window);49 this.embedWidth = $win.width();50 this.embedHeight = $win.height();51 this.$element.width(this.embedWidth);52 this.$element.height(this.embedHeight);53 if (!this.provider.isReload && Utils.Documents.IsInIFrame()){54 // communication with parent frame (if it exists).55 this.bootstrapper.socket = new easyXDM.Socket({56 onMessage: (message, origin) => {57 message = $.parseJSON(message);58 // todo: waitFor CREATED59 this.handleParentFrameEvent(message);60 }61 });62 }63 this.triggerSocket(BaseCommands.LOAD, {64 bootstrapper: {65 config: this.provider.bootstrapper.config,66 params: this.provider.bootstrapper.params67 },68 preview: this.getSharePreview()69 });70 // add/remove classes.71 this.$element.empty();72 this.$element.removeClass();73 this.$element.addClass('browser-' + window.browserDetect.browser);74 this.$element.addClass('browser-version-' + window.browserDetect.version);75 if (!this.provider.isHomeDomain) this.$element.addClass('embedded');76 if (this.provider.isLightbox) this.$element.addClass('lightbox');77 // events.78 if (!this.provider.isReload){79 window.onresize = () => {80 var $win = $(window);81 $('body').height($win.height());82 this.resize();83 };84 $(document).on('mousemove', (e) => {85 this.mouseX = e.pageX;86 this.mouseY = e.pageY;87 });88 this.$element.on('drop', (e => {89 e.preventDefault();90 var dropUrl = (<any>e.originalEvent).dataTransfer.getData("URL");91 var url = Utils.Urls.GetUrlParts(dropUrl);92 var manifestUri = Utils.Urls.GetQuerystringParameterFromString('manifest', url.search);93 //var canvasUri = Utils.Urls.GetQuerystringParameterFromString('canvas', url.search);94 if (manifestUri){95 this.triggerSocket(BaseCommands.DROP, manifestUri);96 var p = new BootstrapParams();97 p.manifestUri = manifestUri;98 this.provider.reload(p);99 }100 }));101 this.$element.on('dragover', (e => {102 // allow drop103 e.preventDefault();104 }));105 // keyboard events.106 $(document).on('keyup keydown', (e) => {107 this.shifted = e.shiftKey;108 this.tabbing = e.keyCode === KeyCodes.KeyDown.Tab;109 });110 $(document).keydown((e) => {111 var event: string = null;112 if (!e.ctrlKey && !e.altKey && !e.shiftKey) {113 if (e.keyCode === KeyCodes.KeyDown.Enter) event = BaseCommands.RETURN;114 if (e.keyCode === KeyCodes.KeyDown.Escape) event = BaseCommands.ESCAPE;115 if (e.keyCode === KeyCodes.KeyDown.PageUp) event = BaseCommands.PAGE_UP;116 if (e.keyCode === KeyCodes.KeyDown.PageDown) event = BaseCommands.PAGE_DOWN;117 if (e.keyCode === KeyCodes.KeyDown.End) event = BaseCommands.END;118 if (e.keyCode === KeyCodes.KeyDown.Home) event = BaseCommands.HOME;119 if (e.keyCode === KeyCodes.KeyDown.NumpadPlus || e.keyCode === 171 || e.keyCode === KeyCodes.KeyDown.Equals) event = BaseCommands.PLUS;120 if (e.keyCode === KeyCodes.KeyDown.NumpadMinus || e.keyCode === 173 || e.keyCode === KeyCodes.KeyDown.Dash) event = BaseCommands.MINUS;121 if (that.useArrowKeysToNavigate()) {122 if (e.keyCode === KeyCodes.KeyDown.LeftArrow) event = BaseCommands.LEFT_ARROW;123 if (e.keyCode === KeyCodes.KeyDown.UpArrow) event = BaseCommands.UP_ARROW;124 if (e.keyCode === KeyCodes.KeyDown.RightArrow) event = BaseCommands.RIGHT_ARROW;125 if (e.keyCode === KeyCodes.KeyDown.DownArrow) event = BaseCommands.DOWN_ARROW;126 }127 }128 if (event){129 e.preventDefault();130 $.publish(event);131 }132 });133 if (this.bootstrapper.params.isHomeDomain && Utils.Documents.IsInIFrame()) {134 $.subscribe(BaseCommands.PARENT_EXIT_FULLSCREEN, () => {135 if (this.isOverlayActive()) {136 $.publish(BaseCommands.ESCAPE);137 }138 $.publish(BaseCommands.ESCAPE);139 $.publish(BaseCommands.RESIZE);140 });141 }142 }143 this.$element.append('<a href="/" id="top"></a>');144 $.subscribe(BaseCommands.ACCEPT_TERMS, () => {145 this.triggerSocket(BaseCommands.ACCEPT_TERMS);146 });147 $.subscribe(BaseCommands.AUTHORIZATION_FAILED, () => {148 this.triggerSocket(BaseCommands.AUTHORIZATION_FAILED);149 this.showMessage(this.provider.config.content.authorisationFailedMessage);150 });151 $.subscribe(BaseCommands.AUTHORIZATION_OCCURRED, () => {152 this.triggerSocket(BaseCommands.AUTHORIZATION_OCCURRED);153 });154 $.subscribe(BaseCommands.BOOKMARK, () => {155 this.bookmark();156 });157 $.subscribe(BaseCommands.CANVAS_INDEX_CHANGE_FAILED, () => {158 this.triggerSocket(BaseCommands.CANVAS_INDEX_CHANGE_FAILED);159 });160 $.subscribe(BaseCommands.CANVAS_INDEX_CHANGED, (e, canvasIndex) => {161 this.triggerSocket(BaseCommands.CANVAS_INDEX_CHANGED, canvasIndex);162 });163 $.subscribe(BaseCommands.CLICKTHROUGH_OCCURRED, () => {164 this.triggerSocket(BaseCommands.CLICKTHROUGH_OCCURRED);165 });166 $.subscribe(BaseCommands.CLOSE_ACTIVE_DIALOGUE, () => {167 this.triggerSocket(BaseCommands.CLOSE_ACTIVE_DIALOGUE);168 });169 $.subscribe(BaseCommands.CLOSE_LEFT_PANEL, () => {170 this.triggerSocket(BaseCommands.CLOSE_LEFT_PANEL);171 this.resize();172 });173 $.subscribe(BaseCommands.CLOSE_RIGHT_PANEL, () => {174 this.triggerSocket(BaseCommands.CLOSE_RIGHT_PANEL);175 this.resize();176 });177 $.subscribe(BaseCommands.CREATED, () => {178 this.triggerSocket(BaseCommands.CREATED);179 });180 $.subscribe(BaseCommands.DOWN_ARROW, () => {181 this.triggerSocket(BaseCommands.DOWN_ARROW);182 });183 $.subscribe(BaseCommands.DOWNLOAD, (e, id) => {184 this.triggerSocket(BaseCommands.DOWNLOAD, id);185 });186 $.subscribe(BaseCommands.END, () => {187 this.triggerSocket(BaseCommands.END);188 });189 $.subscribe(BaseCommands.ESCAPE, () => {190 this.triggerSocket(BaseCommands.ESCAPE);191 if (this.isFullScreen() && !this.isOverlayActive()) {192 $.publish(BaseCommands.TOGGLE_FULLSCREEN);193 }194 });195 $.subscribe(BaseCommands.FEEDBACK, () => {196 this.feedback();197 });198 $.subscribe(BaseCommands.FORBIDDEN, () => {199 this.triggerSocket(BaseCommands.FORBIDDEN);200 $.publish(BaseCommands.OPEN_EXTERNAL_RESOURCE);201 });202 $.subscribe(BaseCommands.HIDE_DOWNLOAD_DIALOGUE, () => {203 this.triggerSocket(BaseCommands.HIDE_DOWNLOAD_DIALOGUE);204 });205 $.subscribe(BaseCommands.HIDE_EMBED_DIALOGUE, () => {206 this.triggerSocket(BaseCommands.HIDE_EMBED_DIALOGUE);207 });208 $.subscribe(BaseCommands.HIDE_EXTERNALCONTENT_DIALOGUE, () => {209 this.triggerSocket(BaseCommands.HIDE_EXTERNALCONTENT_DIALOGUE);210 });211 $.subscribe(BaseCommands.HIDE_GENERIC_DIALOGUE, () => {212 this.triggerSocket(BaseCommands.HIDE_GENERIC_DIALOGUE);213 });214 $.subscribe(BaseCommands.HIDE_HELP_DIALOGUE, () => {215 this.triggerSocket(BaseCommands.HIDE_HELP_DIALOGUE);216 });217 $.subscribe(BaseCommands.HIDE_INFORMATION, () => {218 this.triggerSocket(BaseCommands.HIDE_INFORMATION);219 });220 $.subscribe(BaseCommands.HIDE_LOGIN_DIALOGUE, () => {221 this.triggerSocket(BaseCommands.HIDE_LOGIN_DIALOGUE);222 });223 $.subscribe(BaseCommands.HIDE_OVERLAY, () => {224 this.triggerSocket(BaseCommands.HIDE_OVERLAY);225 });226 $.subscribe(BaseCommands.HIDE_SETTINGS_DIALOGUE, () => {227 this.triggerSocket(BaseCommands.HIDE_SETTINGS_DIALOGUE);228 });229 $.subscribe(BaseCommands.HOME, () => {230 this.triggerSocket(BaseCommands.HOME);231 });232 $.subscribe(BaseCommands.LEFT_ARROW, () => {233 this.triggerSocket(BaseCommands.LEFT_ARROW);234 });235 $.subscribe(BaseCommands.LEFTPANEL_COLLAPSE_FULL_FINISH, () => {236 this.triggerSocket(BaseCommands.LEFTPANEL_COLLAPSE_FULL_FINISH);237 });238 $.subscribe(BaseCommands.LEFTPANEL_COLLAPSE_FULL_START, () => {239 this.triggerSocket(BaseCommands.LEFTPANEL_COLLAPSE_FULL_START);240 });241 $.subscribe(BaseCommands.LEFTPANEL_EXPAND_FULL_FINISH, () => {242 this.triggerSocket(BaseCommands.LEFTPANEL_EXPAND_FULL_FINISH);243 });244 $.subscribe(BaseCommands.LEFTPANEL_EXPAND_FULL_START, () => {245 this.triggerSocket(BaseCommands.LEFTPANEL_EXPAND_FULL_START);246 });247 $.subscribe(BaseCommands.EXTERNAL_LINK_CLICKED, (e, url) => {248 this.triggerSocket(BaseCommands.EXTERNAL_LINK_CLICKED, url);249 });250 $.subscribe(BaseCommands.NOT_FOUND, () => {251 this.triggerSocket(BaseCommands.NOT_FOUND);252 });253 $.subscribe(BaseCommands.OPEN, () => {254 this.triggerSocket(BaseCommands.OPEN);255 var openUri: string = String.format(this.provider.config.options.openTemplate, this.provider.manifestUri);256 window.open(openUri);257 });258 $.subscribe(BaseCommands.OPEN_LEFT_PANEL, () => {259 this.triggerSocket(BaseCommands.OPEN_LEFT_PANEL);260 this.resize();261 });262 $.subscribe(BaseCommands.OPEN_EXTERNAL_RESOURCE, () => {263 this.triggerSocket(BaseCommands.OPEN_EXTERNAL_RESOURCE);264 });265 $.subscribe(BaseCommands.OPEN_RIGHT_PANEL, () => {266 this.triggerSocket(BaseCommands.OPEN_RIGHT_PANEL);267 this.resize();268 });269 $.subscribe(BaseCommands.PAGE_DOWN, () => {270 this.triggerSocket(BaseCommands.PAGE_DOWN);271 });272 $.subscribe(BaseCommands.PAGE_UP, () => {273 this.triggerSocket(BaseCommands.PAGE_UP);274 });275 $.subscribe(BaseCommands.RESOURCE_DEGRADED, (e, resource: ExternalResource) => {276 this.triggerSocket(BaseCommands.RESOURCE_DEGRADED);277 this.handleDegraded(resource)278 });279 $.subscribe(BaseCommands.RETURN, () => {280 this.triggerSocket(BaseCommands.RETURN);281 });282 $.subscribe(BaseCommands.RIGHT_ARROW, () => {283 this.triggerSocket(BaseCommands.RIGHT_ARROW);284 });285 $.subscribe(BaseCommands.RIGHTPANEL_COLLAPSE_FULL_FINISH, () => {286 this.triggerSocket(BaseCommands.RIGHTPANEL_COLLAPSE_FULL_FINISH);287 });288 $.subscribe(BaseCommands.RIGHTPANEL_COLLAPSE_FULL_START, () => {289 this.triggerSocket(BaseCommands.RIGHTPANEL_COLLAPSE_FULL_START);290 });291 $.subscribe(BaseCommands.RIGHTPANEL_EXPAND_FULL_FINISH, () => {292 this.triggerSocket(BaseCommands.RIGHTPANEL_EXPAND_FULL_FINISH);293 });294 $.subscribe(BaseCommands.RIGHTPANEL_EXPAND_FULL_START, () => {295 this.triggerSocket(BaseCommands.RIGHTPANEL_EXPAND_FULL_START);296 });297 $.subscribe(BaseCommands.SEQUENCE_INDEX_CHANGED, () => {298 this.triggerSocket(BaseCommands.SEQUENCE_INDEX_CHANGED);299 });300 $.subscribe(BaseCommands.SETTINGS_CHANGED, (e, args) => {301 this.triggerSocket(BaseCommands.SETTINGS_CHANGED, args);302 });303 $.subscribe(BaseCommands.SHOW_DOWNLOAD_DIALOGUE, () => {304 this.triggerSocket(BaseCommands.SHOW_DOWNLOAD_DIALOGUE);305 });306 $.subscribe(BaseCommands.SHOW_EMBED_DIALOGUE, () => {307 this.triggerSocket(BaseCommands.SHOW_EMBED_DIALOGUE);308 });309 $.subscribe(BaseCommands.SHOW_EXTERNALCONTENT_DIALOGUE, () => {310 this.triggerSocket(BaseCommands.SHOW_EXTERNALCONTENT_DIALOGUE);311 });312 $.subscribe(BaseCommands.SHOW_GENERIC_DIALOGUE, () => {313 this.triggerSocket(BaseCommands.SHOW_GENERIC_DIALOGUE);314 });315 $.subscribe(BaseCommands.SHOW_HELP_DIALOGUE, () => {316 this.triggerSocket(BaseCommands.SHOW_HELP_DIALOGUE);317 });318 $.subscribe(BaseCommands.SHOW_INFORMATION, () => {319 this.triggerSocket(BaseCommands.SHOW_INFORMATION);320 });321 $.subscribe(BaseCommands.SHOW_LOGIN_DIALOGUE, () => {322 this.triggerSocket(BaseCommands.SHOW_LOGIN_DIALOGUE);323 });324 $.subscribe(BaseCommands.SHOW_CLICKTHROUGH_DIALOGUE, () => {325 this.triggerSocket(BaseCommands.SHOW_CLICKTHROUGH_DIALOGUE);326 });327 $.subscribe(BaseCommands.SHOW_RESTRICTED_DIALOGUE, () => {328 this.triggerSocket(BaseCommands.SHOW_RESTRICTED_DIALOGUE);329 });330 $.subscribe(BaseCommands.SHOW_OVERLAY, () => {331 this.triggerSocket(BaseCommands.SHOW_OVERLAY);332 });333 $.subscribe(BaseCommands.SHOW_SETTINGS_DIALOGUE, () => {334 this.triggerSocket(BaseCommands.SHOW_SETTINGS_DIALOGUE);335 });336 $.subscribe(BaseCommands.THUMB_SELECTED, (e, canvasIndex: number) => {337 this.triggerSocket(BaseCommands.THUMB_SELECTED, canvasIndex);338 });339 $.subscribe(BaseCommands.TOGGLE_FULLSCREEN, () => {340 $('#top').focus();341 this.bootstrapper.isFullScreen = !this.bootstrapper.isFullScreen;342 this.triggerSocket(BaseCommands.TOGGLE_FULLSCREEN,343 {344 isFullScreen: this.bootstrapper.isFullScreen,345 overrideFullScreen: this.provider.config.options.overrideFullScreen346 });347 });348 $.subscribe(BaseCommands.UP_ARROW, () => {349 this.triggerSocket(BaseCommands.UP_ARROW);350 });351 $.subscribe(BaseCommands.UPDATE_SETTINGS, () => {352 this.triggerSocket(BaseCommands.UPDATE_SETTINGS);353 });354 $.subscribe(BaseCommands.VIEW_FULL_TERMS, () => {355 this.triggerSocket(BaseCommands.VIEW_FULL_TERMS);356 });357 $.subscribe(BaseCommands.WINDOW_UNLOAD, () => {358 this.triggerSocket(BaseCommands.WINDOW_UNLOAD);359 });360 // create shell and shared views.361 this.shell = new Shell(this.$element);362 // set canvasIndex to -1 (nothing selected yet).363 this.canvasIndex = -1;364 // dependencies365 if (overrideDependencies){366 this.loadDependencies(overrideDependencies);367 } else {368 this.getDependencies((deps: any) => {369 this.loadDependencies(deps);370 });371 }372 }373 createModules(): void {374 this.$clickThroughDialogue = $('<div class="overlay clickthrough"></div>');375 Shell.$overlays.append(this.$clickThroughDialogue);376 this.clickThroughDialogue = new ClickThroughDialogue(this.$clickThroughDialogue);377 this.$restrictedDialogue = $('<div class="overlay login"></div>');378 Shell.$overlays.append(this.$restrictedDialogue);379 this.restrictedDialogue = new RestrictedDialogue(this.$restrictedDialogue);380 this.$loginDialogue = $('<div class="overlay login"></div>');381 Shell.$overlays.append(this.$loginDialogue);382 this.loginDialogue = new LoginDialogue(this.$loginDialogue);383 }384 modulesCreated(): void {385 }386 getDependencies(cb: (deps: any) => void): any {387 var that = this;388 // todo: use compiler flag (when available)389 var depsUri = (window.DEBUG) ? '../../extensions/' + this.name + '/dependencies' : this.name + '-dependencies';390 // check if the deps are already loaded391 var scripts = $('script[data-requiremodule]')392 .filter(function() {393 var attr = $(this).attr('data-requiremodule');394 return (attr.indexOf(that.name) != -1 && attr.indexOf('dependencies') != -1)395 });396 if (!scripts.length) {397 require([depsUri], function (deps) {398 // if debugging, set the base uri to the extension's directory.399 // otherwise set it to the current directory (where app.js is hosted).400 // todo: use compiler flag (when available)401 var baseUri = (window.DEBUG) ? '../../extensions/' + that.name + '/lib/' : '';402 // for each dependency, prepend baseUri.403 for (var i = 0; i < deps.dependencies.length; i++) {404 deps.dependencies[i] = baseUri + deps.dependencies[i];405 }406 cb(deps);407 });408 } else {409 cb(null);410 }411 }412 loadDependencies(deps: any): void {413 var that = this;414 if (deps){415 require(deps.dependencies, function () {416 that.dependenciesLoaded();417 });418 } else {419 that.dependenciesLoaded();420 }421 }422 dependenciesLoaded(): void {423 this.createModules();424 this.modulesCreated();425 $.publish(BaseCommands.RESIZE); // initial sizing426 $.publish(BaseCommands.CREATED);427 this.setParams();428 this.setDefaultFocus();429 this.viewCanvas(this.provider.getCanvasIndexParam());430 }431 setParams(): void{432 if (!this.provider.isHomeDomain) return;433 this.setParam(Params.collectionIndex, this.provider.collectionIndex);434 this.setParam(Params.manifestIndex, this.provider.manifestIndex);435 this.setParam(Params.sequenceIndex, this.provider.sequenceIndex);436 this.setParam(Params.canvasIndex, this.provider.canvasIndex);437 }438 setDefaultFocus(): void {439 setTimeout(() => {440 $('[tabindex=1]').focus();441 }, 1);442 }443 width(): number {444 return $(window).width();445 }446 height(): number {447 return $(window).height();448 }449 triggerSocket(eventName: string, eventObject?: any): void {450 if (this.bootstrapper.socket) {451 this.bootstrapper.socket.postMessage(JSON.stringify({ eventName: eventName, eventObject: eventObject }));452 }453 }454 redirect(uri: string): void {455 this.triggerSocket(BaseCommands.REDIRECT, uri);456 }457 refresh(): void {458 this.triggerSocket(BaseCommands.REFRESH, null);459 }460 resize(): void {461 $.publish(BaseCommands.RESIZE);462 }463 handleParentFrameEvent(message): void {464 // todo: waitFor CREATED465 setTimeout(() => {466 switch (message.eventName) {467 case BaseCommands.TOGGLE_FULLSCREEN:468 $.publish(BaseCommands.TOGGLE_FULLSCREEN, message.eventObject);469 break;470 case BaseCommands.PARENT_EXIT_FULLSCREEN:471 $.publish(BaseCommands.PARENT_EXIT_FULLSCREEN);472 break;473 }474 }, 1000);475 }476 getSharePreview(): any {477 var preview: any = {};478 preview.title = this.provider.getTitle();479 // todo: use getThumb (when implemented)480 var canvas: Manifesto.ICanvas = this.provider.getCurrentCanvas();481 var thumbnail = canvas.getProperty('thumbnail');482 if (!thumbnail || !_.isString(thumbnail)){483 thumbnail = canvas.getThumbUri(this.provider.config.options.bookmarkThumbWidth, this.provider.config.options.bookmarkThumbHeight);484 }485 preview.image = thumbnail;486 return preview;487 }488 getExternalResources(resources?: Manifesto.IExternalResource[]): Promise<Manifesto.IExternalResource[]> {489 var indices = this.provider.getPagedIndices();490 var resourcesToLoad = [];491 _.each(indices, (index) => {492 var canvas: Manifesto.ICanvas = this.provider.getCanvasByIndex(index);493 var r: Manifesto.IExternalResource = new ExternalResource(canvas, this.provider.getInfoUri);494 // used to reload resources with isResponseHandled = true.495 if (resources){496 var found: Manifesto.IExternalResource = _.find(resources, (f: Manifesto.IExternalResource) => {497 return f.dataUri === r.dataUri;498 });499 if (found) {500 resourcesToLoad.push(found);501 } else {502 resourcesToLoad.push(r);503 }504 } else {505 resourcesToLoad.push(r);506 }507 });508 var storageStrategy: string = this.provider.config.options.tokenStorage;509 return new Promise<Manifesto.IExternalResource[]>((resolve) => {510 manifesto.loadExternalResources(511 resourcesToLoad,512 storageStrategy,513 this.clickThrough,514 this.restricted,515 this.login,516 this.getAccessToken,517 this.storeAccessToken,518 this.getStoredAccessToken,519 this.handleExternalResourceResponse).then((r: Manifesto.IExternalResource[]) => {520 this.provider.resources = _.map(r, (resource: Manifesto.IExternalResource) => {521 return <Manifesto.IExternalResource>_.toPlainObject(resource.data);522 });523 resolve(this.provider.resources);524 })['catch']((error: any) => {525 switch(error.name){526 case manifesto.StatusCodes.AUTHORIZATION_FAILED.toString():527 $.publish(BaseCommands.AUTHORIZATION_FAILED);528 break;529 case manifesto.StatusCodes.FORBIDDEN.toString():530 $.publish(BaseCommands.FORBIDDEN);531 break;532 case manifesto.StatusCodes.RESTRICTED.toString():533 // do nothing534 break;535 default:536 this.showMessage(error.message || error);537 }538 });539 });540 }541 // get hash or data-attribute params depending on whether the UV is embedded.542 getParam(key: Params): any{543 var value;544 // deep linking is only allowed when hosted on home domain.545 if (this.provider.isDeepLinkingEnabled()){546 // todo: use a static type on bootstrapper.params547 value = Utils.Urls.GetHashParameter(this.provider.bootstrapper.params.paramMap[key], parent.document);548 }549 if (!value){550 // todo: use a static type on bootstrapper.params551 value = Utils.Urls.GetQuerystringParameter(this.provider.bootstrapper.params.paramMap[key]);552 }553 return value;554 }555 // set hash params depending on whether the UV is embedded.556 setParam(key: Params, value: any): void{557 if (this.provider.isDeepLinkingEnabled()){558 Utils.Urls.SetHashParameter(this.provider.bootstrapper.params.paramMap[key], value, parent.document);559 }560 }561 viewCanvas(canvasIndex: number): void {562 if (canvasIndex === -1) return;563 if (this.provider.isCanvasIndexOutOfRange(canvasIndex)){564 this.showMessage(this.provider.config.content.canvasIndexOutOfRange);565 canvasIndex = 0;566 }567 this.provider.canvasIndex = canvasIndex;568 $.publish(BaseCommands.CANVAS_INDEX_CHANGED, [canvasIndex]);569 $.publish(BaseCommands.OPEN_EXTERNAL_RESOURCE);570 this.setParam(Params.canvasIndex, canvasIndex);571 }572 showMessage(message: string, acceptCallback?: any, buttonText?: string, allowClose?: boolean): void {573 this.closeActiveDialogue();574 $.publish(BaseCommands.SHOW_GENERIC_DIALOGUE, [575 {576 message: message,577 acceptCallback: acceptCallback,578 buttonText: buttonText,579 allowClose: allowClose580 }]);581 }582 closeActiveDialogue(): void{583 $.publish(BaseCommands.CLOSE_ACTIVE_DIALOGUE);584 }585 isOverlayActive(): boolean{586 return Shell.$overlays.is(':visible');587 }588 viewManifest(manifest: Manifesto.IManifest): void{589 var p = new BootstrapParams();590 p.manifestUri = this.provider.manifestUri;591 p.collectionIndex = this.provider.getCollectionIndex(manifest);592 p.manifestIndex = manifest.index;593 p.sequenceIndex = 0;594 p.canvasIndex = 0;595 this.provider.reload(p);596 }597 viewCollection(collection: Manifesto.ICollection): void{598 var p = new BootstrapParams();599 p.manifestUri = this.provider.manifestUri;600 p.collectionIndex = collection.index;601 p.manifestIndex = 0;602 p.sequenceIndex = 0;603 p.canvasIndex = 0;604 this.provider.reload(p);605 }606 isFullScreen(): boolean {607 return this.bootstrapper.isFullScreen;608 }609 isLeftPanelEnabled(): boolean {610 if (Utils.Bools.GetBool(this.provider.config.options.leftPanelEnabled, true)){611 if (this.provider.isMultiCanvas()){612 if (this.provider.getViewingHint().toString() !== manifesto.ViewingHint.continuous().toString()){613 return true;614 }615 }616 }617 return false;618 }619 isRightPanelEnabled(): boolean {620 return Utils.Bools.GetBool(this.provider.config.options.rightPanelEnabled, true);621 }622 useArrowKeysToNavigate(): boolean {623 return Utils.Bools.GetBool(this.provider.config.options.useArrowKeysToNavigate, true);624 }625 bookmark(): void {626 // override for each extension627 }628 feedback(): void {629 this.triggerSocket(BaseCommands.FEEDBACK, new BootstrapParams());630 }631 getBookmarkUri(): string {632 var absUri = parent.document.URL;633 var parts = Utils.Urls.GetUrlParts(absUri);634 var relUri = parts.pathname + parts.search + parent.document.location.hash;635 if (!relUri.startsWith("/")) {636 relUri = "/" + relUri;637 }638 return relUri;639 }640 // auth641 clickThrough(resource: Manifesto.IExternalResource): Promise<void> {642 return new Promise<void>((resolve) => {643 $.publish(BaseCommands.SHOW_CLICKTHROUGH_DIALOGUE, [{644 resource: resource,645 acceptCallback: () => {646 var win = window.open(resource.clickThroughService.id);647 var pollTimer = window.setInterval(() => {648 if (win.closed) {649 window.clearInterval(pollTimer);650 $.publish(BaseCommands.CLICKTHROUGH_OCCURRED);651 resolve();652 }653 }, 500);654 }655 }]);656 });657 }658 restricted(resource: Manifesto.IExternalResource): Promise<void> {659 return new Promise<void>((resolve, reject) => {660 $.publish(BaseCommands.SHOW_RESTRICTED_DIALOGUE, [{661 resource: resource,662 acceptCallback: () => {663 $.publish(BaseCommands.LOAD_FAILED);664 reject(resource);665 }666 }]);667 });668 }669 login(resource: Manifesto.IExternalResource): Promise<void> {670 return new Promise<void>((resolve) => {671 var options: ILoginDialogueOptions = <ILoginDialogueOptions>{};672 if (resource.status === HTTPStatusCode.FORBIDDEN){673 options.warningMessage = LoginWarningMessages.FORBIDDEN;674 options.showCancelButton = true;675 }676 $.publish(BaseCommands.SHOW_LOGIN_DIALOGUE, [{677 resource: resource,678 acceptCallback: () => {679 var win = window.open(resource.loginService.id + "?t=" + new Date().getTime());680 var pollTimer = window.setInterval(function () {681 if (win.closed) {682 window.clearInterval(pollTimer);683 $.publish(BaseCommands.AUTHORIZATION_OCCURRED);684 resolve();685 }686 }, 500);687 },688 options: options689 }]);690 });691 }692 getAccessToken(resource: Manifesto.IExternalResource, rejectOnError: boolean): Promise<Manifesto.IAccessToken> {693 return new Promise<Manifesto.IAccessToken>((resolve, reject) => {694 $.getJSON(resource.tokenService.id + "?callback=?", (token: Manifesto.IAccessToken) => {695 if (token.error){696 if(rejectOnError) {697 reject(token.errorDescription);698 } else {699 resolve(null);700 }701 } else {702 resolve(token);703 }704 }).fail((error) => {705 if(rejectOnError) {706 reject(error);707 } else {708 resolve(null);709 }710 });711 });712 }713 storeAccessToken(resource: Manifesto.IExternalResource, token: Manifesto.IAccessToken, storageStrategy: string): Promise<void> {714 return new Promise<void>((resolve, reject) => {715 Utils.Storage.set(resource.tokenService.id, token, token.expiresIn, new Utils.StorageType(storageStrategy));716 resolve();717 });718 }719 getStoredAccessToken(resource: Manifesto.IExternalResource, storageStrategy: string): Promise<Manifesto.IAccessToken> {720 return new Promise<Manifesto.IAccessToken>((resolve, reject) => {721 var foundItems: storage.StorageItem[] = [];722 var item: storage.StorageItem;723 // try to match on the tokenService, if the resource has one:724 if(resource.tokenService) {725 item = Utils.Storage.get(resource.tokenService.id, new Utils.StorageType(storageStrategy));726 }727 // first try an exact match of the url728 //var item: storage.StorageItem = Utils.Storage.get(resource.dataUri, new Utils.StorageType(storageStrategy));729 if (item){730 foundItems.push(item);731 } else {732 // find an access token for the domain733 var domain = Utils.Urls.GetUrlParts(resource.dataUri).hostname;734 var items: storage.StorageItem[] = Utils.Storage.getItems(new Utils.StorageType(storageStrategy));735 for(var i = 0; i < items.length; i++) {736 item = items[i];737 if(item.key.contains(domain)) {738 foundItems.push(item);739 }740 }741 }742 // sort by expiresAt743 foundItems = _.sortBy(foundItems, (item: storage.StorageItem) => {744 return item.expiresAt;745 });746 var foundToken: IAccessToken;747 if (foundItems.length){748 foundToken = <Manifesto.IAccessToken>foundItems.last().value749 }750 resolve(foundToken);751 });752 }753 handleExternalResourceResponse(resource: Manifesto.IExternalResource): Promise<any> {754 return new Promise<any>((resolve, reject) => {755 resource.isResponseHandled = true;756 if (resource.status === HTTPStatusCode.OK) {757 resolve(resource);758 } else if (resource.status === HTTPStatusCode.MOVED_TEMPORARILY) {759 resolve(resource);760 $.publish(BaseCommands.RESOURCE_DEGRADED, [resource]);761 } else {762 if (resource.error.status === HTTPStatusCode.UNAUTHORIZED ||763 resource.error.status === HTTPStatusCode.INTERNAL_SERVER_ERROR) {764 // if the browser doesn't support CORS765 if (!Modernizr.cors) {766 var informationArgs:InformationArgs = new InformationArgs(InformationType.AUTH_CORS_ERROR, null);767 $.publish(BaseCommands.SHOW_INFORMATION, [informationArgs]);768 resolve(resource);769 } else {770 reject(resource.error.statusText);771 }772 } else if (resource.error.status === HTTPStatusCode.FORBIDDEN){773 var error: Error = new Error();774 error.message = "Forbidden";775 error.name = manifesto.StatusCodes.FORBIDDEN.toString();776 reject(error);777 } else {778 reject(resource.error.statusText);779 }780 }781 });782 }783 handleDegraded(resource: Manifesto.IExternalResource): void {784 var informationArgs: InformationArgs = new InformationArgs(InformationType.DEGRADED_RESOURCE, resource);785 $.publish(BaseCommands.SHOW_INFORMATION, [informationArgs]);786 }787}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const baseCommands = require('fast-check').baseCommands;2const fc = require('fast-check');3const baseCommands = require('fast-check-monorepo').baseCommands;4const baseCommands = require('fast-check').baseCommands;5const fc = require('fast-check');6const baseCommands = require('fast-check-monorepo').baseCommands;7const baseCommands = require('fast-check').baseCommands;8const fc = require('fast-check');9const baseCommands = require('fast-check-monorepo').baseCommands;10const baseCommands = require('fast-check').baseCommands;11const fc = require('fast-check');12const baseCommands = require('fast-check-monorepo').baseCommands;13const baseCommands = require('fast-check').baseCommands;14const fc = require('fast-check');15const baseCommands = require('fast-check-monorepo').baseCommands;16const baseCommands = require('fast-check').baseCommands;17const fc = require('fast-check');18const baseCommands = require('fast-check-monorepo').baseCommands;19const baseCommands = require('fast-check').baseCommands;20const fc = require('fast-check');21const baseCommands = require('fast-check-monorepo').baseCommands;22const baseCommands = require('fast-check').baseCommands;23const fc = require('fast-check');24const baseCommands = require('fast-check-monorepo').baseCommands;25const baseCommands = require('fast-check').baseCommands;26const fc = require('fast-check');27const baseCommands = require('fast-check-monorepo').baseCommands;28const baseCommands = require('fast-check').baseCommands;29const fc = require('fast-check');30const baseCommands = require('fast-check-monorepo').baseCommands;31const baseCommands = require('fast-check').baseCommands;32const fc = require('fast-check');33const baseCommands = require('fast-check-monorepo').baseCommands;34const baseCommands = require('fast-check').baseCommands;35const fc = require('fast-check');36const baseCommands = require('fast-check-monorepo').baseCommands;37const baseCommands = require('fast-check').baseCommands;38const fc = require('fast-check');39const baseCommands = require('fast-check-monorepo').baseCommands;40const baseCommands = require('fast-check').baseCommands;

Full Screen

Using AI Code Generation

copy

Full Screen

1const baseCommands = require("fast-check-monorepo").baseCommands;2const commands = baseCommands();3console.log("commands", commands);4{5 "scripts": {6 },7 "devDependencies": {8 }9}

Full Screen

Using AI Code Generation

copy

Full Screen

1var fc = require('fast-check');2var baseCommands = require('fast-check-monorepo').baseCommands;3var commands = baseCommands()4 .add('add', function (a, b) {5 return a + b;6 })7 .add('sub', function (a, b) {8 return a - b;9 })10 .add('mul', function (a, b) {11 return a * b;12 })13 .add('div', function (a, b) {14 return a / b;15 });16var model = {17 apply: function (cmd) {18 this.state = cmd(this.state);19 }20};21var arb = {22 cmd: fc.constantFrom(...commands.keys()),23 args: fc.tuple(fc.integer(), fc.integer())24};25fc.assert(26 fc.property(fc.commands(commands, arb), function (cmds) {27 var actual = cmds.run(model);28 return actual.state === 0;29 })30);31{32 "scripts": {33 },34 "dependencies": {35 },36 "devDependencies": {37 }38}39module.exports = {40};41var fc = require('fast-check');42var baseCommands = require('fast-check-monorepo').baseCommands;43var commands = baseCommands()44 .add('add', function (a, b) {45 return a + b;46 })47 .add('sub', function (a, b) {48 return a - b;49 })50 .add('mul', function (a, b) {51 return a * b;52 })53 .add('div', function (a, b) {54 return a / b;55 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { baseCommands } = require('fast-check-monorepo');2const { runCommand } = require('./run-command');3const commands = baseCommands();4async function runTest() {5 const result = await runCommand(commands[0]);6 console.log(result);7}8runTest();9at checkExecSyncError (child_process.js:621:11)10at execSync (child_process.js:657:15)11at runCommand (/Users/ashish/Documents/Projects/JavaScript/fast-check-monorepo/run-command.js:7:21)12at runTest (/Users/ashish/Documents/Projects/JavaScript/fast-check-monorepo/test.js:17:20)13at Object. (/Users/ashish/Documents/Projects/JavaScript/fast-check-monorepo/test.js:22:1)14at Module._compile (internal/modules/cjs/loader.js:1137:30)15at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)16at Module.load (internal/modules/cjs/loader.js:985:32)17at Function.Module._load (internal/modules/cjs/loader.js:878:14)18at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

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 fast-check-monorepo 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