Best JavaScript code snippet using storybook-root
WorkingHours.js
Source:WorkingHours.js
1import React from 'react'2import { titleCase } from 'title-case';3const WorkingHours = ({ openingHours, midBreaks }) => {4 return (5 <table className="table table-bordered">6 <thead>7 <tr>8 <th></th>9 <th className="text-center" colSpan="2">Open</th>10 <th className="text-center" colSpan="2">Break</th>11 </tr>12 <tr>13 <th>Day</th>14 <th className="text-center">From</th>15 <th className="text-center">To</th>16 <th className="text-center">From</th>17 <th className="text-center">To</th>18 </tr>19 </thead>20 <tbody>21 {mergeAndRenderTimings(openingHours, midBreaks)}22 </tbody>23 </table>24 )25}26const mergeAndRenderTimings = (openingHours, midBreaks) => {27 let timings = {28 sunday: {},29 monday: {},30 tuesday: {},31 wednesday: {},32 thursday: {},33 friday: {},34 saturday: {}35 };36 if (openingHours && openingHours.hasOwnProperty('everyday')) {37 // sunday38 timings = {39 ...timings, sunday: {40 ...timings.sunday,41 timeFrom: openingHours['everyday'].from,42 timeTo: openingHours['everyday'].to43 }44 };45 // monday46 timings = {47 ...timings, monday: {48 ...timings.monday,49 timeFrom: openingHours['everyday'].from,50 timeTo: openingHours['everyday'].to51 }52 };53 // tuesday54 timings = {55 ...timings, tuesday: {56 ...timings.tuesday,57 timeFrom: openingHours['everyday'].from,58 timeTo: openingHours['everyday'].to59 }60 };61 // wednesday62 timings = {63 ...timings, wednesday: {64 ...timings.wednesday,65 timeFrom: openingHours['everyday'].from,66 timeTo: openingHours['everyday'].to67 }68 };69 // thursday70 timings = {71 ...timings, thursday: {72 ...timings.thursday,73 timeFrom: openingHours['everyday'].from,74 timeTo: openingHours['everyday'].to75 }76 };77 // friday78 timings = {79 ...timings, friday: {80 ...timings.friday,81 timeFrom: openingHours['everyday'].from,82 timeTo: openingHours['everyday'].to83 }84 };85 // saturday86 timings = {87 ...timings, saturday: {88 ...timings.saturday,89 timeFrom: openingHours['everyday'].from,90 timeTo: openingHours['everyday'].to91 }92 };93 } else {94 timings = {95 ...timings,96 sunday: {97 ...timings.sunday,98 timeFrom: openingHours && openingHours.hasOwnProperty('sunday') ? openingHours.sunday.from : ' - ',99 timeTo: openingHours && openingHours.hasOwnProperty('sunday') ? openingHours.sunday.to : ' - '100 }, monday: {101 ...timings.monday,102 timeFrom: openingHours && openingHours.hasOwnProperty('monday') ? openingHours.monday.from : ' - ',103 timeTo: openingHours && openingHours.hasOwnProperty('monday') ? openingHours.monday.to : ' - '104 }, tuesday: {105 ...timings.tuesday,106 timeFrom: openingHours && openingHours.hasOwnProperty('tuesday') ? openingHours.tuesday.from : ' - ',107 timeTo: openingHours && openingHours.hasOwnProperty('tuesday') ? openingHours.tuesday.to : ' - '108 }, wednesday: {109 ...timings.wednesday,110 timeFrom: openingHours && openingHours.hasOwnProperty('wednesday') ? openingHours.wednesday.from : ' - ',111 timeTo: openingHours && openingHours.hasOwnProperty('wednesday') ? openingHours.wednesday.to : ' - '112 }, thursday: {113 ...timings.thursday,114 timeFrom: openingHours && openingHours.hasOwnProperty('thursday') ? openingHours.thursday.from : ' - ',115 timeTo: openingHours && openingHours.hasOwnProperty('thursday') ? openingHours.thursday.to : ' - '116 }, friday: {117 ...timings.friday,118 timeFrom: openingHours && openingHours.hasOwnProperty('friday') ? openingHours.friday.from : ' - ',119 timeTo: openingHours && openingHours.hasOwnProperty('friday') ? openingHours.friday.to : ' - '120 }, saturday: {121 ...timings.saturday,122 timeFrom: openingHours && openingHours.hasOwnProperty('saturday') ? openingHours.saturday.from : ' - ',123 timeTo: openingHours && openingHours.hasOwnProperty('saturday') ? openingHours.saturday.to : ' - '124 }125 };126 }127 if (midBreaks && midBreaks.everyday && midBreaks.everyday.from && midBreaks.everyday.to) {128 // sunday129 timings = {130 ...timings, sunday: {131 ...timings.sunday,132 breakFrom: midBreaks['everyday'].from,133 breakTo: midBreaks['everyday'].to134 }135 };136 // monday137 timings = {138 ...timings, monday: {139 ...timings.monday,140 breakFrom: midBreaks['everyday'].from,141 breakTo: midBreaks['everyday'].to142 }143 };144 // tuesday145 timings = {146 ...timings, tuesday: {147 ...timings.tuesday,148 breakFrom: midBreaks['everyday'].from,149 breakTo: midBreaks['everyday'].to150 }151 };152 // wednesday153 timings = {154 ...timings, wednesday: {155 ...timings.wednesday,156 breakFrom: midBreaks['everyday'].from,157 breakTo: midBreaks['everyday'].to158 }159 };160 // thursday161 timings = {162 ...timings, thursday: {163 ...timings.thursday,164 breakFrom: midBreaks['everyday'].from,165 breakTo: midBreaks['everyday'].to166 }167 };168 // friday169 timings = {170 ...timings, friday: {171 ...timings.friday,172 breakFrom: midBreaks['everyday'].from,173 breakTo: midBreaks['everyday'].to174 }175 };176 // saturday177 timings = {178 ...timings, saturday: {179 ...timings.saturday,180 breakFrom: midBreaks['everyday'].from,181 breakTo: midBreaks['everyday'].to182 }183 };184 } else {185 timings = {186 ...timings, sunday: {187 ...timings.sunday,188 breakFrom: midBreaks && midBreaks.sunday && midBreaks.hasOwnProperty('sunday') ? midBreaks.sunday.from : ' - ',189 breakTo: midBreaks && midBreaks.sunday && midBreaks.hasOwnProperty('sunday') ? midBreaks.sunday.to : ' - '190 }, monday: {191 ...timings.monday,192 breakFrom: midBreaks && midBreaks.monday && midBreaks.hasOwnProperty('monday') ? midBreaks.monday.from : ' - ',193 breakTo: midBreaks && midBreaks.monday && midBreaks.hasOwnProperty('monday') ? midBreaks.monday.to : ' - '194 }, tuesday: {195 ...timings.tuesday,196 breakFrom: midBreaks && midBreaks.tuesday && midBreaks.hasOwnProperty('tuesday') ? midBreaks.tuesday.from : ' - ',197 breakTo: midBreaks && midBreaks.tuesday && midBreaks.hasOwnProperty('tuesday') ? midBreaks.tuesday.to : ' - '198 }, wednesday: {199 ...timings.wednesday,200 breakFrom: midBreaks && midBreaks.wednesday && midBreaks.hasOwnProperty('wednesday') ? midBreaks.wednesday.from : ' - ',201 breakTo: midBreaks && midBreaks.wednesday && midBreaks.hasOwnProperty('wednesday') ? midBreaks.wednesday.to : ' - '202 }, thursday: {203 ...timings.thursday,204 breakFrom: midBreaks && midBreaks.thursday && midBreaks.hasOwnProperty('thursday') ? midBreaks.thursday.from : ' - ',205 breakTo: midBreaks && midBreaks.thursday && midBreaks.hasOwnProperty('thursday') ? midBreaks.thursday.to : ' - '206 }, friday: {207 ...timings.friday,208 breakFrom: midBreaks && midBreaks.friday && midBreaks.hasOwnProperty('friday') ? midBreaks.friday.from : ' - ',209 breakTo: midBreaks && midBreaks.friday && midBreaks.hasOwnProperty('friday') ? midBreaks.friday.to : ' - '210 }, saturday: {211 ...timings.saturday,212 breakFrom: midBreaks && midBreaks.saturday && midBreaks.hasOwnProperty('saturday') ? midBreaks.saturday.from : ' - ',213 breakTo: midBreaks && midBreaks.saturday && midBreaks.hasOwnProperty('saturday') ? midBreaks.saturday.to : ' - '214 },215 };216 }217 return Object.keys(timings).map((keyName, i) => {218 return (219 <tr key={keyName}>220 <td className="text-left">{titleCase(keyName)}</td>221 <td className="text-center">{timings[keyName].timeFrom}</td>222 <td className="text-center">{timings[keyName].timeTo}</td>223 <td className="text-center">{timings[keyName].breakFrom}</td>224 <td className="text-center">{timings[keyName].breakTo}</td>225 </tr>226 )227 })228}...
isNonInteractiveElement-test.js
Source:isNonInteractiveElement-test.js
1/* eslint-env mocha */2import expect from 'expect';3import { elementType } from 'jsx-ast-utils';4import isNonInteractiveElement from '../../../src/util/isNonInteractiveElement';5import {6 genElementSymbol,7 genIndeterminantInteractiveElements,8 genInteractiveElements,9 genInteractiveRoleElements,10 genNonInteractiveElements,11 genNonInteractiveRoleElements,12} from '../../../__mocks__/genInteractives';13describe('isNonInteractiveElement', () => {14 describe('JSX Components (no tagName)', () => {15 it('should identify them as interactive elements', () => {16 expect(isNonInteractiveElement(undefined, []))17 .toBe(false);18 });19 });20 describe('non-interactive elements', () => {21 genNonInteractiveElements().forEach(({ openingElement }) => {22 it(`should identify \`${genElementSymbol(openingElement)}\` as a non-interactive element`, () => {23 expect(isNonInteractiveElement(24 elementType(openingElement),25 openingElement.attributes,26 )).toBe(true);27 });28 });29 });30 describe('non-interactive role elements', () => {31 genNonInteractiveRoleElements().forEach(({ openingElement }) => {32 it(`should NOT identify \`${genElementSymbol(openingElement)}\` as a non-interactive element`, () => {33 expect(isNonInteractiveElement(34 elementType(openingElement),35 openingElement.attributes,36 )).toBe(false);37 });38 });39 });40 describe('interactive elements', () => {41 genInteractiveElements().forEach(({ openingElement }) => {42 it(`should NOT identify \`${genElementSymbol(openingElement)}\` as a non-interactive element`, () => {43 expect(isNonInteractiveElement(44 elementType(openingElement),45 openingElement.attributes,46 )).toBe(false);47 });48 });49 });50 describe('interactive role elements', () => {51 genInteractiveRoleElements().forEach(({ openingElement }) => {52 it(`should NOT identify \`${genElementSymbol(openingElement)}\` as a non-interactive element`, () => {53 expect(isNonInteractiveElement(54 elementType(openingElement),55 openingElement.attributes,56 )).toBe(false);57 });58 });59 });60 describe('indeterminate elements', () => {61 genIndeterminantInteractiveElements().forEach(({ openingElement }) => {62 it(`should NOT identify \`${openingElement.name.name}\` as a non-interactive element`, () => {63 expect(isNonInteractiveElement(64 elementType(openingElement),65 openingElement.attributes,66 )).toBe(false);67 });68 });69 });...
opening-times-reducer.test.js
Source:opening-times-reducer.test.js
1import { rootReducer } from 'redux/root-reducer';2import { describe } from 'riteway';3import {4 getOpeningTimes,5 isOpenToday,6 reducer,7 setOpeningTimes,8} from './opening-times-reducer';9const createState = ({ openingTimes = [] } = {}) => openingTimes;10describe('opening times reducer', async assert => {11 assert({12 given: 'no state',13 should: 'return the valid initial state',14 actual: reducer(undefined, {}),15 expected: createState(),16 });17 {18 const openingTimes = [{ id: 1 }];19 assert({20 given: 'no state and a set opeting times action',21 should: 'set the opening time',22 actual: reducer(undefined, setOpeningTimes(openingTimes)),23 expected: createState({ openingTimes }),24 });25 }26 {27 const openingTimes = [{ id: 1 }];28 const state = createState();29 assert({30 given: 'state and a set opeting times action',31 should: 'set the opening time',32 actual: reducer(state, setOpeningTimes(openingTimes)),33 expected: createState({ openingTimes }),34 });35 }36 assert({37 given: 'no state and a get opening times selector',38 should: 'return the opening times',39 actual: getOpeningTimes(rootReducer(undefined, {})),40 expected: [],41 });42 assert({43 given: 'state and a get opening times seletor',44 should: 'return the opening times',45 actual: getOpeningTimes(46 rootReducer(undefined, setOpeningTimes([{ id: 1 }])),47 ),48 expected: [{ id: 1 }],49 });50 {51 assert({52 given: 'state and a is open today selector',53 should: 'return false',54 actual: isOpenToday(rootReducer(undefined, {})),55 expected: false,56 });57 }58 {59 const openingTimes = [60 { isOpen: false, day: 'sunday', openAt: '10:00', closeAt: '22:00' },61 { day: 'monday', openAt: '10:00', closeAt: '22:00' },62 ];63 assert({64 given: 'state and a is open today selector',65 should: 'return false',66 actual: isOpenToday(67 rootReducer(undefined, setOpeningTimes(openingTimes)),68 ),69 expected: false,70 });71 }72 {73 const openingTimes = [74 { isOpen: true, day: 'sunday', openAt: '10:00', closeAt: '22:00' },75 { day: 'monday', openAt: '10:00', closeAt: '22:00' },76 ];77 assert({78 given: 'state and a is open today selector',79 should: 'return false',80 actual: isOpenToday(81 rootReducer(undefined, setOpeningTimes(openingTimes)),82 ),83 expected: true,84 });85 }...
Using AI Code Generation
1import { storiesOf } from '@storybook/react';2import { action } from '@storybook/addon-actions';3import { linkTo } from '@storybook/addon-links';4import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';5import { withInfo } from '@storybook/addon-info';6import { withReadme } from 'storybook-readme';7import { withDocs } from 'storybook-readme';8import readme from './README.md';9storiesOf('Button', module)10 .add('with text', () => (11 <Button onClick={action('clicked')}>Hello Button</Button>12 .add('with some emoji', () => (13 <Button onClick={action('clicked')}>π π π π―</Button>14 ));15import { Button } from 'components';16<Button primary size="large" onClick={handler}>17import { configure } from '@storybook/react';18configure(require.context('../src', true, /\.stories\.js$/), module);19import '@storybook/addon-actions/register';20import '@storybook/addon-links/register';21import '@storybook/addon-knobs/register';22import '@storybook/addon-info/register';23import 'storybook-readme/register';24const path = require('path');25module.exports = (baseConfig, env, defaultConfig) => {26 defaultConfig.module.rules.push({27 loaders: [require.resolve('@storybook/addon-storysource/loader')],28 });29 defaultConfig.module.rules.push({30 test: /\.(ts|tsx)$/,31 include: path.resolve(__dirname, '../'),32 loader: require.resolve('awesome-typescript-loader'),33 });34 defaultConfig.resolve.extensions.push('.ts', '.tsx');
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';4import { action } from '@storybook/addon-actions';5import { linkTo } from '@storybook/addon-links';6import { Button, Welcome } from '@storybook/react/demo';7storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);8storiesOf('Button', module)9 .addDecorator(withKnobs)10 .add('with text', () => (11 <Button onClick={action('clicked')}>12 {text('Label', 'Hello Storybook')}13 .add('with some emoji', () => (14 <Button onClick={action('clicked')}>15 {text('Label', 'π π π π―')}16 .add('with some emoji and action', () => (17 <Button onClick={action('clicked')}>18 {text('Label', 'π π π π―')}19 .add('with some emoji and action', () => (20 <Button onClick={action('clicked')}>21 {text('Label', 'π π π π―')}22 .add('with some emoji and action', () => (23 <Button onClick={action('clicked')}>24 {text('Label', 'π π π π―')}25 .add('with some emoji and action', () => (26 <Button onClick={action('clicked')}>27 {text('Label', 'π π π π―')}28 .add('with some emoji and action', () => (29 <Button onClick={action('clicked')}>30 {text('Label', 'π π π π―')}31 .add('with some emoji and action', () => (32 <Button onClick={action('clicked')}>33 {text('Label', 'π π π π―')}34 .add('with some emoji and action', () => (35 <Button onClick={action('clicked')}>36 {text('Label', 'π π π π―')}
Using AI Code Generation
1import { open } from 'storybook-root'2open('test-story', { name: 'test' })3import { configure } from '@storybook/react'4import { addStorybookRoot } from 'storybook-root'5import { addDecorator } from '@storybook/react'6import { withInfo } from '@storybook/addon-info'7addDecorator(withInfo)8addStorybookRoot({9 props: {10 name: {11 },12 },13})14configure(loadStories, module)15const path = require('path')16module.exports = (baseConfig, env, config) => {17 config.module.rules.push({18 include: path.resolve(__dirname, '../'),19 {20 options: {21 },22 },23 })24}25import React from 'react'26import { addDecorator } from '@storybook/react'27import { withInfo } from '@storybook/addon-info'28addDecorator(withInfo)29import '@storybook/addon-actions/register'30import '@storybook/addon-links/register'31import 'storybook-root/register'32import { addons } from '@storybook/addons'33import { themes } from '@storybook/theming'34import { create } from '@storybook/theming/create'35addons.setConfig({36 theme: create({
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!!