Best JavaScript code snippet using devicefarmer-stf
fs-cms-page.adapter.spec.ts
Source:fs-cms-page.adapter.spec.ts
1import { TestBed } from '@angular/core/testing';2import { BaseSiteService, ConfigModule, LanguageService, PageContext, PageType } from '@spartacus/core';3import { of, Subscription } from 'rxjs';4import { FsSpartacusBridgeModule } from '../../../fs-spartacus-bridge.module';5import { CaasClientFactory } from '../../caas/caas-client.factory';6import { FsCmsPageAdapter } from './fs-cms-page.adapter';7import { FS_CMS_PAGE_PREPARER } from './fs-cms-page.converter';8import { caasFilterResult, fsCmsPageInterfaceJsonEn } from './fs-cms-page.adapter.spec.data';9import createSpy = jasmine.createSpy;10import Spy = jasmine.Spy;11import { MockBaseSiteService } from './processing/merge/cms-structure-model-merger-factory.spec';12class MockPreparer {13 convert = createSpy('Converter.convert').and.returnValue(of(fsCmsPageInterfaceJsonEn));14}15class MockCaasClient {16 getByUid: Spy;17 getByIds: Spy;18 constructor(result) {19 this.getByUid = createSpy('CaasClient.getByUid').and.returnValue(of(result));20 this.getByIds = createSpy('CaaSclient.getByIds').and.returnValue(of({}));21 }22}23function caasClientFactory(client) {24 return () => ({25 createCaasClient: () => of(client),26 });27}28function languageServiceFactory(language) {29 return () => ({30 getActive: () => of(language),31 setActive: (isecode: string): Subscription => new Subscription(),32 });33}34describe('FsCmsPageAdapter', () => {35 const caasClient = new MockCaasClient(caasFilterResult);36 const pageContext: PageContext = { id: 'homepage', type: PageType.CONTENT_PAGE };37 beforeEach(() => {38 TestBed.configureTestingModule({39 imports: [40 FsSpartacusBridgeModule.withConfig({41 bridge: {42 test: {43 caas: {44 baseUrl: 'baseUrl',45 project: 'project',46 apiKey: 'apiKey',47 tenantId: 'defaultTenant',48 },49 firstSpiritManagedPages: [],50 },51 },52 }),53 ConfigModule.forRoot(),54 ],55 providers: [56 { provide: LanguageService, useFactory: languageServiceFactory('de') },57 { provide: CaasClientFactory, useFactory: caasClientFactory(caasClient) },58 { provide: FS_CMS_PAGE_PREPARER, useClass: MockPreparer, multi: true },59 { provide: BaseSiteService, useClass: MockBaseSiteService },60 ],61 });62 });63 it('should call caas client with right parameters', (done) => {64 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);65 adapter.load(pageContext).subscribe((result) => {66 expect(caasClient.getByUid).toHaveBeenCalledWith('homepage', 'de', 'homepage');67 done();68 });69 });70 it('should forward the caas document to the converter', (done) => {71 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);72 adapter.load(pageContext).subscribe((result) => {73 const converters = TestBed.inject(FS_CMS_PAGE_PREPARER);74 expect(converters[1].convert.calls.mostRecent().args[0]).toEqual(caasFilterResult._embedded['rh:doc'][0]);75 done();76 });77 });78 it("should store the page's uid once it's known and use it to query the CaaS", (done) => {79 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);80 expect((adapter as any).seoUrlToUidMap.get('test_seo_route')).toBeUndefined();81 adapter.load({ id: 'test_seo_route', type: PageType.CONTENT_PAGE }).subscribe((result) => {82 expect(caasClient.getByUid).toHaveBeenCalledWith('test_seo_route', 'de', 'test_seo_route');83 expect((adapter as any).seoUrlToUidMap.get('test_seo_route')).toBe('homepage');84 expect((adapter as any).seoUrlToUidMap.get('unknown_seo_url')).toBeUndefined();85 adapter.load({ id: 'test_seo_route', type: PageType.CONTENT_PAGE }).subscribe((innerResult) => {86 expect(caasClient.getByUid).toHaveBeenCalledWith('homepage', 'de', 'test_seo_route');87 expect((adapter as any).seoUrlToUidMap.get('test_seo_route')).toBe('homepage');88 done();89 });90 });91 });92 it("should not store the page's uid if the seo url is empty", (done) => {93 TestBed.overrideProvider(LanguageService, {94 useFactory: languageServiceFactory('fr'),95 });96 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);97 expect((adapter as any).seoUrlToUidMap.get('')).toBeUndefined();98 adapter.load(pageContext).subscribe((result) => {99 expect(caasClient.getByUid).toHaveBeenCalledWith('homepage', 'fr', 'homepage');100 expect((adapter as any).seoUrlToUidMap.get('')).toBeUndefined();101 done();102 });103 });104 it('should forward the caas document in the language of the storefront', (done) => {105 TestBed.overrideProvider(LanguageService, {106 useFactory: languageServiceFactory('ar'),107 });108 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);109 adapter.load(pageContext).subscribe((result) => {110 const converters = TestBed.inject(FS_CMS_PAGE_PREPARER);111 expect(converters[1].convert.calls.mostRecent().args[0]).toEqual(caasFilterResult._embedded['rh:doc'][2]);112 done();113 });114 });115 it('should forward the first caas document if no caas document in the language of the storefront is found', (done) => {116 TestBed.overrideProvider(LanguageService, {117 useFactory: languageServiceFactory('other_language'),118 });119 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);120 adapter.load(pageContext).subscribe((result) => {121 const converters = TestBed.inject(FS_CMS_PAGE_PREPARER);122 expect(converters[1].convert.calls.mostRecent().args[0]).toEqual(caasFilterResult._embedded['rh:doc'][0]);123 done();124 });125 });126 it('should return an empty page, if no matching caas document was found', (done) => {127 TestBed.overrideProvider(CaasClientFactory, {128 useFactory: caasClientFactory(129 new MockCaasClient({130 _id: 'preview.content',131 _etag: {132 $oid: '5e3c27ae58512d0001629f20',133 },134 _returned: 0,135 })136 ),137 });138 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);139 adapter.load(pageContext).subscribe((result) => {140 expect(result).toBeNull();141 done();142 });143 });144 it('should return an empty page, if the caas response can not be parsed', (done) => {145 TestBed.overrideProvider(CaasClientFactory, {146 useFactory: caasClientFactory(new MockCaasClient({})),147 });148 const adapter: FsCmsPageAdapter = TestBed.inject(FsCmsPageAdapter);149 adapter.load(pageContext).subscribe((result) => {150 expect(result).toBeNull();151 done();152 });153 });...
main.js
Source:main.js
1'use strict';2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.createMultiLspLanguageService = undefined;6var _asyncToGenerator = _interopRequireDefault(require('async-to-generator'));7/**8 * Creates a language service capable of connecting to an LSP server.9 * Note that spawnOptions and initializationOptions must both be RPC-able.10 *11 * TODO: Document all of the fields below.12 */13/**14 * Copyright (c) 2015-present, Facebook, Inc.15 * All rights reserved.16 *17 * This source code is licensed under the license found in the LICENSE file in18 * the root directory of this source tree.19 *20 * 21 * @format22 */23let createMultiLspLanguageService = exports.createMultiLspLanguageService = (() => {24 var _ref = (0, _asyncToGenerator.default)(function* (languageId, command, args, params) {25 const result = new (_nuclideLanguageServiceRpc || _load_nuclideLanguageServiceRpc()).MultiProjectLanguageService();26 const logger = (0, (_log4js || _load_log4js()).getLogger)(params.logCategory);27 logger.setLevel(params.logLevel);28 const fileCache = params.fileNotifier;29 if (!(fileCache instanceof (_main || _load_main()).FileCache)) {30 throw new Error('Invariant violation: "fileCache instanceof FileCache"');31 }32 // This MultiProjectLanguageService stores LspLanguageServices, lazily33 // created upon demand, one per project root. Demand is usually "when the34 // user opens a file" or "when the user requests project-wide symbol search".35 // What state is the each LspLanguageService in? ...36 // * 'Initializing' state, still spawning the LSP server and negotiating with37 // it, or inviting the user via a dialog box to retry initialization.38 // * 'Ready' state, able to handle LanguageService requests properly.39 // * 'Stopped' state, meaning that the LspConnection died and will not be40 // restarted, but we can still respond to those LanguageServiceRequests41 // that don't require an LspConnection).42 const languageServiceFactory = (() => {43 var _ref2 = (0, _asyncToGenerator.default)(function* (projectDir) {44 yield result.hasObservedDiagnostics();45 // We're awaiting until AtomLanguageService has observed diagnostics (to46 // prevent race condition: see below).47 const lsp = new (_LspLanguageService || _load_LspLanguageService()).LspLanguageService(logger, fileCache, (yield (0, (_nuclideLanguageServiceRpc || _load_nuclideLanguageServiceRpc()).forkHostServices)(params.host, logger)), languageId, command, args, params.spawnOptions, projectDir, params.fileExtensions, params.initializationOptions || {});48 lsp.start(); // Kick off 'Initializing'...49 return lsp;50 // CARE! We want to avoid a race condition where LSP starts producing51 // diagnostics before AtomLanguageService has yet had a chance to observe52 // them (and we don't want to have to buffer the diagnostics indefinitely).53 // We rely on the fact that LSP won't produce them before start() has54 // returned. As soon as we ourselves return, MultiProjectLanguageService55 // will hook up observeDiagnostics into the LSP process, so it'll be ready.56 });57 return function languageServiceFactory(_x5) {58 return _ref2.apply(this, arguments);59 };60 })();61 result.initialize(logger, fileCache, params.host, params.projectFileNames, params.fileExtensions, languageServiceFactory);62 return result;63 });64 return function createMultiLspLanguageService(_x, _x2, _x3, _x4) {65 return _ref.apply(this, arguments);66 };67})();68var _log4js;69function _load_log4js() {70 return _log4js = require('log4js');71}72var _LspLanguageService;73function _load_LspLanguageService() {74 return _LspLanguageService = require('./LspLanguageService');75}76var _main;77function _load_main() {78 return _main = require('../../nuclide-open-files-rpc/lib/main');79}80var _nuclideLanguageServiceRpc;81function _load_nuclideLanguageServiceRpc() {82 return _nuclideLanguageServiceRpc = require('../../nuclide-language-service-rpc');83}...
Using AI Code Generation
1var languageService = require('devicefarmer-stf-libs').LanguageServiceFactory.create()2var languageService = require('devicefarmer-stf-libs').LanguageService3var languageService = require('devicefarmer-stf-libs').LanguageService4var languageService = require('devicefarmer-stf-libs').LanguageService5var languageService = require('devicefarmer-stf-libs').LanguageService6var languageService = require('devicefarmer-stf-libs').LanguageService7var languageService = require('devicefarmer-stf-libs').LanguageService8var languageService = require('devicefarmer-stf-libs').LanguageService9var languageService = require('devicefarmer-stf-libs').LanguageService10var languageService = require('devicefarmer-stf-libs').LanguageService11var languageService = require('devicefarmer-stf-libs').LanguageService12var languageService = require('devicefarmer-stf-libs').LanguageService13var languageService = require('devicefarmer-stf-libs').LanguageService14var languageService = require('devicefarmer-stf-libs').LanguageService15var languageService = require('devicefarmer-stf-libs').LanguageService
Using AI Code Generation
1var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;2var languageService = LanguageServiceFactory.getLanguageService();3var language = languageService.getLanguage();4var country = languageService.getCountry();5var locale = languageService.getLocale();6var languageList = languageService.getLanguageList();7var countryList = languageService.getCountryList();8var localeList = languageService.getLocaleList();9var languageListForCountry = languageService.getLanguageListForCountry('US');10var countryListForLanguage = languageService.getCountryListForLanguage('en');11var localeListForLanguage = languageService.getLocaleListForLanguage('en');12var localeListForCountry = languageService.getLocaleListForCountry('US');13var localeListForLanguageAndCountry = languageService.getLocaleListForLanguageAndCountry('en', 'US');14var languageNameForLanguageCode = languageService.getLanguageNameForLanguageCode('en');15var languageNameForCountryCode = languageService.getLanguageNameForCountryCode('US');16var languageNameForLocaleCode = languageService.getLanguageNameForLocaleCode('en_US');17var countryNameForLanguageCode = languageService.getCountryNameForLanguageCode('en');18var countryNameForCountryCode = languageService.getCountryNameForCountryCode('US');19var countryNameForLocaleCode = languageService.getCountryNameForLocaleCode('en_US');20var localeNameForLanguageCode = languageService.getLocaleNameForLanguageCode('en');21var localeNameForCountryCode = languageService.getLocaleNameForCountryCode('US');
Using AI Code Generation
1var languageServiceFactory = require('devicefarmer-stf').languageServiceFactory;2var LanguageService = require('devicefarmer-stf').LanguageService;3var LanguageService = require('devicefarmer-stf').LanguageService;4var LanguageService = require('devicefarmer-stf').LanguageService;5var LanguageService = require('devicefarmer-stf').LanguageService;6var LanguageService = require('devicefarmer-stf').LanguageService;7var LanguageService = require('devicefarmer-stf').LanguageService;8var LanguageService = require('devicefarmer-stf').LanguageService;9var LanguageService = require('devicefarmer-stf').LanguageService;10var LanguageService = require('devicefarmer-stf').LanguageService;11var LanguageService = require('devicefarmer-stf').LanguageService;12var LanguageService = require('devicefarmer-stf
Using AI Code Generation
1var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;2var languageService = languageServiceFactory.create();3languageService.setLanguage('en');4var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;5var languageService = languageServiceFactory.create();6languageService.setLanguage('en');7var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;8var languageService = languageServiceFactory.create();9languageService.setLanguage('en');10var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;11var languageService = languageServiceFactory.create();12languageService.setLanguage('en');13var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;14var languageService = languageServiceFactory.create();15languageService.setLanguage('en');16var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;17var languageService = languageServiceFactory.create();18languageService.setLanguage('en');19var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;20var languageService = languageServiceFactory.create();21languageService.setLanguage('en');22var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;23var languageService = languageServiceFactory.create();24languageService.setLanguage('en');25var languageServiceFactory = require('devicefarmer-stf').service.LanguageServiceFactory;26var languageService = languageServiceFactory.create();27languageService.setLanguage('en');
Using AI Code Generation
1var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;2var LanguageService = LanguageServiceFactory.createLanguageService();3LanguageService.getLanguages().then(function(languages) {4 console.log(languages);5});6 throw err;7 at Function.Module._resolveFilename (module.js:469:15)8 at Function.Module._load (module.js:417:25)9 at Module.require (module.js:497:17)10 at require (internal/module.js:20:19)11 at Object.<anonymous> (/home/ubuntu/test/test.js:1:15)12 at Module._compile (module.js:570:32)13 at Object.Module._extensions..js (module.js:579:10)14 at Module.load (module.js:487:32)15 at tryModuleLoad (module.js:446:12)16 at Function.Module._load (module.js:438:3)
Using AI Code Generation
1var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;2var languageServiceFactory = new LanguageServiceFactory();3var languageService = languageServiceFactory.createLanguageService("en-US");4var result = languageService.getLanguage();5console.log(result);6var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;7var languageServiceFactory = new LanguageServiceFactory();8var languageService = languageServiceFactory.createLanguageService("en-US");9var result = languageService.getLanguage();10console.log(result);11var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;12var languageServiceFactory = new LanguageServiceFactory();13var languageService = languageServiceFactory.createLanguageService("en-US");14var result = languageService.getLanguage();15console.log(result);16var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;17var languageServiceFactory = new LanguageServiceFactory();18var languageService = languageServiceFactory.createLanguageService("en-US");19var result = languageService.getLanguage();20console.log(result);21var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;22var languageServiceFactory = new LanguageServiceFactory();23var languageService = languageServiceFactory.createLanguageService("en-US");24var result = languageService.getLanguage();25console.log(result);26var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;27var languageServiceFactory = new LanguageServiceFactory();28var languageService = languageServiceFactory.createLanguageService("en-US");29var result = languageService.getLanguage();30console.log(result);31var LanguageServiceFactory = require("devicefarmer-stf").LanguageServiceFactory;
Using AI Code Generation
1var adbkit = require('adbkit');2var LanguageServiceFactory = require('adbkit-language-service');3var client = adbkit.createClient();4var languageService = LanguageServiceFactory(client);5languageService.inputText('hello world')6 .then(function() {7 console.log('Input text');8 })9 .catch(function(err) {10 console.error('Something went wrong:', err.stack);11 });12var adbkit = require('adbkit');13var LanguageServiceFactory = require('adbkit-language-service');14var client = adbkit.createClient();15var languageService = LanguageServiceFactory(client);16languageService.inputText('hello world')17 .then(function() {18 console.log('Input text');19 })20 .catch(function(err) {21 console.error('Something went wrong:', err.stack);22 });23var adbkit = require('adbkit');24var LanguageServiceFactory = require('adbkit-language-service');25var client = adbkit.createClient();26var languageService = LanguageServiceFactory(client);27languageService.inputText('hello world')28 .then(function() {29 console.log('Input text');30 })31 .catch(function(err) {32 console.error('Something went wrong:', err.stack);33 });34var adbkit = require('adbkit');35var LanguageServiceFactory = require('adbkit-language-service');36var client = adbkit.createClient();37var languageService = LanguageServiceFactory(client);38languageService.inputText('hello world')39 .then(function() {40 console.log('Input text');41 })42 .catch(function(err) {43 console.error('Something went wrong:', err.stack);44 });45var adbkit = require('adbkit');46var LanguageServiceFactory = require('adbkit-language-service');47var client = adbkit.createClient();48var languageService = LanguageServiceFactory(client);49languageService.inputText('hello world')50 .then(function() {51 console.log('Input text');52 })53 .catch(function(err)
Using AI Code Generation
1var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;2var languageService = LanguageServiceFactory.createLanguageService();3languageService.getLanguageList(function(err, languages) {4 if (err) {5 console.log(err);6 } else {7 console.log(languages);8 }9});10languageService.setLanguage("en", function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;18var languageService = LanguageServiceFactory.createLanguageService();19languageService.getLanguageList(function(err, languages) {20 if (err) {21 console.log(err);22 } else {23 console.log(languages);24 }25});26languageService.setLanguage("en", function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});33var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;34var languageService = LanguageServiceFactory.createLanguageService();35languageService.getLanguageList(function(err, languages) {36 if (err) {37 console.log(err);38 } else {39 console.log(languages);40 }41});42languageService.setLanguage("en", function(err, result) {43 if (err) {44 console.log(err);45 } else {46 console.log(result);47 }48});49var LanguageServiceFactory = require('devicefarmer-stf').LanguageServiceFactory;50var languageService = LanguageServiceFactory.createLanguageService();51languageService.getLanguageList(function(err, languages) {52 if (err) {53 console.log(err);54 } else {55 console.log(languages);56 }57});58languageService.setLanguage("en", function(err, result) {59 if (err) {60 console.log(err);61 } else {62 console.log(result);63 }64});65var LanguageServiceFactory = require('devicefarmer-stf
Using AI Code Generation
1const LanguageServiceFactory = require('devicefarmer-stf/lib/util/languageservice');2const LanguageService = new LanguageServiceFactory();3const languageName = LanguageService.getLanguageName("en");4const languageCode = LanguageService.getLanguageCode("English");5console.log(languageName);6console.log(languageCode);
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var LanguageServiceFactory = stf.LanguageServiceFactory;3var languageService = LanguageServiceFactory.createService();4languageService.getLanguage(function(err, language) {5 if (err) {6 throw err;7 }8 console.log('Language is ' + language);9});10var stf = require('devicefarmer-stf');11var LanguageServiceFactory = stf.LanguageServiceFactory;12var languageService = LanguageServiceFactory.createService();13languageService.getLanguage(function(err, language) {14 if (err) {15 throw err;16 }17 console.log('Language is ' + language);18});19var stf = require('devicefarmer-stf');20var LanguageServiceFactory = stf.LanguageServiceFactory;21var languageService = LanguageServiceFactory.createService();22languageService.getLanguage(function(err, language) {23 if (err) {24 throw err;25 }26 console.log('Language is ' + language);27});28var stf = require('devicefarmer-stf');29var LanguageServiceFactory = stf.LanguageServiceFactory;30var languageService = LanguageServiceFactory.createService();31languageService.getLanguage(function(err, language) {32 if (err) {33 throw err;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!