From c66490c3f9146eacbf34181360ba869ffb27c5ef Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 2 Jan 2025 13:27:09 +0530 Subject: [PATCH] extend tests --- src/components/Stepper/Stepper.test.js | 48 ++++++++++++++++++--- src/components/Stepper/js/StepperButtons.js | 1 + 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/components/Stepper/Stepper.test.js b/src/components/Stepper/Stepper.test.js index 9e15b5d9..c615f3c4 100644 --- a/src/components/Stepper/Stepper.test.js +++ b/src/components/Stepper/Stepper.test.js @@ -1,11 +1,10 @@ -/* eslint-disable react/prop-types */ import React from 'react'; import Stepper from './index'; - function StepperComponent({ validator, onFinish: mockOnFinish, + onSkip: mockOnSkip, orientation = 'vertical' }) { const onFinish = () => { @@ -23,6 +22,7 @@ function StepperComponent({ stepValidator={validator || stepValidator} stepErrMessage="Validation failed" orientation={orientation} + onSkip={mockOnSkip} > Step 1 content @@ -103,8 +103,47 @@ describe('Stepper Component', () => { }); }); - describe('Vertical Orientation', () => { + describe('Skip Functionality', () => { + it('should render skip button when onSkip prop is provided', () => { + const onSkip = cy.stub().as('onSkip'); + cy.mount() + .get('.skip-btn button') + .should('exist') + .and('contain', 'Skip'); + }); + + it('should not render skip button when onSkip prop is not provided', () => { + cy.mount() + .get('.skip-btn') + .should('not.exist'); + }); + + it('should call onSkip with current step id when skip button is clicked', () => { + const onSkip = cy.stub().as('onSkip'); + cy.mount() + .get('.skip-btn button') + .click() + .get('@onSkip') + .should('have.been.calledWith', 'step1'); + }); + it('should allow skipping multiple steps', () => { + const onSkip = cy.stub().as('onSkip'); + cy.mount( true} />) + .get('.skip-btn button') + .click() + .get('.stepper-buttons button') + .contains('Continue') + .click() + .get('.skip-btn button') + .click() + .get('@onSkip') + .should('have.been.calledTwice') + .and('have.been.calledWith', 'step2'); + }); + }); + + describe('Vertical Orientation', () => { it('should show green connecting line for completed steps', () => { cy.mount( true} />) .get('.stepper-buttons button') @@ -119,7 +158,7 @@ describe('Stepper Component', () => { it('should render in horizontal layout', () => { cy.mount() .get('.step-list-horizontal') - .should('exist') + .should('exist'); }); it('should show progress line below step numbers', () => { @@ -150,5 +189,4 @@ describe('Stepper Component', () => { .should('contain', 'Step 2 content'); }); }); - }); \ No newline at end of file diff --git a/src/components/Stepper/js/StepperButtons.js b/src/components/Stepper/js/StepperButtons.js index 1aa576b5..0927a3fd 100644 --- a/src/components/Stepper/js/StepperButtons.js +++ b/src/components/Stepper/js/StepperButtons.js @@ -82,6 +82,7 @@ StepperButtons.propTypes = { nextBtnTxt: PropTypes.string.isRequired, finishBtnTxt: PropTypes.string.isRequired, backBtnTxt: PropTypes.string.isRequired, + skipBtnTxt: PropTypes.string.isRequired, }; export default StepperButtons;