Skip to content

Commit

Permalink
adds unit tests for the message component
Browse files Browse the repository at this point in the history
  • Loading branch information
ifrim committed Nov 4, 2023
1 parent 3f3ce51 commit 013a2d7
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/components/Message/Message.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
import React from 'react';
import Message from './index';

function Component(props) {
return (
<Message {...props}>
lorem ipsum
</Message>
);
}

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(<Component />)
.get(selectors.message)
.should('exist')
.and('have.class', infoThemeClass);
});

it('can be rendered with a different theme', () => {
cy.mount(<Component theme="success" />)
.get(selectors.message)
.should('have.class', successThemeClass);
});

it('can be rendered with no margins', () => {
cy.mount(<Component noMargin />)
.get(selectors.message)
.should('have.class', noMarginClass);
});

it('can have custom classes', () => {
const myClass = 'foo';
cy.mount(<Component className={myClass} />)
.get(selectors.message)
.should('have.class', myClass);
});

it('renders an icon that calls the onClose callback when clicked', () => {
const onClose = cy.stub();
cy.mount(<Component onClose={onClose} />)
.get(selectors.closeIcon)
.click()
.then(() => {
expect(onClose).to.be.called;
});
});
});

0 comments on commit 013a2d7

Please sign in to comment.