Best JavaScript code snippet using storybook-root
jsx-tag-spacing.js
Source:jsx-tag-spacing.js
1/**2 * @fileoverview Validates whitespace in and around the JSX opening and closing brackets3 * @author Diogo Franco (Kovensky)4 */5'use strict';6const getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket');7const docsUrl = require('../util/docsUrl');8// ------------------------------------------------------------------------------9// Validators10// ------------------------------------------------------------------------------11function validateClosingSlash(context, node, option) {12 const sourceCode = context.getSourceCode();13 const SELF_CLOSING_NEVER_MESSAGE = 'Whitespace is forbidden between `/` and `>`; write `/>`';14 const SELF_CLOSING_ALWAYS_MESSAGE = 'Whitespace is required between `/` and `>`; write `/ >`';15 const NEVER_MESSAGE = 'Whitespace is forbidden between `<` and `/`; write `</`';16 const ALWAYS_MESSAGE = 'Whitespace is required between `<` and `/`; write `< /`';17 let adjacent;18 if (node.selfClosing) {19 const lastTokens = sourceCode.getLastTokens(node, 2);20 adjacent = !sourceCode.isSpaceBetweenTokens(lastTokens[0], lastTokens[1]);21 if (option === 'never') {22 if (!adjacent) {23 context.report({24 node,25 loc: {26 start: lastTokens[0].loc.start,27 end: lastTokens[1].loc.end28 },29 message: SELF_CLOSING_NEVER_MESSAGE,30 fix(fixer) {31 return fixer.removeRange([lastTokens[0].range[1], lastTokens[1].range[0]]);32 }33 });34 }35 } else if (option === 'always' && adjacent) {36 context.report({37 node,38 loc: {39 start: lastTokens[0].loc.start,40 end: lastTokens[1].loc.end41 },42 message: SELF_CLOSING_ALWAYS_MESSAGE,43 fix(fixer) {44 return fixer.insertTextBefore(lastTokens[1], ' ');45 }46 });47 }48 } else {49 const firstTokens = sourceCode.getFirstTokens(node, 2);50 adjacent = !sourceCode.isSpaceBetweenTokens(firstTokens[0], firstTokens[1]);51 if (option === 'never') {52 if (!adjacent) {53 context.report({54 node,55 loc: {56 start: firstTokens[0].loc.start,57 end: firstTokens[1].loc.end58 },59 message: NEVER_MESSAGE,60 fix(fixer) {61 return fixer.removeRange([firstTokens[0].range[1], firstTokens[1].range[0]]);62 }63 });64 }65 } else if (option === 'always' && adjacent) {66 context.report({67 node,68 loc: {69 start: firstTokens[0].loc.start,70 end: firstTokens[1].loc.end71 },72 message: ALWAYS_MESSAGE,73 fix(fixer) {74 return fixer.insertTextBefore(firstTokens[1], ' ');75 }76 });77 }78 }79}80function validateBeforeSelfClosing(context, node, option) {81 const sourceCode = context.getSourceCode();82 const NEVER_MESSAGE = 'A space is forbidden before closing bracket';83 const ALWAYS_MESSAGE = 'A space is required before closing bracket';84 const leftToken = getTokenBeforeClosingBracket(node);85 const closingSlash = sourceCode.getTokenAfter(leftToken);86 if (leftToken.loc.end.line !== closingSlash.loc.start.line) {87 return;88 }89 if (option === 'always' && !sourceCode.isSpaceBetweenTokens(leftToken, closingSlash)) {90 context.report({91 node,92 loc: closingSlash.loc.start,93 message: ALWAYS_MESSAGE,94 fix(fixer) {95 return fixer.insertTextBefore(closingSlash, ' ');96 }97 });98 } else if (option === 'never' && sourceCode.isSpaceBetweenTokens(leftToken, closingSlash)) {99 context.report({100 node,101 loc: closingSlash.loc.start,102 message: NEVER_MESSAGE,103 fix(fixer) {104 const previousToken = sourceCode.getTokenBefore(closingSlash);105 return fixer.removeRange([previousToken.range[1], closingSlash.range[0]]);106 }107 });108 }109}110function validateAfterOpening(context, node, option) {111 const sourceCode = context.getSourceCode();112 const NEVER_MESSAGE = 'A space is forbidden after opening bracket';113 const ALWAYS_MESSAGE = 'A space is required after opening bracket';114 const openingToken = sourceCode.getTokenBefore(node.name);115 if (option === 'allow-multiline') {116 if (openingToken.loc.start.line !== node.name.loc.start.line) {117 return;118 }119 }120 const adjacent = !sourceCode.isSpaceBetweenTokens(openingToken, node.name);121 if (option === 'never' || option === 'allow-multiline') {122 if (!adjacent) {123 context.report({124 node,125 loc: {126 start: openingToken.loc.start,127 end: node.name.loc.start128 },129 message: NEVER_MESSAGE,130 fix(fixer) {131 return fixer.removeRange([openingToken.range[1], node.name.range[0]]);132 }133 });134 }135 } else if (option === 'always' && adjacent) {136 context.report({137 node,138 loc: {139 start: openingToken.loc.start,140 end: node.name.loc.start141 },142 message: ALWAYS_MESSAGE,143 fix(fixer) {144 return fixer.insertTextBefore(node.name, ' ');145 }146 });147 }148}149function validateBeforeClosing(context, node, option) {150 // Don't enforce this rule for self closing tags151 if (!node.selfClosing) {152 const sourceCode = context.getSourceCode();153 const NEVER_MESSAGE = 'A space is forbidden before closing bracket';154 const ALWAYS_MESSAGE = 'Whitespace is required before closing bracket';155 const lastTokens = sourceCode.getLastTokens(node, 2);156 const closingToken = lastTokens[1];157 const leftToken = lastTokens[0];158 if (leftToken.loc.start.line !== closingToken.loc.start.line) {159 return;160 }161 const adjacent = !sourceCode.isSpaceBetweenTokens(leftToken, closingToken);162 if (option === 'never' && !adjacent) {163 context.report({164 node,165 loc: {166 start: leftToken.loc.end,167 end: closingToken.loc.start168 },169 message: NEVER_MESSAGE,170 fix(fixer) {171 return fixer.removeRange([leftToken.range[1], closingToken.range[0]]);172 }173 });174 } else if (option === 'always' && adjacent) {175 context.report({176 node,177 loc: {178 start: leftToken.loc.end,179 end: closingToken.loc.start180 },181 message: ALWAYS_MESSAGE,182 fix(fixer) {183 return fixer.insertTextBefore(closingToken, ' ');184 }185 });186 }187 }188}189// ------------------------------------------------------------------------------190// Rule Definition191// ------------------------------------------------------------------------------192const optionDefaults = {193 closingSlash: 'never',194 beforeSelfClosing: 'always',195 afterOpening: 'never',196 beforeClosing: 'allow'197};198module.exports = {199 meta: {200 docs: {201 description: 'Validate whitespace in and around the JSX opening and closing brackets',202 category: 'Stylistic Issues',203 recommended: false,204 url: docsUrl('jsx-tag-spacing')205 },206 fixable: 'whitespace',207 schema: [208 {209 type: 'object',210 properties: {211 closingSlash: {212 enum: ['always', 'never', 'allow']213 },214 beforeSelfClosing: {215 enum: ['always', 'never', 'allow']216 },217 afterOpening: {218 enum: ['always', 'allow-multiline', 'never', 'allow']219 },220 beforeClosing: {221 enum: ['always', 'never', 'allow']222 }223 },224 default: optionDefaults,225 additionalProperties: false226 }227 ]228 },229 create(context) {230 const options = Object.assign({}, optionDefaults, context.options[0]);231 return {232 JSXOpeningElement(node) {233 if (options.closingSlash !== 'allow' && node.selfClosing) {234 validateClosingSlash(context, node, options.closingSlash);235 }236 if (options.afterOpening !== 'allow') {237 validateAfterOpening(context, node, options.afterOpening);238 }239 if (options.beforeSelfClosing !== 'allow' && node.selfClosing) {240 validateBeforeSelfClosing(context, node, options.beforeSelfClosing);241 }242 if (options.beforeClosing !== 'allow') {243 validateBeforeClosing(context, node, options.beforeClosing);244 }245 },246 JSXClosingElement(node) {247 if (options.afterOpening !== 'allow') {248 validateAfterOpening(context, node, options.afterOpening);249 }250 if (options.closingSlash !== 'allow') {251 validateClosingSlash(context, node, options.closingSlash);252 }253 if (options.beforeClosing !== 'allow') {254 validateBeforeClosing(context, node, options.beforeClosing);255 }256 }257 };258 }...
browser_multiselect_tabs_close_tabs_to_the_right.js
Source:browser_multiselect_tabs_close_tabs_to_the_right.js
1const PREF_WARN_ON_CLOSE = "browser.tabs.warnOnCloseOtherTabs";2add_task(async function setPref() {3 await SpecialPowers.pushPrefEnv({4 set: [[PREF_WARN_ON_CLOSE, false]],5 });6});7add_task(async function withAMultiSelectedTab() {8 let tab1 = await addTab();9 let tab2 = await addTab();10 let tab3 = await addTab();11 let tab4 = await addTab();12 let tab5 = await addTab();13 is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");14 await BrowserTestUtils.switchTab(gBrowser, tab1);15 await triggerClickOn(tab3, { ctrlKey: true });16 ok(tab1.multiselected, "Tab1 is multiselected");17 ok(!tab2.multiselected, "Tab2 is not multiselected");18 ok(tab3.multiselected, "Tab3 is multiselected");19 ok(!tab4.multiselected, "Tab4 is not multiselected");20 ok(!tab5.multiselected, "Tab5 is not multiselected");21 is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");22 // Tab2 will be closed because tab1 is the contextTab.23 let closingTabs = [tab2, tab4, tab5];24 let tabClosingPromises = [];25 for (let tab of closingTabs) {26 tabClosingPromises.push(BrowserTestUtils.waitForTabClosing(tab));27 }28 gBrowser.removeTabsToTheEndFrom(tab1);29 for (let promise of tabClosingPromises) {30 await promise;31 }32 ok(!tab1.closing, "Tab1 is not closing");33 ok(tab2.closing, "Tab2 is closing");34 ok(!tab3.closing, "Tab3 is not closing");35 ok(tab4.closing, "Tab4 is closing");36 ok(tab5.closing, "Tab5 is closing");37 is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");38 for (let tab of [tab1, tab2, tab3]) {39 BrowserTestUtils.removeTab(tab);40 }41});42add_task(async function withNotAMultiSelectedTab() {43 let tab1 = await addTab();44 let tab2 = await addTab();45 let tab3 = await addTab();46 let tab4 = await addTab();47 let tab5 = await addTab();48 is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");49 await BrowserTestUtils.switchTab(gBrowser, tab1);50 await triggerClickOn(tab3, { ctrlKey: true });51 await triggerClickOn(tab5, { ctrlKey: true });52 ok(tab1.multiselected, "Tab1 is multiselected");53 ok(!tab2.multiselected, "Tab2 is not multiselected");54 ok(tab3.multiselected, "Tab3 is multiselected");55 ok(!tab4.multiselected, "Tab4 is not multiselected");56 ok(tab5.multiselected, "Tab5 is multiselected");57 is(gBrowser.multiSelectedTabsCount, 3, "Three multiselected tabs");58 let closingTabs = [tab5];59 let tabClosingPromises = [];60 for (let tab of closingTabs) {61 tabClosingPromises.push(BrowserTestUtils.waitForTabClosing(tab));62 }63 gBrowser.removeTabsToTheEndFrom(tab4);64 for (let promise of tabClosingPromises) {65 await promise;66 }67 ok(!tab1.closing, "Tab1 is not closing");68 ok(!tab2.closing, "Tab2 is not closing");69 ok(!tab3.closing, "Tab3 is not closing");70 ok(!tab4.closing, "Tab4 is not closing");71 ok(tab5.closing, "Tab5 is closing");72 is(gBrowser.multiSelectedTabsCount, 2, "Selection is not cleared");73 closingTabs = [tab3, tab4];74 tabClosingPromises = [];75 for (let tab of closingTabs) {76 tabClosingPromises.push(BrowserTestUtils.waitForTabClosing(tab));77 }78 gBrowser.removeTabsToTheEndFrom(tab2);79 for (let promise of tabClosingPromises) {80 await promise;81 }82 ok(!tab1.closing, "Tab1 is not closing");83 ok(!tab2.closing, "Tab2 is not closing");84 ok(tab3.closing, "Tab3 is closing");85 ok(tab4.closing, "Tab4 is closing");86 is(gBrowser.multiSelectedTabsCount, 0, "Selection is cleared");87 for (let tab of [tab1, tab2]) {88 BrowserTestUtils.removeTab(tab);89 }...
Using AI Code Generation
1import { configure, addDecorator } from '@storybook/react';2import { withOptions } from '@storybook/addon-options';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { withA11y } from '@storybook/addon-a11y';6import { withTests } from '@storybook/addon-jest';7import results from '../.jest-test-results.json';8import { withThemesProvider } from 'storybook-addon-styled-component-theme';9import { theme } from '../src/theme';10import { withConsole } from '@storybook/addon-console';11const req = require.context('../src/components', true, /\.stories\.js$/);12function loadStories() {13 req.keys().forEach(filename => req(filename));14}15addDecorator(16 withOptions({
Using AI Code Generation
1import {root} from 'storybook-root';2root.close();3import {root} from 'storybook-root';4root.open();5import {root} from 'storybook-root';6root.toggle();7import {root} from 'storybook-root';8root.close();9import {root} from 'storybook-root';10root.open();11import {root} from 'storybook-root';12root.toggle();13import {root} from 'storybook-root';14root.close();15import {root} from 'storybook-root';16root.open();17import {root} from 'storybook-root';18root.toggle();19import {root} from 'storybook-root';20root.close();21import {root} from 'storybook-root';22root.open();23import {root} from 'storybook-root';24root.toggle();25import {root} from 'storybook-root';26root.close();27import {root} from 'storybook-root';28root.open();29import {root} from 'storybook-root';30root.toggle();31import {root} from 'storybook-root';32root.close();33import {root} from 'storybook-root';34root.open();35import {root} from 'storybook-root';36root.toggle();37import {root} from 'storybook-root';38root.close();39import {root} from 'storybook-root';40root.open();41import {root
Using AI Code Generation
1const storybookRoot = document.getElementById('storybook-root');2storybookRoot.close();3const storybookPreviewIframe = document.getElementById('storybook-preview-iframe');4storybookPreviewIframe.close();5const storybookPreviewWrapper = document.getElementById('storybook-preview-wrapper');6storybookPreviewWrapper.close();7const storybookPreviewBackground = document.getElementById('storybook-preview-background');8storybookPreviewBackground.close();9const storybookPreview = document.getElementById('storybook-preview');10storybookPreview.close();
Using AI Code Generation
1import { configure } from '@storybook/react';2function loadStories() {3 require('../stories/index.js');4}5configure(loadStories, module);6import { configure } from '@storybook/react';7const req = require.context('../stories', true, /.stories.js$/);8function loadStories() {9 req.keys().forEach(filename => req(filename));10}11configure(loadStories, module);12module.exports = ({ config }) => {13 config.module.rules.push({14 loaders: [require.resolve('@storybook/source-loader')],15 });16 return config;17};18import { configure } from '@storybook/react';19const req = require.context('../stories', true, /.stories.js$/);20function loadStories() {21 req.keys().forEach(filename => req(filename));22}23configure(loadStories, module);24import React from 'react';25import { storiesOf } from '@storybook/react';26import { action } from '@storybook/addon-actions';27import { Button } from '@storybook/react/demo';28storiesOf('Button', module)29 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)30 .add('with some emoji', () => (31 <Button onClick={action('clicked')}>32 ));33{34 "scripts": {35 },
Using AI Code Generation
1export const close = () => {2 document.querySelector('storybook-root').shadowRoot.querySelector('sb-aside').shadowRoot.querySelector('sb-aside-panel').shadowRoot.querySelector('sb-aside-panel-header').shadowRoot.querySelector('sb-aside-panel-header-tools').shadowRoot.querySelector('sb-icon-button').click()3}4import { close } from '../../test.js'5describe('test', () => {6 it('should close the side panel', () => {7 cy.visit('localhost:6006')8 cy.get('sb-aside').should('be.visible')9 close()10 cy.get('sb-aside').should('not.be.visible')11 })12})
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!!