How to use currentProps method in storybook-root

Best JavaScript code snippet using storybook-root

DependentEntityList.test.js

Source:DependentEntityList.test.js Github

copy

Full Screen

1import React from 'react';2import { mount, shallow } from 'enzyme';3import { BrowserRouter } from 'react-router-dom';4import { DependentEntityList } from '../DependentEntityList';5describe('DependentEntityList', () => {6 afterEach(() => {7 jest.clearAllMocks();8 jest.restoreAllMocks();9 });10 const props = {11 location: { pathname: '/notes/' },12 match: { params: { customerId: 2 } },13 isModalOpen: false,14 openModal: () => () => {},15 showAlert: () => {},16 closeAlert: () => {},17 onClickModalCancelButton: () => {},18 onClickModalDeleteButton: () => () => {},19 history: {},20 entityProps: {21 name: 'note',22 service: {23 getByCustomerId: () => Promise.resolve([{}]),24 },25 listTitle: 'Notes',26 idName: 'noteId',27 columns: [28 { name: 'noteText', displayName: 'Note' },29 { name: 'actions', displayName: 'Actions' },30 ],31 },32 };33 it('should render a spinner', () => {34 const wrapper = shallow(<DependentEntityList {...props} />);35 expect(wrapper.find('Spinner').length).toBe(1);36 });37 it('should render an entity table', async () => {38 const wrapper = shallow(<DependentEntityList {...props} />);39 await wrapper.update();40 expect(wrapper.find('Table').length).toBe(1);41 });42 it('should render a correct title', async () => {43 const wrapper = shallow(<DependentEntityList {...props} />);44 await wrapper.update();45 expect(wrapper.find('h2').text()).toBe('Notes');46 wrapper.setProps({ location: { pathname: '/notes/', state: 'Bob Smith' } });47 expect(wrapper.find('h2').text()).toBe('Notes for customer Bob Smith');48 });49 it('should render an alert', async () => {50 const currentProps = {51 ...props,52 message: 'Error',53 };54 const wrapper = shallow(<DependentEntityList {...currentProps} />);55 await wrapper.update();56 expect(wrapper.find('Alert').length).toBe(1);57 });58 it('should call showAlert for a message from server', async () => {59 const getByCustomerIdMock = () =>60 Promise.resolve({ error: true, errorTitle: 'Test' });61 const showAlertMock = jest.fn(() => {});62 const currentProps = { ...props, showAlert: showAlertMock };63 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;64 const wrapper = shallow(<DependentEntityList {...currentProps} />);65 await wrapper.update();66 expect(showAlertMock).toHaveBeenCalledTimes(1);67 expect(showAlertMock).toBeCalledWith('Test', 'error');68 });69 it('should call showAlert for an invalid customerId', async () => {70 const showAlertMock = jest.fn(() => {});71 const currentProps = {72 ...props,73 showAlert: showAlertMock,74 match: { params: { customerId: 'id' } },75 };76 const wrapper = shallow(<DependentEntityList {...currentProps} />);77 await wrapper.update();78 expect(showAlertMock).toHaveBeenCalledTimes(1);79 expect(showAlertMock).toBeCalledWith('Customer is not found.', 'error');80 });81 it('should render an delete modal', async () => {82 const currentProps = {83 ...props,84 isModalOpen: true,85 };86 const wrapper = shallow(<DependentEntityList {...currentProps} />);87 await wrapper.update();88 expect(wrapper.find('Modal').length).toBe(1);89 });90 it('should render a create customer link', async () => {91 const wrapper = shallow(<DependentEntityList {...props} />);92 await wrapper.update();93 expect(wrapper.find('PrimaryLink').props().to).toBe('/notes/create/');94 });95 it('should set state for empty response', async () => {96 const getByCustomerIdMock = jest.fn(() => Promise.resolve());97 const currentProps = { ...props };98 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;99 const wrapper = shallow(<DependentEntityList {...currentProps} />);100 await wrapper.update();101 expect(wrapper.instance().state).toStrictEqual({102 entities: [],103 isLoading: false,104 isLoaded: true,105 });106 expect(getByCustomerIdMock).toHaveBeenCalledTimes(1);107 });108 it('should set state for response with data', async () => {109 const getByCustomerIdMock = jest.fn(() =>110 Promise.resolve([{ noteId: 1, customerId: 2, noteText: 'Note1' }])111 );112 const currentProps = { ...props };113 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;114 const wrapper = shallow(<DependentEntityList {...currentProps} />);115 await wrapper.update();116 expect(wrapper.instance().state).toStrictEqual({117 entities: [{ noteId: 1, customerId: 2, noteText: 'Note1' }],118 isLoading: false,119 isLoaded: true,120 });121 expect(getByCustomerIdMock).toHaveBeenCalledTimes(1);122 });123 it('should set state for response with error', async () => {124 const getByCustomerIdMock = jest.fn(() =>125 Promise.resolve({ error: true, errorTitle: 'Test' })126 );127 const showAlertMock = jest.fn(() => {});128 const currentProps = { ...props, showAlert: showAlertMock };129 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;130 const wrapper = shallow(<DependentEntityList {...currentProps} />);131 await wrapper.update();132 expect(wrapper.instance().state).toStrictEqual({133 entities: [],134 isLoading: false,135 isLoaded: true,136 });137 expect(getByCustomerIdMock).toHaveBeenCalledTimes(1);138 expect(showAlertMock).toHaveBeenCalledTimes(1);139 });140 it('should call close alert message and getByCustomerId method on update', async () => {141 const getByCustomerIdMock = jest.fn(() => Promise.resolve());142 const closeAlertMock = jest.fn(() => {});143 const currentProps = { ...props, closeAlert: closeAlertMock };144 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;145 const wrapper = shallow(<DependentEntityList {...currentProps} />);146 await wrapper.update();147 wrapper.instance().state.isLoaded = false;148 wrapper.instance().state.isLoading = false;149 wrapper.setProps({});150 expect(closeAlertMock).toHaveBeenCalledTimes(1);151 expect(getByCustomerIdMock).toHaveBeenCalledTimes(2);152 });153 it('should not call close alert message and getByCustomerId method on update if isLoaded is true', async () => {154 const getByCustomerIdMock = jest.fn(() => Promise.resolve());155 const closeAlertMock = jest.fn(() => {});156 const currentProps = { ...props, closeAlert: closeAlertMock };157 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;158 const wrapper = shallow(<DependentEntityList {...currentProps} />);159 await wrapper.update();160 wrapper.instance().state.isLoaded = true;161 wrapper.instance().state.isLoading = false;162 wrapper.setProps({});163 expect(closeAlertMock).toHaveBeenCalledTimes(0);164 expect(getByCustomerIdMock).toHaveBeenCalledTimes(1);165 });166 it('should not call close alert message and getByCustomerId method on update if isLoading is true', async () => {167 const getByCustomerIdMock = jest.fn(() => Promise.resolve());168 const closeAlertMock = jest.fn(() => {});169 const currentProps = { ...props, closeAlert: closeAlertMock };170 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;171 const wrapper = shallow(<DependentEntityList {...currentProps} />);172 await wrapper.update();173 wrapper.instance().state.isLoaded = false;174 wrapper.instance().state.isLoading = true;175 wrapper.setProps({});176 expect(closeAlertMock).toHaveBeenCalledTimes(0);177 expect(getByCustomerIdMock).toHaveBeenCalledTimes(1);178 });179 it('should return correct delete modal props', async () => {180 const getByCustomerIdMock = () => Promise.resolve();181 const onClickModalDeleteButtonMock = jest.fn();182 const currentProps = {183 ...props,184 onClickModalDeleteButton: onClickModalDeleteButtonMock,185 };186 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;187 const wrapper = shallow(<DependentEntityList {...currentProps} />);188 await wrapper.update();189 const errorModalProps = wrapper.instance().getDeleteModalProps();190 delete errorModalProps.onAction;191 errorModalProps.onCancel = errorModalProps.onCancel.name;192 expect(errorModalProps).toStrictEqual({193 title: 'Delete note',194 body: 'Are you sure you want to delete this note?',195 cancelButtonLabel: 'Cancel',196 actionButtonLabel: 'Delete',197 onCancel: 'onClickModalCancelButton',198 });199 expect(onClickModalDeleteButtonMock).toHaveBeenCalledTimes(1);200 });201 it('should call goBack on return button click', async () => {202 const goBackMock = jest.fn(() => {});203 const currentProps = {204 ...props,205 match: { params: { customerId: 'id' } },206 history: { goBack: goBackMock },207 };208 const wrapper = mount(209 <BrowserRouter>210 <DependentEntityList {...currentProps} />211 </BrowserRouter>212 );213 await wrapper.update();214 expect(wrapper.find('ButtonLink').text()).toBe('Return to Customers');215 wrapper.find('ButtonLink').simulate('click');216 expect(goBackMock).toHaveBeenCalledTimes(1);217 });218 it('should render correct link for edit', async () => {219 const getByCustomerIdMock = jest.fn(() =>220 Promise.resolve([{ noteId: 1, customerId: 2, noteText: 'Note1' }])221 );222 const currentProps = { ...props };223 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;224 const wrapper = mount(225 <BrowserRouter>226 <DependentEntityList {...props} />227 </BrowserRouter>228 );229 await wrapper.instance().componentDidMount();230 await wrapper.update();231 expect(wrapper.find('PrimaryLink').at(1).text()).toBe('Edit');232 expect(wrapper.find('PrimaryLink').at(1).props().to).toStrictEqual(233 '/notes/edit/1/'234 );235 });236 it('should delete button open a delete modal', async () => {237 const getByCustomerIdMock = () =>238 Promise.resolve([239 { noteId: 1, customerId: 2, noteText: 'Note1' },240 { noteId: 2, customerId: 2, noteText: 'Note2' },241 ]);242 const onClickDeleteButtonMock = jest.fn(() => {});243 const openModalMock = jest.fn(() => onClickDeleteButtonMock);244 const currentProps = { ...props, openModal: openModalMock };245 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;246 const wrapper = mount(247 <BrowserRouter>248 <DependentEntityList {...currentProps} />249 </BrowserRouter>250 );251 await wrapper.instance().componentDidMount();252 await wrapper.update();253 expect(wrapper.find('ButtonLink').at(1).text()).toBe('Delete');254 wrapper.find('ButtonLink').at(1).simulate('click');255 expect(onClickDeleteButtonMock).toHaveBeenCalledTimes(1);256 expect(openModalMock).toHaveBeenCalledTimes(2);257 expect(openModalMock).toBeCalledWith(1);258 });259 it('should not delete button open a delete modal for the last entity', async () => {260 const getByCustomerIdMock = () =>261 Promise.resolve([{ noteId: 1, customerId: 2, noteText: 'Note1' }]);262 const onClickDeleteButtonMock = jest.fn(() => {});263 const openModalMock = jest.fn(() => onClickDeleteButtonMock);264 const currentProps = { ...props, openModal: openModalMock };265 currentProps.entityProps.service.getByCustomerId = getByCustomerIdMock;266 const wrapper = mount(267 <BrowserRouter>268 <DependentEntityList {...currentProps} />269 </BrowserRouter>270 );271 await wrapper.instance().componentDidMount();272 await wrapper.update();273 expect(wrapper.find('ButtonLink').at(1).text()).toBe('Delete');274 wrapper.find('ButtonLink').at(1).simulate('click');275 expect(onClickDeleteButtonMock).toHaveBeenCalledTimes(0);276 expect(openModalMock).toHaveBeenCalledTimes(1);277 expect(openModalMock).toBeCalledWith(1);278 });...

Full Screen

Full Screen

DependentEntityCreateEditForm.test.js

Source:DependentEntityCreateEditForm.test.js Github

copy

Full Screen

1import React from 'react';2import { mount, shallow } from 'enzyme';3import { DependentEntityCreateEditForm } from '../DependentEntityCreateEditForm';4describe('DependentEntityCreateEditForm', () => {5 afterEach(() => {6 jest.clearAllMocks();7 jest.restoreAllMocks();8 });9 let props;10 beforeEach(() => {11 const MockedForm = () => null;12 props = {13 match: { params: { customerId: 2, noteId: 1 } },14 showAlert: () => {},15 closeAlert: () => {},16 onClickCancelButton: () => {},17 onSubmit: () => {},18 entityProps: {19 initialState: { noteText: '', noteId: 0, customerId: 0 },20 formTitle: 'Note Form',21 idName: 'noteId',22 form: props => <MockedForm {...props} />,23 service: {24 getById: () => Promise.resolve({}),25 create: () => Promise.resolve({}),26 update: () => Promise.resolve({}),27 },28 },29 };30 });31 it('should render a form', async () => {32 const currentProps = {33 ...props,34 match: { params: { customerId: 2, noteId: 0 } },35 };36 const wrapper = mount(<DependentEntityCreateEditForm {...currentProps} />);37 expect(wrapper.find('MockedForm').length).toBe(1);38 expect(wrapper.find('CreateEditSubmitButtonGroup').length).toBe(1);39 });40 it('should render a form in create mode', async () => {41 const currentProps = {42 ...props,43 match: { params: { customerId: 2, noteId: 0 } },44 };45 const wrapper = shallow(46 <DependentEntityCreateEditForm {...currentProps} />47 );48 await wrapper.update();49 expect(wrapper.instance().state).toStrictEqual({50 entity: {51 noteText: '',52 customerId: 2,53 noteId: 0,54 },55 isLoading: false,56 isLoaded: true,57 });58 });59 it('should render a form in create mode if there is no data from server', async () => {60 const getByIdMock = () => Promise.resolve();61 const currentProps = {62 ...props,63 match: { params: { customerId: 2, noteId: 1 } },64 };65 currentProps.entityProps.service.getById = getByIdMock;66 const wrapper = shallow(67 <DependentEntityCreateEditForm {...currentProps} />68 );69 await wrapper.update();70 expect(wrapper.instance().state).toStrictEqual({71 entity: {72 noteText: '',73 customerId: 2,74 noteId: 0,75 },76 isLoading: false,77 isLoaded: true,78 });79 });80 it('should render a form in edit mode', async () => {81 const getByIdMock = () =>82 Promise.resolve({ noteId: 1, customerId: 2, noteText: 'Note1' });83 const currentProps = { ...props };84 currentProps.entityProps.service.getById = getByIdMock;85 const wrapper = shallow(86 <DependentEntityCreateEditForm {...currentProps} />87 );88 await wrapper.update();89 expect(wrapper.instance().state).toStrictEqual({90 entity: {91 noteText: 'Note1',92 customerId: 2,93 noteId: 1,94 },95 isLoading: false,96 isLoaded: true,97 });98 });99 it('should render an error message from server', async () => {100 const getByIdMock = () =>101 Promise.resolve({ error: true, errorTitle: 'Test' });102 const showAlertMock = jest.fn(() => {});103 const currentProps = { ...props, showAlert: showAlertMock };104 currentProps.entityProps.service.getById = getByIdMock;105 const wrapper = shallow(106 <DependentEntityCreateEditForm {...currentProps} />107 );108 await wrapper.update();109 expect(showAlertMock).toHaveBeenCalledTimes(1);110 expect(showAlertMock).toBeCalledWith('Test', 'error');111 });112 it('should render a error message on invalid customerId', async () => {113 const showAlertMock = jest.fn(() => {});114 const currentProps = {115 ...props,116 match: { params: { customerId: 'id', noteId: 0 } },117 showAlert: showAlertMock,118 };119 const wrapper = shallow(120 <DependentEntityCreateEditForm {...currentProps} />121 );122 await wrapper.update();123 expect(showAlertMock).toHaveBeenCalledTimes(1);124 expect(showAlertMock).toBeCalledWith('Customer is not found.', 'error');125 });126 it('should call close alert handler and getById on update', () => {127 const getByIdMock = jest.fn(() =>128 Promise.resolve({ noteId: 1, customerId: 2, noteText: 'Note1' })129 );130 const closeAlertMock = jest.fn(() => {});131 const currentProps = {132 ...props,133 match: { params: { customerId: 2, noteId: 1 } },134 closeAlert: closeAlertMock,135 };136 currentProps.entityProps.service.getById = getByIdMock;137 const wrapper = shallow(138 <DependentEntityCreateEditForm {...currentProps} />139 );140 wrapper.instance().state.isLoaded = false;141 wrapper.instance().state.isLoading = false;142 wrapper.setProps({});143 expect(closeAlertMock).toHaveBeenCalledTimes(1);144 expect(getByIdMock).toHaveBeenCalledTimes(2);145 });146 it('should not call close alert handler and getById on update if isLoaded is true', () => {147 const getByIdMock = jest.fn(() =>148 Promise.resolve({ noteId: 1, customerId: 2, noteText: 'Note1' })149 );150 const closeAlertMock = jest.fn(() => {});151 const currentProps = {152 ...props,153 match: { params: { customerId: 2, noteId: 1 } },154 closeAlert: closeAlertMock,155 };156 currentProps.entityProps.service.getById = getByIdMock;157 const wrapper = shallow(158 <DependentEntityCreateEditForm {...currentProps} />159 );160 wrapper.instance().state.isLoaded = true;161 wrapper.instance().state.isLoading = false;162 wrapper.setProps({});163 expect(closeAlertMock).toHaveBeenCalledTimes(0);164 expect(getByIdMock).toHaveBeenCalledTimes(1);165 });166 it('should not call close alert handler and getById on update if isLoading is true', () => {167 const getByIdMock = jest.fn(() =>168 Promise.resolve({ noteId: 1, customerId: 2, noteText: 'Note1' })169 );170 const closeAlertMock = jest.fn(() => {});171 const currentProps = {172 ...props,173 match: { params: { customerId: 2, noteId: 1 } },174 closeAlert: closeAlertMock,175 };176 currentProps.entityProps.service.getById = getByIdMock;177 const wrapper = shallow(178 <DependentEntityCreateEditForm {...currentProps} />179 );180 wrapper.instance().state.isLoaded = false;181 wrapper.instance().state.isLoading = true;182 wrapper.setProps({});183 expect(closeAlertMock).toHaveBeenCalledTimes(0);184 expect(getByIdMock).toHaveBeenCalledTimes(1);185 });186 it('should call only close alert handler on update', () => {187 const getByIdMock = jest.fn(() => {});188 const closeAlertMock = jest.fn(() => {});189 const currentProps = {190 ...props,191 match: { params: { customerId: 0, noteId: 0 } },192 closeAlert: closeAlertMock,193 };194 currentProps.entityProps.service.getById = getByIdMock;195 const wrapper = shallow(196 <DependentEntityCreateEditForm {...currentProps} />197 );198 wrapper.instance().state.isLoaded = false;199 wrapper.instance().state.isLoading = false;200 wrapper.setProps({});201 expect(closeAlertMock).toHaveBeenCalledTimes(1);202 expect(getByIdMock).toHaveBeenCalledTimes(0);203 });...

Full Screen

Full Screen

RowComparer.ts

Source:RowComparer.ts Github

copy

Full Screen

1import { RowRendererProps } from '../types';2export default function shouldRowUpdate<R>(nextProps: RowRendererProps<R>, currentProps: RowRendererProps<R>) {3 return (4 currentProps.columns !== nextProps.columns ||5 nextProps.row !== currentProps.row ||6 currentProps.colOverscanStartIdx !== nextProps.colOverscanStartIdx ||7 currentProps.colOverscanEndIdx !== nextProps.colOverscanEndIdx ||8 currentProps.isSelected !== nextProps.isSelected ||9 currentProps.isScrolling !== nextProps.isScrolling ||10 nextProps.height !== currentProps.height ||11 currentProps.extraClasses !== nextProps.extraClasses12 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs';4import { action } from '@storybook/addon-actions';5import { withReadme } from 'storybook-readme';6import { withPropsTable } from 'storybook-addon-react-docgen';7import { withInfo } from '@storybook/addon-info';8import { withCurrentProps } from 'storybook-addon-current-props';9import { withPropsCombinations } from 'storybook-addon-react-docgen';10import { withTests } from '@storybook/addon-jest';11import { withA11y } from '@storybook/addon-a11y';12import { withPerformance } from 'storybook-addon-performance';13import { withConsole } from '@storybook/addon-console';14import { withViewport } from '@storybook/addon-viewport';15import { withSmartKnobs } from 'storybook-addon-smart-knobs';16import { withDesign } from 'storybook-addon-designs';17import { withStorysource } from '@storybook/addon-storysource';18import { withState } from '@dump247/storybook-state';19import { withRedux } from 'addon-redux';20import { withReduxDecorator } from 'storybook-addon-redux-decorator';21import { Button } from '@storybook/react/demo';22import { Button as Button2 } from '@storybook/react/demo';23import { Button as Button3 } from '@storybook/react/demo';24import { Button as Button4 } from '@storybook/react/demo';25import { Button as Button5 } from '@storybook/react/demo';26import { Button as Button6 } from '@storybook/react/demo';27import { Button as Button7 } from '@storybook/react/demo';28import { Button as Button8 } from '@storybook/react/demo';29import { Button as Button9 } from '@storybook/react/demo';30import { Button as Button10 } from '@storybook/react/demo';31import { Button as Button11 } from '@storybook/react/demo';32import { Button as Button12 } from '@storybook/react/demo';33import { Button as Button13 } from '@storybook/react/demo';34import { Button as Button14 } from '@storybook/react/demo';35import { Button as Button15 } from '@storybook/react/demo';36import { Button as Button16 } from '@storybook/react/demo';37import { Button as Button17 } from '@storybook/react/demo';38import { Button as Button18 } from '@

Full Screen

Using AI Code Generation

copy

Full Screen

1import { currentProps } from 'storybook-root';2const props = currentProps();3export default props;4import React from 'react';5import { storiesOf } from '@kadira/storybook';6import { withKnobs, text } from '@kadira/storybook-addon-knobs';7import { withPropsTable } from 'storybook-addon-react-docgen';8import { withInfo } from '@kadira/storybook-addon-info';9import { withProps } from 'storybook-addon-props';10storiesOf('MyComponent', module)11 .addDecorator(withKnobs)12 .addDecorator(withPropsTable)13 .addDecorator(withProps)14 .addDecorator(withInfo)15 .add('with text', () => (16 <MyComponent text={text('Text', 'Hello Storybook')} />17 ));

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import ReactDOM from 'react-dom';3import { currentProps } from 'storybook-root';4import Props from 'storybook-addon-props';5const props = currentProps();6ReactDOM.render(<Props {...props} />, document.getElementById('root'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const currentProps = require('storybook-root').currentProps;2const story = require('../src/components/Story');3const props = currentProps();4story(props);5function story(props) {6}7const props = require('./props');8const currentStory = require('./current-story');9module.exports = {10 currentProps: () => props[currentStory()]11};12module.exports = () => {13 return 'story-name';14};15module.exports = {16 'story-name': {17 }18};19module.exports = {20};21module.exports = {22 storybookRoot: require.resolve('storybook-root')23};24module.exports = {25 storybookRoot: require.resolve('storybook-root')26};27module.exports = {28 storybookRoot: require.resolve('storybook-root')29};

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