Best JavaScript code snippet using storybook-root
partialValueFunction.js
Source:partialValueFunction.js
1'use strict';2define(['mcda/controllers/helpers/wizard', 'angular', 'mcda/lib/patavi', 'underscore'], function(Wizard, angular, patavi, _) {3 return function($scope, $injector, currentScenario, taskDefinition, PartialValueFunction) {4 var standardize = function(state) {5 // Copy choices to problem6 _.each(_.pairs(state.problem.criteria), function(pair) {7 var name = pair[0], criterion = pair[1];8 var isLinear = state.choice.data[name].type === "linear";9 var baseIncluded = ["range", "type", "direction"];10 var included = isLinear ? baseIncluded : baseIncluded.concat(["values", "cutoffs"]);11 criterion.pvf = _.pick(state.choice.data[name], included);12 });13 return state;14 };15 var initialize = function(state) {16 function pluckObject(obj, field) {17 return _.object(_.map(_.pairs(obj), function(el) {18 return [el[0], el[1][field]];19 }));20 }21 var calculate = function(currentState) {22 var choice = currentState.choice;23 function rewritePreferences(preferences) {24 preferences = angular.copy(preferences);25 for (var i = 0; i < preferences.length; ++i) {26 for (var j = 0; j < preferences[i].length; ++j) {27 var level = choice.preferences.indexOf(preferences[i][j]) + 1;28 preferences[i][j] = level === 0 ? null : level;29 }30 }31 return preferences;32 }33 var preferences = rewritePreferences(choice.data[choice.criterion].preferences);34 var task = patavi.submit("smaa", { method: "macbeth", preferences: preferences });35 task.results.then(function(results) {36 $scope.$root.$safeApply($scope, function() {37 currentState.results = results.results;38 var values = _.clone(results.results);39 values = values.slice(1, values.length - 1);40 choice.data[choice.criterion].values = values;41 currentState.error = null;42 });43 }, function(code, error) {44 $scope.$root.$safeApply($scope, function() {45 currentState.error =46 { code: (code && code.desc) ? code.desc : code,47 cause: error };48 });49 });50 };51 var initial = {52 choice:53 { data: pluckObject(state.problem.criteria, "pvf"),54 calculate: calculate,55 preferences:56 ["Very Weakly", "Weakly", "Moderately", "Strongly", "Very Strongly", "Extremely"],57 getXY: _.memoize(function(data, criterion) {58 var y = [1].concat(data[criterion].values).concat([0]);59 var best = state.problem.criteria[criterion].best();60 var worst = state.problem.criteria[criterion].worst();61 var x = [best].concat(data[criterion].cutoffs).concat([worst]);62 var values = _.map(_.zip(x, y), function(p) {63 return { x: p[0], y: p[1] };64 });65 return [ { key: "Piecewise PVF", values: values }];66 }, function(data, criterion) { // Hash function67 var values = _.reduce(data[criterion].values, function(sum, x) { return sum + x; });68 var cutoffs = _.reduce(data[criterion].cutoffs, function(sum, x) { return sum + x; });69 return 31 * values + cutoffs + criterion.hashCode();70 })71 }72 };73 return _.extend(state, initial);74 };75 var validChoice = function(currentState) {76 if (currentState && currentState.choice.subType === 'elicit values') {77 var criterion = currentState.choice.criterion;78 var choice = currentState.choice.data;79 return choice[criterion].cutoffs.length == choice[criterion].values.length;80 }81 return true;82 };83 var getNextPiecewiseLinear = function(criteria, state) {84 return _.find(criteria, function(c) {85 return state.choice.data[c].type === "piecewise-linear" && !state.choice.data[c].cutoffs;86 });87 };88 var nextState = function(currentState) {89 var nextState = angular.copy(currentState);90 var criteria = _.keys(nextState.problem.criteria).sort();91 var criterion = getNextPiecewiseLinear(criteria, nextState);92 var choice = nextState.choice;93 var info;94 if (choice.subType === 'elicit cutoffs') {95 info = nextState.problem.criteria[choice.criterion];96 choice.subType = 'elicit values';97 var cutoffs = choice.data[choice.criterion].cutoffs;98 var size = cutoffs.length + 2;99 // Initialize preference matrix100 choice.data[choice.criterion].preferences = [];101 for (var i = 0; i < size; ++i) {102 choice.data[choice.criterion].preferences[i] = [];103 for (var j = 0; j < size; ++j) {104 choice.data[choice.criterion].preferences[i][j] = i == j ? choice.preferences[0] : null;105 }106 }107 // Generate comparator lists108 var tmp = [info.best()].concat(cutoffs || []).concat([info.worst()]);109 choice.data[choice.criterion].base = tmp.slice(0, tmp.length - 1);110 choice.data[choice.criterion].comp = [];111 for (i = 0; i < tmp.length - 1; ++i) {112 choice.data[choice.criterion].comp[i] = tmp.slice(i + 1, tmp.length);113 }114 choice.data[choice.criterion].values = [];115 } else if (criterion) {116 info = nextState.problem.criteria[criterion];117 choice.subType = "elicit cutoffs";118 choice.criterion = criterion;119 choice.data[criterion].cutoffs = [];120 choice.data[criterion].addCutoff = function(cutoff) {121 choice.data[criterion].cutoffs.push(cutoff);122 choice.data[criterion].cutoffs.sort(function(a, b) {123 return info.pvf.direction === "decreasing" ? a - b : b - a;124 });125 };126 choice.data[criterion].validCutoff = function(cutoff) {127 var allowed = (cutoff < info.best() && cutoff > info.worst()) || (cutoff < info.worst() && cutoff > info.best());128 var unique = choice.data[criterion].cutoffs.indexOf(cutoff) == -1;129 return allowed && unique;130 };131 }132 return standardize(nextState);133 };134 $scope.save = function(state) {135 currentScenario.update(PartialValueFunction.attach(standardize(state)));136 currentScenario.redirectToDefaultView();137 };138 $scope.canSave = function(state) {139 if(!state) return false;140 var criteria = _.keys(state.problem.criteria).sort();141 var criterion = getNextPiecewiseLinear(criteria, state);142 return state.choice.subType !== 'elicit cutoffs' && !criterion;143 };144 $injector.invoke(Wizard, this, {145 $scope: $scope,146 handler: { validChoice: validChoice,147 fields: ["type", "choice", "title"],148 hasIntermediateResults: false,149 initialize: _.partial(initialize, taskDefinition.clean(currentScenario.state)),150 standardize: _.identity,151 nextState: nextState }152 });153 };...
to-require-context.test.js
Source:to-require-context.test.js
1import path from 'path';2import { toRequireContext } from './to-require-context';3const testCases = [4 {5 glob: '**/*.stories.tsx',6 recursive: true,7 validPaths: [8 './Icon.stories.tsx',9 './src/Icon.stories.tsx',10 './src/components/Icon.stories.tsx',11 './src/components/Icon.stories/Icon.stories.tsx',12 ],13 invalidPaths: [14 './stories.tsx',15 './Icon.stories.ts',16 './Icon.stories.js',17 './src/components/stories.tsx',18 './src/components/Icon.stories/stories.tsx',19 './src/components/Icon.stories.ts',20 './src/components/Icon.stories.js',21 ],22 },23 // INVALID GLOB24 {25 glob: '../src/stories/**/*.stories.(js|mdx)',26 recursive: true,27 validPaths: [28 '../src/stories/components/Icon.stories.js',29 '../src/stories/Icon.stories.js',30 '../src/stories/Icon.stories.mdx',31 '../src/stories/components/Icon/Icon.stories.js',32 '../src/stories/components/Icon.stories/Icon.stories.mdx',33 ],34 invalidPaths: [35 './stories.js',36 './src/stories/Icon.stories.js',37 './Icon.stories.js',38 '../src/Icon.stories.mdx',39 '../src/stories/components/Icon/Icon.stories.ts',40 '../src/stories/components/Icon/Icon.mdx',41 ],42 },43 {44 glob: 'dirname/../stories/*.stories.*',45 recursive: false,46 validPaths: [47 './dirname/../stories/App.stories.js',48 './dirname/../stories/addon-centered.stories.js',49 ],50 invalidPaths: ['./dirname/../stories.js', './dirname/../App.stories.js'],51 },52 {53 glob: '../src/stories/**/@(*.stories.js|*.stories.mdx)',54 recursive: true,55 validPaths: [56 '../src/stories/components/Icon.stories.js',57 '../src/stories/Icon.stories.js',58 '../src/stories/Icon.stories.mdx',59 '../src/stories/components/Icon/Icon.stories.js',60 '../src/stories/components/Icon.stories/Icon.stories.mdx',61 ],62 invalidPaths: [63 './stories.js',64 './src/stories/Icon.stories.js',65 './Icon.stories.js',66 '../src/Icon.stories.mdx',67 '../src/stories/components/Icon/Icon.stories.ts',68 '../src/stories/components/Icon/Icon.mdx',69 ],70 },71 {72 glob: '../src/stories/**/*.stories.+(js|mdx)',73 recursive: true,74 validPaths: [75 '../src/stories/components/Icon.stories.js',76 '../src/stories/Icon.stories.js',77 '../src/stories/Icon.stories.mdx',78 '../src/stories/components/Icon/Icon.stories.js',79 '../src/stories/components/Icon.stories/Icon.stories.mdx',80 ],81 invalidPaths: [82 './stories.js',83 './src/stories/Icon.stories.js',84 './Icon.stories.js',85 '../src/Icon.stories.mdx',86 '../src/stories/components/Icon/Icon.stories.ts',87 '../src/stories/components/Icon/Icon.mdx',88 ],89 },90 {91 glob: '../src/stories/**/*.stories.*(js|mdx)',92 recursive: true,93 validPaths: [94 '../src/stories/components/Icon.stories.js',95 '../src/stories/Icon.stories.js',96 '../src/stories/Icon.stories.mdx',97 '../src/stories/components/Icon/Icon.stories.js',98 '../src/stories/components/Icon.stories/Icon.stories.mdx',99 ],100 invalidPaths: [101 './stories.js',102 './src/stories/Icon.stories.js',103 './Icon.stories.js',104 '../src/Icon.stories.mdx',105 '../src/stories/components/Icon/Icon.stories.ts',106 '../src/stories/components/Icon/Icon.mdx',107 ],108 },109 // DUMB GLOB110 {111 glob: '../src/stories/**/*.stories.[tj]sx',112 recursive: true,113 validPaths: [114 '../src/stories/components/Icon.stories.jsx',115 '../src/stories/Icon.stories.jsx',116 '../src/stories/Icon.stories.tsx',117 '../src/stories/components/Icon/Icon.stories.jsx',118 '../src/stories/components/Icon.stories/Icon.stories.tsx',119 ],120 invalidPaths: [121 './stories.jsx',122 './src/stories/Icon.stories.jsx',123 './Icon.stories.jsx',124 '../src/Icon.stories.tsx',125 '../src/stories/components/Icon/Icon.stories.ts',126 '../src/stories/components/Icon/Icon.tsx',127 ],128 },129 {130 glob: '../components/*.stories.js',131 recursive: false,132 validPaths: ['../components/Icon.stories.js'],133 invalidPaths: [134 '../components/icon/node_modules/icon/Icon.stories.js',135 './stories.js',136 './src/stories/Icon.stories.js',137 './Icon.stories.js',138 '../src/Icon.stories.mdx',139 '../src/stories/components/Icon/Icon.stories.ts',140 '../src/stories/components/Icon/Icon.mdx',141 ],142 },143 {144 glob: '../components/*/*.stories.js',145 recursive: true,146 validPaths: ['../components/icon/Icon.stories.js'],147 invalidPaths: [148 '../components/icon/node_modules/icon/Icon.stories.js',149 './stories.js',150 './src/stories/Icon.stories.js',151 './Icon.stories.js',152 '../src/Icon.stories.mdx',153 '../src/stories/components/Icon/Icon.stories.ts',154 '../src/stories/components/Icon/Icon.mdx',155 ],156 },157 {158 glob: '../components/*/stories/*.js',159 recursive: true,160 validPaths: ['../components/icon/stories/Icon.js'],161 invalidPaths: [162 '../components/icon/node_modules/icon/stories/Icon.js',163 './stories.js',164 './src/stories/Icon.stories.js',165 './Icon.stories.js',166 '../src/Icon.stories.mdx',167 '../src/stories/components/Icon/Icon.stories.ts',168 '../src/stories/components/Icon/Icon.mdx',169 ],170 },171];172describe('toRequireContext', () => {173 testCases.forEach(({ glob, recursive, validPaths, invalidPaths }) => {174 it(`matches only suitable paths - ${glob}`, () => {175 const { path: base, recursive: willRecurse, match } = toRequireContext(glob);176 const regex = new RegExp(match);177 function isMatched(filePath) {178 const relativePath = `./${path.relative(base, filePath)}`;179 const baseIncluded = filePath.includes(base);180 const matched = regex.test(relativePath);181 return baseIncluded && matched;182 }183 const isNotMatchedForValidPaths = validPaths.filter((filePath) => !isMatched(filePath));184 const isMatchedForInvalidPaths = invalidPaths.filter((filePath) => !!isMatched(filePath));185 expect(isNotMatchedForValidPaths).toEqual([]);186 expect(isMatchedForInvalidPaths).toEqual([]);187 expect(willRecurse).toEqual(recursive);188 });189 });...
Using AI Code Generation
1import { baseIncluded } from 'storybook-root-decorator'2import { baseExcluded } from 'storybook-root-decorator'3import { baseIncluded } from 'storybook-root-decorator'4import { baseExcluded } from 'storybook-root-decorator'5import { baseIncluded } from 'storybook-root-decorator'6import { baseExcluded } from 'storybook-root-decorator'7import { baseIncluded } from 'storybook-root-decorator'8import { baseExcluded } from 'storybook-root-decorator'9import { baseIncluded } from 'storybook-root-decorator'10import { baseExcluded } from 'storybook-root-decorator'11import { baseIncluded } from 'storybook-root-decorator'12import { baseExcluded } from 'storybook-root-decorator'13import { baseIncluded } from 'storybook-root-decorator'14import { baseExcluded } from 'storybook-root-decorator'15import { baseIncluded } from 'storybook-root-decorator'16import { baseExcluded } from 'storybook-root-decorator'17import { baseIncluded } from 'storybook-root-decorator'18import { base
Using AI Code Generation
1import { baseIncluded } from 'storybook-root-config';2baseIncluded();3import { baseExcluded } from 'storybook-root-config';4baseExcluded();5import { baseIncludedAndExcluded } from 'storybook-root-config';6baseIncludedAndExcluded();7import { baseIncludedAndExcluded } from 'storybook-root-config';8baseIncludedAndExcluded();9import { baseIncludedAndExcluded } from 'storybook-root-config';10baseIncludedAndExcluded();11import { baseIncludedAndExcluded } from 'storybook-root-config';12baseIncludedAndExcluded();13import { baseIncludedAndExcluded } from 'storybook-root-config';14baseIncludedAndExcluded();15import { baseIncludedAndExcluded } from 'storybook-root-config';16baseIncludedAndExcluded();17import { baseIncludedAndExcluded } from 'storybook-root-config';18baseIncludedAndExcluded();19import { baseIncludedAndExcluded } from 'storybook-root-config';20baseIncludedAndExcluded();21import { baseIncludedAndExcluded } from 'storybook-root-config';22baseIncludedAndExcluded();23import { baseIncludedAndExcluded } from 'storybook-root-config';24baseIncludedAndExcluded();25import { baseIncludedAndExcluded } from 'storybook-root-config';26baseIncludedAndExcluded();27import { baseIncludedAndExcluded } from 'storybook-root-config';28baseIncludedAndExcluded();29import { baseIncludedAndEx
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { baseIncluded } from 'storybook-root';4import MyComponent from './MyComponent';5storiesOf('MyComponent', module).add('default', () => (6));7import React from 'react';8import { baseIncluded } from 'storybook-root';9export default () => {10 const baseIncluded = baseIncluded();11 return (12 {baseIncluded}13 );14};15import { baseIncluded } from 'storybook-root';16describe('baseIncluded', () => {17 it('should return true', () => {18 const baseIncluded = baseIncluded();19 expect(baseIncluded).toBe(true);20 });21});22import { baseIncluded } from 'storybook-root';23describe('baseIncluded', () => {24 it('should return true', () => {25 const baseIncluded = baseIncluded();26 expect(baseIncluded).toMatchSnapshot();27 });28});29import { baseIncluded } from 'storybook-root';30describe('baseIncluded', () => {31 it('should return true', () => {32 const baseIncluded = baseIncluded();33 expect(baseIncluded).toBe(true);34 });35});36import { baseIncluded } from 'storybook-root';37describe('baseIncluded', () => {38 it('should return true', () => {39 const baseIncluded = baseIncluded();40 expect(baseIncluded).toMatchSnapshot();41 });42});43import { baseIncluded } from 'storybook-root';44describe('baseIncluded', () => {45 it('should return true', () => {46 const baseIncluded = baseIncluded();47 expect(baseIncluded).toMatchSnapshot();48 });49});
Using AI Code Generation
1import { baseIncluded } from 'storybook-root';2import { baseIncluded } from 'storybook-root';3import { baseIncluded } from 'storybook-root';4import { baseIncluded } from 'storybook-root';5import { baseIncluded } from 'storybook-root';6import { baseIncluded } from 'storybook-root';7import { baseIncluded } from 'storybook-root';8import { baseIncluded } from 'storybook-root';9import { baseIncluded } from 'storybook-root';10import { baseIncluded } from 'storybook-root';11import { baseIncluded } from 'storybook-root';12import { baseIncluded } from 'storybook-root';13import { baseIncluded } from 'storybook-root';
Using AI Code Generation
1import { baseIncluded } from 'storybook-root';2console.log(baseIncluded());3import { baseIncluded } from 'storybook-root';4console.log(baseIncluded());5import { baseIncluded } from 'storybook-root';6console.log(baseIncluded());7import { baseIncluded } from 'storybook-root';8console.log(baseIncluded());9import { baseIncluded } from 'storybook-root';10console.log(baseIncluded());11import { baseIncluded } from 'storybook-root';12console.log(baseIncluded());13import { baseIncluded } from 'storybook-root';14console.log(baseIncluded());15import { baseIncluded } from 'storybook-root';16console.log(baseIncluded());17import { baseIncluded } from 'storybook-root';18console.log(baseIncluded());19import { baseIncluded } from 'storybook-root';20console.log(baseIncluded());21import { baseIncluded } from 'storybook-root';22console.log(baseIncluded());23import { baseIncluded } from 'storybook-root';24console.log(baseIncluded());25import { baseIncluded } from 'storybook-root';26console.log(baseIncluded());27import { baseIncluded } from 'storybook-root';28console.log(baseIncluded());29import { baseIncluded } from 'storybook-root';30console.log(baseIncluded());31import { baseIncluded } from 'storybook-root';32console.log(baseIncluded());33import { baseIncluded } from 'storybook-root';34console.log(baseIncluded());35import { baseIncluded } from 'storybook-root';
Using AI Code Generation
1import { baseIncluded } from 'storybook-root';2import { baseIncluded } from 'storybook-root/lib/utils';3import { baseIncluded } from 'storybook-root/lib/utils';4import { baseIncluded } from 'storybook-root/lib/utils';5"scripts": {6 }
Using AI Code Generation
1import {baseIncluded} from 'storybook-root-include';2console.log(baseIncluded());3import {storybookIncluded} from 'storybook-root-include';4console.log(storybookIncluded());5import {storybookIncluded} from 'storybook-root-include';6console.log(storybookIncluded());7import {storybookIncluded} from 'storybook-root-include';8console.log(storybookIncluded());9import {storybookIncluded} from 'storybook-root-include';10console.log(storybookIncluded());11import {storybookIncluded} from 'storybook-root-include';12console.log(storybookIncluded());13import {storybookIncluded} from 'storybook-root-include';14console.log(storybookIncluded());15import {storybookIncluded} from 'storybook-root-include';16console.log(storybookIncluded());17import {storybookIncluded} from 'storybook-root-include';18console.log(storybookIncluded());19import {storybookIncluded} from 'storybook-root-include';20console.log(storybookIncluded());21import {storybookIncluded} from 'storybook-root-include';22console.log(storybookIncluded());
Using AI Code Generation
1import { baseIncluded } from "storybook-root-include";2export default {3};4export const test = () => {5 return "test";6};7import { baseIncluded } from "storybook-root-include";8export default {9};10export const test = () => {11 return "test";12};13test.decorators = [baseIncluded];14import { baseIncluded } from "storybook-root-include";15export default {16};17export const test = () => {18 return "test";19};20test.decorators = [baseIncluded];21import { baseIncluded } from "storybook-root-include";22export const decorators = [baseIncluded];23import { baseIncluded
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!!