How to use relative method in storybook-root

Best JavaScript code snippet using storybook-root

relative.js

Source:relative.js Github

copy

Full Screen

1goog.provide('goog.date.relative'); 2goog.require('goog.i18n.DateTimeFormat'); 3goog.date.relative.MINUTE_MS_ = 60000; 4goog.date.relative.DAY_MS_ = 86400000; 5goog.date.relative.Unit_ = { 6 MINUTES: 0, 7 HOURS: 1, 8 DAYS: 2 9}; 10goog.date.relative.fullDateFormatter_; 11goog.date.relative.shortTimeFormatter_; 12goog.date.relative.monthDateFormatter_; 13goog.date.relative.formatMonth_ = function(date) { 14 if(! goog.date.relative.monthDateFormatter_) { 15 goog.date.relative.monthDateFormatter_ = new goog.i18n.DateTimeFormat('MMM dd'); 16 } 17 return goog.date.relative.monthDateFormatter_.format(date); 18}; 19goog.date.relative.formatShortTime_ = function(date) { 20 if(! goog.date.relative.shortTimeFormatter_) { 21 goog.date.relative.shortTimeFormatter_ = new goog.i18n.DateTimeFormat(goog.i18n.DateTimeFormat.Format.SHORT_TIME); 22 } 23 return goog.date.relative.shortTimeFormatter_.format(date); 24}; 25goog.date.relative.formatFullDate_ = function(date) { 26 if(! goog.date.relative.fullDateFormatter_) { 27 goog.date.relative.fullDateFormatter_ = new goog.i18n.DateTimeFormat(goog.i18n.DateTimeFormat.Format.FULL_DATE); 28 } 29 return goog.date.relative.fullDateFormatter_.format(date); 30}; 31goog.date.relative.format = function(dateMs) { 32 var now = goog.now(); 33 var delta = Math.floor((now - dateMs) / goog.date.relative.MINUTE_MS_); 34 var future = false; 35 if(delta < 0) { 36 future = true; 37 delta *= - 1; 38 } 39 if(delta < 60) { 40 return goog.date.relative.getMessage_(delta, future, goog.date.relative.Unit_.MINUTES); 41 } else { 42 delta = Math.floor(delta / 60); 43 if(delta < 24) { 44 return goog.date.relative.getMessage_(delta, future, goog.date.relative.Unit_.HOURS); 45 } else { 46 var offset = new Date(goog.now()).getTimezoneOffset() * goog.date.relative.MINUTE_MS_; 47 delta = Math.floor((now + offset) / goog.date.relative.DAY_MS_) - Math.floor((dateMs + offset) / goog.date.relative.DAY_MS_); 48 if(future) { 49 delta *= - 1; 50 } 51 if(delta < 14) { 52 return goog.date.relative.getMessage_(delta, future, goog.date.relative.Unit_.DAYS); 53 } else { 54 return ''; 55 } 56 } 57 } 58}; 59goog.date.relative.formatPast = function(dateMs) { 60 var now = goog.now(); 61 if(now < dateMs) { 62 dateMs = now; 63 } 64 return goog.date.relative.format(dateMs); 65}; 66goog.date.relative.formatDay = function(dateMs) { 67 var message; 68 var today = new Date(goog.now()); 69 today.setHours(0); 70 today.setMinutes(0); 71 today.setSeconds(0); 72 today.setMilliseconds(0); 73 var yesterday = new Date(today.getTime() - goog.date.relative.DAY_MS_); 74 if(today.getTime() < dateMs) { 75 var MSG_TODAY = goog.getMsg('Today'); 76 message = MSG_TODAY; 77 } else if(yesterday.getTime() < dateMs) { 78 var MSG_YESTERDAY = goog.getMsg('Yesterday'); 79 message = MSG_YESTERDAY; 80 } else { 81 message = goog.date.relative.formatMonth_(new Date(dateMs)); 82 } 83 return message; 84}; 85goog.date.relative.getDateString = function(date, opt_shortTimeMsg, opt_fullDateMsg) { 86 return goog.date.relative.getDateString_(date, goog.date.relative.format, opt_shortTimeMsg, opt_fullDateMsg); 87}; 88goog.date.relative.getPastDateString = function(date, opt_shortTimeMsg, opt_fullDateMsg) { 89 return goog.date.relative.getDateString_(date, goog.date.relative.formatPast, opt_shortTimeMsg, opt_fullDateMsg); 90}; 91goog.date.relative.getDateString_ = function(date, relativeFormatter, opt_shortTimeMsg, opt_fullDateMsg) { 92 var dateMs = date.getTime(); 93 var relativeDate = relativeFormatter(dateMs); 94 if(relativeDate) { 95 relativeDate = ' (' + relativeDate + ')'; 96 } 97 var delta = Math.floor((goog.now() - dateMs) / goog.date.relative.MINUTE_MS_); 98 if(delta < 60 * 24) { 99 return(opt_shortTimeMsg || goog.date.relative.formatShortTime_(date)) + relativeDate; 100 } else { 101 return(opt_fullDateMsg || goog.date.relative.formatFullDate_(date)) + relativeDate; 102 } 103}; 104goog.date.relative.getMessage_ = function(delta, future, unit) { 105 if(! future && unit == goog.date.relative.Unit_.MINUTES) { 106 var MSG_MINUTES_AGO_SINGULAR = goog.getMsg('{$num} minute ago', { 'num': delta }); 107 var MSG_MINUTES_AGO_PLURAL = goog.getMsg('{$num} minutes ago', { 'num': delta }); 108 return delta == 1 ? MSG_MINUTES_AGO_SINGULAR: MSG_MINUTES_AGO_PLURAL; 109 } else if(future && unit == goog.date.relative.Unit_.MINUTES) { 110 var MSG_IN_MINUTES_SINGULAR = goog.getMsg('in {$num} minute', { 'num': delta }); 111 var MSG_IN_MINUTES_PLURAL = goog.getMsg('in {$num} minutes', { 'num': delta }); 112 return delta == 1 ? MSG_IN_MINUTES_SINGULAR: MSG_IN_MINUTES_PLURAL; 113 } else if(! future && unit == goog.date.relative.Unit_.HOURS) { 114 var MSG_HOURS_AGO_SINGULAR = goog.getMsg('{$num} hour ago', { 'num': delta }); 115 var MSG_HOURS_AGO_PLURAL = goog.getMsg('{$num} hours ago', { 'num': delta }); 116 return delta == 1 ? MSG_HOURS_AGO_SINGULAR: MSG_HOURS_AGO_PLURAL; 117 } else if(future && unit == goog.date.relative.Unit_.HOURS) { 118 var MSG_IN_HOURS_SINGULAR = goog.getMsg('in {$num} hour', { 'num': delta }); 119 var MSG_IN_HOURS_PLURAL = goog.getMsg('in {$num} hours', { 'num': delta }); 120 return delta == 1 ? MSG_IN_HOURS_SINGULAR: MSG_IN_HOURS_PLURAL; 121 } else if(! future && unit == goog.date.relative.Unit_.DAYS) { 122 var MSG_DAYS_AGO_SINGULAR = goog.getMsg('{$num} day ago', { 'num': delta }); 123 var MSG_DAYS_AGO_PLURAL = goog.getMsg('{$num} days ago', { 'num': delta }); 124 return delta == 1 ? MSG_DAYS_AGO_SINGULAR: MSG_DAYS_AGO_PLURAL; 125 } else if(future && unit == goog.date.relative.Unit_.DAYS) { 126 var MSG_IN_DAYS_SINGULAR = goog.getMsg('in {$num} day', { 'num': delta }); 127 var MSG_IN_DAYS_PLURAL = goog.getMsg('in {$num} days', { 'num': delta }); 128 return delta == 1 ? MSG_IN_DAYS_SINGULAR: MSG_IN_DAYS_PLURAL; 129 } else { 130 return ''; 131 } ...

Full Screen

Full Screen

parse-date.js

Source:parse-date.js Github

copy

Full Screen

1const { parseRelativeDate } = require('@/utils/parse-date');2const MockDate = require('mockdate');3describe('parseRelativeDate', () => {4 const second = 1000;5 const minute = 60 * second;6 const hour = 60 * minute;7 const day = 24 * hour;8 const week = 7 * day;9 const month = 30 * day;10 const year = 365 * day;11 const weekday = (d) => +new Date(date.getFullYear(), date.getMonth(), date.getDate() + d - (date.getDay() > d ? date.getDay() : date.getDay() + 7));12 const date = new Date();13 MockDate.set(date);14 it('s秒钟前', () => {15 expect(+new Date(parseRelativeDate('10秒前'))).toBe(+date - 10 * second);16 });17 it('m分钟前', () => {18 expect(+new Date(parseRelativeDate('10分钟前'))).toBe(+date - 10 * minute);19 });20 it('m分鐘前', () => {21 expect(+new Date(parseRelativeDate('10分鐘前'))).toBe(+date - 10 * minute);22 });23 it('m分钟后', () => {24 expect(+new Date(parseRelativeDate('10分钟后'))).toBe(+date + 10 * minute);25 });26 it('a minute ago', () => {27 expect(+new Date(parseRelativeDate('a minute ago'))).toBe(+date - 1 * minute);28 });29 it('s minutes ago', () => {30 expect(+new Date(parseRelativeDate('10 minutes ago'))).toBe(+date - 10 * minute);31 });32 it('s mins ago', () => {33 expect(+new Date(parseRelativeDate('10 mins ago'))).toBe(+date - 10 * minute);34 });35 it('in s minutes', () => {36 expect(+new Date(parseRelativeDate('in 10 minutes'))).toBe(+date + 10 * minute);37 });38 it('in an hour', () => {39 expect(+new Date(parseRelativeDate('in an hour'))).toBe(+date + 1 * hour);40 });41 it('H小时前', () => {42 expect(+new Date(parseRelativeDate('10小时前'))).toBe(+date - 10 * hour);43 });44 it('H个小时前', () => {45 expect(+new Date(parseRelativeDate('10个小时前'))).toBe(+date - 10 * hour);46 });47 it('D天前', () => {48 expect(+new Date(parseRelativeDate('10天前'))).toBe(+date - 10 * day);49 });50 it('W周前', () => {51 expect(+new Date(parseRelativeDate('10周前'))).toBe(+date - 10 * week);52 });53 it('W星期前', () => {54 expect(+new Date(parseRelativeDate('10星期前'))).toBe(+date - 10 * week);55 });56 it('W个星期前', () => {57 expect(+new Date(parseRelativeDate('10个星期前'))).toBe(+date - 10 * week);58 });59 it('M月前', () => {60 expect(+new Date(parseRelativeDate('1月前'))).toBe(+date - 1 * month);61 });62 it('M个月前', () => {63 expect(+new Date(parseRelativeDate('1个月前'))).toBe(+date - 1 * month);64 });65 it('Y年前', () => {66 expect(+new Date(parseRelativeDate('1年前'))).toBe(+date - 1 * year);67 });68 it('Y年M个月前', () => {69 expect(+new Date(parseRelativeDate('1年1个月前'))).toBe(+date - 1 * year - 1 * month);70 });71 it('D天H小时前', () => {72 expect(+new Date(parseRelativeDate('1天1小时前'))).toBe(+date - 1 * day - 1 * hour);73 });74 it('H小时m分钟s秒钟前', () => {75 expect(+new Date(parseRelativeDate('1小时1分钟1秒钟前'))).toBe(+date - 1 * hour - 1 * minute - 1 * second);76 });77 it('H小时m分钟s秒钟后', () => {78 expect(+new Date(parseRelativeDate('1小时1分钟1秒钟后'))).toBe(+date + 1 * hour + 1 * minute + 1 * second);79 });80 it('今天', () => {81 expect(+new Date(parseRelativeDate('今天'))).toBe(+date.setHours(0, 0, 0, 0));82 });83 it('Today H:m', () => {84 expect(+new Date(parseRelativeDate('Today 08:00'))).toBe(+date + 8 * hour);85 });86 it('Today, h:m a', () => {87 expect(+new Date(parseRelativeDate('Today, 8:00 pm'))).toBe(+date + 20 * hour);88 });89 it('TDA H:m:s', () => {90 expect(+new Date(parseRelativeDate('TDA 08:00:00'))).toBe(+date + 8 * hour);91 });92 it('今天 H:m', () => {93 expect(+new Date(parseRelativeDate('今天 08:00'))).toBe(+date + 8 * hour);94 });95 it('今天H点m分', () => {96 expect(+new Date(parseRelativeDate('今天8点0分'))).toBe(+date + 8 * hour);97 });98 it('昨日H点m分s秒', () => {99 expect(+new Date(parseRelativeDate('昨日20时0分0秒'))).toBe(+date - 4 * hour);100 });101 it('前天 H:m', () => {102 expect(+new Date(parseRelativeDate('前天 20:00'))).toBe(+date - 1 * day - 4 * hour);103 });104 it('明天 H:m', () => {105 expect(+new Date(parseRelativeDate('明天 20:00'))).toBe(+date + 1 * day + 20 * hour);106 });107 it('星期几 h:m', () => {108 expect(+new Date(parseRelativeDate('星期一 8:00'))).toBe(weekday(1) + 8 * hour);109 });110 it('周几 h:m', () => {111 expect(+new Date(parseRelativeDate('周二 8:00'))).toBe(weekday(2) + 8 * hour);112 });113 it('星期天 h:m', () => {114 expect(+new Date(parseRelativeDate('星期天 8:00'))).toBe(weekday(7) + 8 * hour);115 });116 it('Invalid', () => {117 expect(parseRelativeDate('RSSHub')).toBe('RSSHub');118 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from '@storybook/react';2import { action } from '@storybook/addon-actions';3storiesOf('Button', module)4 .add('with text', () => (5 <Button onClick={action('clicked')}>Hello Button</Button>6 .add('with some emoji', () => (7 <Button onClick={action('clicked')}>8 ));9{10 "scripts": {11 },12 "devDependencies": {13 },14 "dependencies": {15 }16}17import { configure } from '@storybook/react';18const req = require.context('../src', true, /.stories.js$/);19function loadStories() {20 req.keys().forEach(filename => req(filename));21}22configure(loadStories, module);23import '@storybook/addon-actions/register';24const path = require('path

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from '@storybook/react';2import { withKnobs, text } from '@storybook/addon-knobs';3import Component from './Component';4storiesOf('Component', module)5 .addDecorator(withKnobs)6 .add('Component', () => (7 text={text('Text', 'Hello')}8 ));9import { storiesOf } from '@storybook/react';10import { withKnobs, text } from '@storybook/addon-knobs';11import Component from './Component';12storiesOf('Component', module)13 .addDecorator(withKnobs)14 .add('Component', () => (15 text={text('Text', 'Hello')}16 ));

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root/src'2storiesOf('Button', module)3 .add('with text', () => (4 <Button onClick={action('clicked')}>Hello Button</Button>5 .add('with some emoji', () => (6 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>7 ));8import { storiesOf } from 'storybook-root/src'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 ));15MIT © [mikechabot](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure } from '@storybook/react';2import { setOptions } from '@storybook/addon-options';3import { setDefaults } from 'storybook-addon-jsx';4import { addDecorator } from '@storybook/react';5import { withOptions } from '@storybook/addon-options';6import { withInfo } from '@storybook/addon-info';7import { withKnobs } from '@storybook/addon-knobs';8import { setDefaults as setAddonInfoDefaults } from '@storybook/addon-info';9import { withA11y } from '@storybook/addon-a11y';10import { withTests } from '@storybook/addon-jest';11import results from '../.jest-test-results.json';12import './test.scss';13configure(require.context('../src', true, /\.stories\.js$/), module);14setAddonInfoDefaults({15});16addDecorator(withKnobs);17addDecorator(withTests({ results }));18addDecorator(withInfo);19addDecorator(withA11y);20addDecorator(21 withOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withKnobs, text } from '@storybook/addon-knobs';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import React from 'react';5import MyComponent from 'src/components/MyComponent';6storiesOf('MyComponent', module)7 .addDecorator(withKnobs)8 .add('with some emoji', () => (9 <MyComponent>{text('Label', '😀 😎 👍 💯')}</MyComponent>10 ));11import React from 'react';12import PropTypes from 'prop-types';13const MyComponent = ({ children }) => <div>{children}</div>;14MyComponent.propTypes = {15};16export default MyComponent;17"babel": {18 }19{20}21import '../src/index.css';22import '@storybook/addon-knobs/register';23module.exports = (baseConfig, env, config) => {24 config.module.rules.push({25 include: path.resolve(__dirname, '../'),26 });27 return config;28};29module.exports = (baseConfig, env, config) => {30 config.module.rules.push({31 include: path.resolve(__dirname, '../'),32 });33 return config;34};35module.exports = (baseConfig, env, config) => {36 config.module.rules.push({37 include: path.resolve(__dirname, '../'),38 });39 return config;40};41module.exports = (baseConfig, env, config) => {42 config.module.rules.push({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root';2storiesOf('my story', module)3 .add('story 1', () => <div>hello</div>)4 .add('story 2', () => <div>hello</div>);5import { configure } from '@storybook/react';6configure(() => {7 require('storybook-root/test.js');8}, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = require('storybook-root');2module.exports = root(__dirname, '.storybook/webpack.config');3const path = require('path');4module.exports = (baseConfig, env, defaultConfig) => {5 defaultConfig.module.rules.push({6 include: path.resolve(__dirname, '../')7 });8 return defaultConfig;9};10import './Button.scss';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root';2storiesOf('some story', module)3 .add('some example', () => <div>some example</div>);4import { configure } from '@storybook/react';5import 'storybook-root/register';6configure(() => {7 require('test.js');8}, module);

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