How to use getChannelOptions method in storybook-root

Best JavaScript code snippet using storybook-root

ti154stack_network_config.syscfg.js

Source:ti154stack_network_config.syscfg.js Github

copy

Full Screen

...60 {61 name: "channels",62 displayName: "Channel Mask",63 default: getDefaultChannelMask(null),64 options: (inst) => getChannelOptions(inst, false),65 description: Docs.channels.description,66 longDescription: Docs.channels.longDescription67 },68 {69 name: "fhChannels",70 displayName: "FH Channel Mask",71 default: selectAllOptions(getChannelOptions(null, false)),72 options: (inst) => getChannelOptions(inst, false),73 hidden: true,74 description: Docs.fhChannels.description,75 longDescription: Docs.fhChannels.longDescription76 },77 {78 name: "fhAsyncChannels",79 displayName: "FH Async Channel Mask",80 default: selectAllOptions(getChannelOptions(null, false)),81 options: (inst) => getChannelOptions(inst, false),82 hidden: true,83 description: Docs.fhAsyncChannels.description,84 longDescription: Docs.fhAsyncChannels.longDescription85 },86 {87 name: "fhNetname",88 displayName: "FH Network Name",89 default: "FHTest",90 hidden: true,91 description: Docs.fhNetname.description,92 longDescription: Docs.fhNetname.longDescription93 },94 {95 name: "maxDevices",96 displayName: "Max Devices",97 default: 50,98 description: Docs.maxDevices.description,99 longDescription: Docs.maxDevices.longDescription100 },101 {102 displayName: "Application",103 description: "Configure settings for application-level operations",104 config: [105 {106 name: "reportingInterval",107 displayName: "Reporting Interval (ms)",108 default: 3000,109 description: Docs.reportingInterval.description,110 longDescription: Docs.reportingInterval.longDescription111 },112 {113 name: "pollingInterval",114 displayName: "Polling Interval (ms)",115 default: 2000,116 description: Docs.pollingInterval.description,117 longDescription: Docs.pollingInterval.longDescription118 },119 {120 name: "trackingDelayTime",121 displayName: "Tracking Time Delay (ms)",122 default: 5000,123 description: Docs.trackingDelayTime.description,124 longDescription: Docs.trackingDelayTime.longDescription125 },126 {127 name: "scanBackoffInterval",128 displayName: "Scan Back-off Interval (ms)",129 default: 5000,130 hidden: true,131 description: Docs.scanBackoffInterval.description,132 longDescription: Docs.scanBackoffInterval.longDescription133 },134 {135 name: "orphanBackoffInterval",136 displayName: "Orphan Back-off Interval (ms)",137 default: 300000,138 hidden: true,139 description: Docs.orphanBackoffInterval.description,140 longDescription: Docs.orphanBackoffInterval.longDescription141 },142 {143 name: "scanDuration",144 displayName: "Scan Duration (s)",145 default: 5,146 description: Docs.scanDuration.description,147 longDescription: Docs.scanDuration.longDescription148 }149 ]150 },151 {152 displayName: "MAC",153 description: "Configure settings for MAC-level operations",154 config: [155 {156 name: "macBeaconOrder",157 displayName: "MAC Beacon Order",158 default: 15,159 description: Docs.macBeaconOrder.description,160 longDescription: Docs.macBeaconOrder.longDescription,161 readOnly: Docs.macBeaconOrder.readOnly162 },163 {164 name: "macSuperframeOrder",165 displayName: "MAC Super Frame Order",166 default: 15,167 description: Docs.macSuperframeOrder.description,168 longDescription: Docs.macSuperframeOrder.longDescription,169 readOnly: Docs.macSuperframeOrder.readOnly170 },171 {172 name: "minBe",173 displayName: "Min Back-off Exponent",174 default: 3,175 description: Docs.minBe.description,176 longDescription: Docs.minBe.longDescription177 },178 {179 name: "maxBe",180 displayName: "Max Back-off Exponent",181 default: 5,182 description: Docs.maxBe.description,183 longDescription: Docs.maxBe.longDescription184 },185 {186 name: "fhBroadcastInterval",187 displayName: "Broadcast Interval (ms)",188 default: 10000,189 hidden: true,190 description: Docs.fhBroadcastInterval.description,191 longDescription: Docs.fhBroadcastInterval.longDescription192 },193 {194 name: "fhBroadcastDwellTime",195 displayName: "Broadcast Dwell Time (ms)",196 default: 100,197 hidden: true,198 description: Docs.fhBroadcastDwellTime.description,199 longDescription: Docs.fhBroadcastDwellTime.longDescription200 }201 ]202 },203 /* Note: channelMask, fhChannelMask and fhAsyncChannelMask are legacy204 * configs. In order to seamlessly handle custom board changes at205 * runtime, the new channel configs (channels, fhChannels,206 * fhAsyncChannels) are dynamically updated with the correct channel207 * options based on the user's selected RF reference board, frequency208 * band, and data-rate209 *210 * For backwards compatibility, any changes to legacy channel mask211 * configs (from legacy files) that are valid in the new configs will212 * trigger updates to the corresponding new config.213 */214 {215 name: "channelMask",216 displayName: "Legacy Channel Mask",217 default: selectAllOptions(getChannelOptions(null, true)),218 options: getChannelOptions(null, true),219 hidden: true,220 description: "Legacy configurable that should always be hidden",221 longDescription: "Legacy configurable that should always be hidden",222 onChange: (inst) => onLegacyChannelMaskChange(inst, "channelMask",223 "channels")224 },225 {226 name: "fhChannelMask",227 displayName: "Legacy FH Channel Mask",228 default: selectAllOptions(getChannelOptions(null, true)),229 options: getChannelOptions(null, true),230 hidden: true,231 description: "Legacy configurable that should always be hidden",232 longDescription: "Legacy configurable that should always be hidden",233 onChange: (inst) => onLegacyChannelMaskChange(inst, "fhChannelMask",234 "fhChannels")235 },236 {237 name: "fhAsyncChannelMask",238 displayName: "Legacy FH Async Channel Mask",239 default: selectAllOptions(getChannelOptions(null, true)),240 options: getChannelOptions(null, true),241 hidden: true,242 description: "Legacy configurable that should always be hidden",243 longDescription: "Legacy configurable that should always be hidden",244 onChange: (inst) => onLegacyChannelMaskChange(inst,245 "fhAsyncChannelMask", "fhAsyncChannels")246 }247 ]248};249250/*251 *******************************************************************************252 Network Group Config Functions253 *******************************************************************************254 */255256/*257 * ======== onLegacyChannelMaskChange ========258 * On change function to ensure backwards compatibility between former channel259 * mask configs (channelMask, fhChannelMask, fhAsyncChannelMask) and current,260 * dynamically updated channel masks (channels, fhChannels, fhAsyncChannels).261 *262 * New channel mask configs will only be updated if legacy channel setting is263 * valid.264 *265 * @param inst - 15.4 module instance266 * @param legacyCfgName - name of legacy config267 * @param inst - name of new config to which legacy config is mapped268269 */270function onLegacyChannelMaskChange(inst, legacyCfgName, newCfgName)271{272 // Retrieve list of valid channels from new mask config273 const currChannelOptions = getChannelOptions(inst, true);274275 // Accept only channel levels from legacy config that are valid276 const currLegacyChannels = inst[legacyCfgName];277 const validLegacyChannels = Common.validateDynamicMultiEnum(inst, null,278 null, currLegacyChannels, currChannelOptions).validOptsSelected;279280 // Update current channel config with values from legacy config281 if(!_.isEmpty(validLegacyChannels))282 {283 inst[newCfgName] = _.map(validLegacyChannels, String);284 }285}286287/*!288 * ======== getDefaultChannelMask ========289 * Returns the default channel mask config based on default frequency band.290 * Default channel mask is first four supported channels291 *292 * @param inst - 15.4 module instance (null during initialization)293 * @returns - default channel mask config294 */295function getDefaultChannelMask(inst)296{297 const channels = getSupportedChannels(inst);298 const defaultChannels = channels.slice(0, 4);299300 // Return list of channels as strings301 return(defaultChannels.map(String));302}303304/*!305 * ======== selectAllOptions ========306 * Returns array with all values from provided drop down options array307 *308 * @param options - drop down options array309 * @returns - array with all values from options array310 */311function selectAllOptions(options)312{313 return(_.map(options, "name"));314}315316/*!317 * ======== setDefaultChannelMasks ========318 * Sets the default channel mask config based on default frequency band319 * (sub-1 GHz if supported)320 *321 * @param inst - 15.4 module instance (null during initialization)322 */323function setDefaultChannelMasks(inst)324{325 // Set default channel mask for regular channel mask config326 inst.channels = getDefaultChannelMask(inst);327328 // Select all channels supported for FH channel mask configs329 const allSupportedChannels = getChannelOptions(inst, false);330 inst.fhChannels = selectAllOptions(allSupportedChannels);331 inst.fhAsyncChannels = selectAllOptions(allSupportedChannels);332}333334/*335 * ======== getSupportedChannels ========336 * Generate and return array of channels currently supported based on337 * frequency band and phy type currently selected338 *339 * @param inst - 15.4 module instance (null during initialization)340 * @returns array - array of ints341 */342function getSupportedChannels(inst)343{344 let range = [];345346 if((inst == null && !Common.isSub1GHzDevice())347 || (inst != null && inst.freqBand === "freqBand24"))348 {349 range = _.range(11, 27); // Channels 11 - 26350 }351 else if(inst != null && inst.freqSub1 === "freq433")352 {353 range = _.range(0, 7); // Channels 0 - 6354 }355 else if(inst != null && inst.freqSub1 === "freq863")356 {357 if(inst.phyType === "phy5kbps" || inst.phyType === "phy50kbps")358 {359 range = _.range(0, 34); // Channels 0 - 33360 }361 else362 {363 range = _.range(0, 17); // Channels 0 - 16364 }365 }366 else if(inst != null && inst.phyType === "phy200kbps")367 {368 range = _.range(0, 64); // Channels 0 - 63369 }370 else371 {372 // Default case at module initialization (when inst is null)373 range = _.range(0, 129); // Channels 0 - 128374 }375376 return(range);377}378379/*380 * ======== getChannelOptions ========381 * Generate and return options array for channel configs drop down menu382 *383 * @param inst - 15.4 module instance (null during initialization)384 * @param inst - Boolean. True if function called to populate legacy configs385 * @returns array - array of name and display name objects for each channel386 */387function getChannelOptions(inst, isLegacyConfig)388{389 const options = [];390391 // Get largest subset of channels allowed by device392 const allowedRange = getSupportedChannels(inst);393394 // Create an array of drop down options for channel configs395 _.each(allowedRange, (channel) =>396 {397 // Dynamically populated configs only accept arrays of strings, not ints398 // (as used in legacy configs)399 let optionName;400 if(!isLegacyConfig)401 {402 optionName = String(channel);403 }404 else405 {406 optionName = channel;407 }408409 options.push({410 name: optionName,411 displayName: `Channel ${channel}`412 });413 });414415 return(options);416}417418/*419 * ======== setBeaconSuperFrameOrders ========420 * Update beacon and super frame order configs value and visibility based on421 * selected mode422 *423 * @param inst - module instance containing the config that changed424 * @param ui - user interface object425 */426function setBeaconSuperFrameOrders(inst, ui)427{428 if(inst.mode === "beacon")429 {430 ui.macBeaconOrder.readOnly = false;431 ui.macSuperframeOrder.readOnly = false;432 inst.macSuperframeOrder = 8;433 inst.macBeaconOrder = 8;434 }435 else436 {437 ui.macBeaconOrder.readOnly = Docs.macBeaconOrder.readOnly;438 ui.macSuperframeOrder.readOnly = Docs.macSuperframeOrder.readOnly;439 inst.macSuperframeOrder = 15;440 inst.macBeaconOrder = 15;441 }442}443444/*445 * ======== setBeaconInterval ========446 * Update beacon interval readonly value447 *448 * @param inst - module instance containing the config that changed449 * @returns float - beacon interval in seconds450 */451function getBeaconInterval(inst)452{453 let beaconInterval;454455 if(inst.mode === "beacon")456 {457 let symbolsPerBit = 0;458 let dataRate = 0;459 const beaconOrder = inst.macBeaconOrder;460 if(inst.phyType === "phy50kbps")461 {462 symbolsPerBit = 1;463 dataRate = 50;464 }465 else if(inst.phyType === "phy5kbps")466 {467 symbolsPerBit = 5;468 dataRate = 5;469 }470 else if(inst.phyType === "phy200kbps")471 {472 symbolsPerBit = 1;473 dataRate = 200;474 }475 else476 {477 symbolsPerBit = 0.25;478 dataRate = 250;479 }480481 beaconInterval = (960 * (2 ** beaconOrder))482 / (dataRate * 1000 * symbolsPerBit);483 }484485 return(beaconInterval);486}487488/*489 * ======== getNetworkConfigHiddenState ========490 * Get the expected visibility of the selected config491 *492 * @param inst - module instance containing the config that changed493 * @param cfgName - name of config494 * @returns bool - true if hidden, false if visible495 */496function getNetworkConfigHiddenState(inst, cfgName)497{498 const freqHoppingSelected = (inst.mode === "frequencyHopping");499 const beaconModeSelected = (inst.mode === "beacon");500 const isCollectorProject = (inst.project.includes("collector"));501 const isSensorProject = (inst.project.includes("sensor"));502 let isVisible = true;503 switch(cfgName)504 {505 case "channelMask":506 case "fhChannelMask":507 case "fhAsyncChannelMask":508 {509 // Legacy channel mask configs that should always remain hidden510 isVisible = false;511 break;512 }513 case "channels":514 {515 isVisible = !freqHoppingSelected;516 break;517 }518 case "fhNetname":519 case "fhChannels":520 case "fhAsyncChannels":521 {522 isVisible = freqHoppingSelected;523 break;524 }525 case "fhBroadcastInterval":526 case "fhBroadcastDwellTime":527 {528 isVisible = isCollectorProject && freqHoppingSelected;529 break;530 }531 case "orphanBackoffInterval":532 case "scanBackoffInterval":533 {534 isVisible = isSensorProject && !freqHoppingSelected;535 break;536 }537 case "trackingDelayTime":538 case "maxDevices":539 {540 isVisible = isCollectorProject;541 break;542 }543 case "pollingInterval":544 {545 isVisible = !beaconModeSelected;546 break;547 }548 case "reportingInterval":549 case "panID":550 case "scanDuration":551 case "macBeaconOrder":552 case "macSuperframeOrder":553 case "minBe":554 case "maxBe":555 default:556 {557 isVisible = true;558 break;559 }560 }561562 // Hide all configs for coprocessor project563 isVisible = isVisible && (inst.project !== "coprocessor");564565 // Return whether config is hidden566 return(!isVisible);567}568569/*570 * ======== setNetworkConfigHiddenState ========571 * Sets the visibility of the selected config572 *573 * @param inst - module instance containing the config that changed574 * @param ui - user interface object575 * @param cfgName - name of config576 */577function setNetworkConfigHiddenState(inst, ui, cfgName)578{579 Common.setConfigHiddenState(inst, ui, cfgName, config.config,580 getNetworkConfigHiddenState);581}582583/*584 * ======== setAllNetworkConfigsHiddenState ========585 * Sets the visibility of all network configs586 *587 * @param inst - module instance588 * @param ui - user interface object589 */590function setAllNetworkConfigsHiddenState(inst, ui)591{592 Common.setAllConfigsHiddenState(inst, ui, config.config,593 getNetworkConfigHiddenState);594}595596/*597 * ======== validateOneChannelSelected ========598 * Validate that at least one channel is selected599 *600 * @param inst - Network settings instance to be validated601 * @param validation - object to hold detected validation issues602 * @param cfgName - name of channel mask config to be validated603 */604function validateOneChannelSelected(inst, validation, cfgName)605{606 // Verify that at least one channel is selected (if config not hidden)607 if((!getNetworkConfigHiddenState(inst, cfgName))608 && (inst[cfgName].length === 0))609 {610 validation.logError("Must select at least one channel", inst, cfgName);611 }612}613614/*615 * ======== validateOrder ========616 * Validate the beacon or superframe order for beacon mode617 *618 * @param inst - Network settings instance to be validated619 * @param validation - object to hold detected validation issues620 * @param cfgName - name of beacon/superframe order config to be validated621 */622function validateOrder(inst, validation, cfgName)623{624 if(inst.mode === "beacon")625 {626 Common.validateRangeInt(inst, validation, cfgName, 1, 14);627 if(cfgName === "macBeaconOrder"628 && (inst[cfgName] <= 14) && (inst[cfgName] >= 1))629 {630 validation.logInfo(`MAC Beacon Interval: `631 + `${getBeaconInterval(inst)}sec\n`, inst, cfgName);632 }633 }634}635636/*637 * ======== validateBackOffExponents ========638 * Validate minBe and maxBe configs639 *640 * @param inst - Network settings instance to be validated641 * @param validation - object to hold detected validation issues642 */643function validateBackOffExponents(inst, validation)644{645 if(inst.maxBe < inst.minBe)646 {647 validation.logError("Max must be more than min", inst,648 ["minBe", "maxBe"]);649 }650651 Common.validateRangeInt(inst, validation, "minBe", 0,652 Common.cTypeMax.u_int8);653 Common.validateRangeInt(inst, validation, "maxBe", 0,654 Common.cTypeMax.u_int8);655}656657/*658 * ======== validate ========659 * Validate this inst's configuration660 *661 * @param inst - Network settings instance to be validated662 * @param validation - object to hold detected validation issues663 */664function validate(inst, validation)665{666 // Validate PAN ID range -- always visible667 Common.validateRangeHex(inst, validation, "panID", 0, 0xffff);668669 // Validate dynamic channel configs670 const validOptions = getChannelOptions(inst, false);671672 if(!getNetworkConfigHiddenState(inst, "channels"))673 {674 // Verify that at least one channel is selected675 validateOneChannelSelected(inst, validation, "channels");676 Common.validateDynamicMultiEnum(inst, validation, "channels",677 inst.channels, validOptions);678 }679680 if(!getNetworkConfigHiddenState(inst, "fhChannels"))681 {682 // Verify that at least one channel is selected683 validateOneChannelSelected(inst, validation, "fhChannels");684 Common.validateDynamicMultiEnum(inst, validation, "fhChannels", ...

Full Screen

Full Screen

actions.test.js

Source:actions.test.js Github

copy

Full Screen

...32 actionsResult['test-action']('one');33 actionsResult['test-action2']('two');34 expect(getChannelData(channel, 0)).toEqual({ name: 'test-action', args: ['one'] });35 expect(getChannelData(channel, 1)).toEqual({ name: 'test-action2', args: ['two'] });36 expect(getChannelOptions(channel, 0).some).toEqual('config');37 expect(getChannelOptions(channel, 1).some).toEqual('config');38 });39 it('with multiple arguments as object', () => {40 const channel = createChannel();41 const actionsResult = actions({42 'test-action': 'test action',43 'test-action2': 'test action two',44 });45 expect(Object.keys(actionsResult)).toEqual(['test-action', 'test-action2']);46 actionsResult['test-action']('one');47 actionsResult['test-action2']('two');48 expect(getChannelData(channel, 0)).toEqual({ name: 'test action', args: ['one'] });49 expect(getChannelData(channel, 1)).toEqual({ name: 'test action two', args: ['two'] });50 });51 it('with first argument as array of arguments + config', () => {52 const channel = createChannel();53 const actionsResult = actions(['test-action', 'test-action2', { some: 'config' }]);54 expect(Object.keys(actionsResult)).toEqual(['test-action', 'test-action2']);55 actionsResult['test-action']('one');56 actionsResult['test-action2']('two');57 expect(getChannelData(channel, 0)).toEqual({ name: 'test-action', args: ['one'] });58 expect(getChannelData(channel, 1)).toEqual({ name: 'test-action2', args: ['two'] });59 expect(getChannelOptions(channel, 0).some).toEqual('config');60 expect(getChannelOptions(channel, 1).some).toEqual('config');61 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getChannelOptions } from 'storybook-root-decorator';2import React from 'react';3import { storiesOf } from '@storybook/react';4import { withKnobs } from '@storybook/addon-knobs';5import { withRootDecorator } from 'storybook-root-decorator';6import { withTheme } from 'storybook-addon-material-ui';7import { withInfo } from '@storybook/addon-info';8import { withNotes } from '@storybook/addon-notes';9import { withReadme } from 'storybook-readme';10storiesOf('Test', module)11 .addDecorator(withRootDecorator())12 .addDecorator(withKnobs)13 .addDecorator(withTheme())14 .addDecorator(withInfo())15 .addDecorator(withNotes)16 .addDecorator(withReadme)17 .addDecorator(story => {18 const options = getChannelOptions();19 return story();20 })21 .add('with text', () => <div>hello</div>);22### withRootDecorator([options])23- `options` (optional) - Object with the following properties:24 - `themeOptions` (optional) - Object with the following properties:25 - `spacing` (optional) - The spacing to use. Defaults to

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getChannelOptions } from 'storybook-root';2const channelOptions = getChannelOptions();3const channel = addons.getChannel();4channel.emit(channelOptions.eventId, {5 payload: {6 error: {7 },8 },9});10MIT © [dmitriy-kudlovich](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getChannelOptions } from 'storybook-root';2const { store, api, addons, fullAPI, forceReRender, configApi } = getChannelOptions(channel);3import { getStorybook } from 'storybook-root';4const stories = getStorybook();5import { getStorybookUI } from 'storybook-root';6const StorybookUI = getStorybookUI({

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