From 013a2d7f944c7b0e9ca18396ee2b37f9a53976e0 Mon Sep 17 00:00:00 2001 From: Vlad Ifrim Date: Sat, 4 Nov 2023 17:58:00 +0200 Subject: [PATCH] adds unit tests for the message component --- src/components/Message/Message.test.js | 53 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/components/Message/Message.test.js b/src/components/Message/Message.test.js index 2b58e3a7..09cf6864 100644 --- a/src/components/Message/Message.test.js +++ b/src/components/Message/Message.test.js @@ -1,7 +1,56 @@ +import React from 'react'; import Message from './index'; +function Component(props) { + return ( + + lorem ipsum + + ); +} + describe('Message', () => { - it('TODO', () => { - expect(true).to.equal(true); + const infoThemeClass = 'tyk-message--info'; + const successThemeClass = 'tyk-message--success'; + const noMarginClass = 'no-margin'; + const selectors = { + message: '.tyk-message', + closeIcon: '.tyk-icon.tykon-x', + }; + + it('renders the component with the info theme by default', () => { + cy.mount() + .get(selectors.message) + .should('exist') + .and('have.class', infoThemeClass); + }); + + it('can be rendered with a different theme', () => { + cy.mount() + .get(selectors.message) + .should('have.class', successThemeClass); + }); + + it('can be rendered with no margins', () => { + cy.mount() + .get(selectors.message) + .should('have.class', noMarginClass); + }); + + it('can have custom classes', () => { + const myClass = 'foo'; + cy.mount() + .get(selectors.message) + .should('have.class', myClass); + }); + + it('renders an icon that calls the onClose callback when clicked', () => { + const onClose = cy.stub(); + cy.mount() + .get(selectors.closeIcon) + .click() + .then(() => { + expect(onClose).to.be.called; + }); }); });