Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-10530][TUI-34] Improve test coverage for Tyk-UI Toast Component #324

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 95 additions & 3 deletions src/components/Toast/Toast.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,99 @@
import Toast from './index';
import React from 'react';
import PropTypes from 'prop-types';
import toast from './index';

/* eslint-disable react/destructuring-assignment */
function Component(props) {
// eslint-disable-next-line react/jsx-no-useless-fragment
return (<>{props.children || (<button type="button" onClick={props.onClick}>Show Toast</button>)}</>);
}
Yasintrm marked this conversation as resolved.
Show resolved Hide resolved

Component.propTypes = {
onClick: PropTypes.func,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
PropTypes.element,
PropTypes.string,
]),
};

describe('Toast', () => {
it('TODO', () => {
expect(true).to.equal(true);
const classNames = {
toast: 'tyk-toast',
toastContainer: 'tyk-toast__container',
message: 'tyk-toast__message',
messageContent: 'tyk-message__content',
theme: {
success: 'tyk-message--success',
danger: 'tyk-message--danger',
info: 'tyk-message--info',
warning: 'tyk-message--warning',
},
icons: {
icon: 'tyk-icon',
success: 'tykon-check',
warning: 'tykon-warning',
},
};

const selectors = {
toast: `.${classNames.toast}`,
toastContainer: `.${classNames.toastContainer}`,
message: `.${classNames.message}`,
messageContent: `.${classNames.messageContent}`,
theme: {
success: `.${classNames.theme.success}`,
danger: `.${classNames.theme.danger}`,
info: `.${classNames.theme.info}`,
warning: `.${classNames.theme.warning}`,
},
icons: {
icon: `.${classNames.icons.icon}`,
success: `.${classNames.icons.success}`,
warning: `.${classNames.icons.warning}`,
},
};
it('should render toast components and remove it after the given delay', () => {
cy.mount(<Component onClick={() => toast.notify('demo', { delay: 150 })} />)
.get('button')
.click()
.click()
.then(() => {
cy.get(selectors.toastContainer)
.should('exist')
.find(selectors.message)
.should('exist')
.and('have.length', 2)
.and('have.class', classNames.theme.success);
})
.then(() => {
cy.get(selectors.toastContainer)
.should('exist')
.find(selectors.message, { timeout: 350 })
.should('not.exist');
});
});
Yasintrm marked this conversation as resolved.
Show resolved Hide resolved

it('should display given message with correct icon for each theme', {}, () => {
cy.wrap(Object.entries(classNames.theme)).each(([theme, className]) => {
const onClick = () => toast[theme].bind(toast)(`demo ${theme}`, { timeout: 200 });
cy.mount(<Component onClick={onClick} />)
.get('button')
.click()
.then(() => {
cy.get(selectors.toastContainer)
.should('exist')
.find(`.${classNames.message}.${className}`)
.should('exist')
.find(selectors.icons.icon)
.should('exist')
.and('have.class', theme === 'success' ? classNames.icons.success : classNames.icons.warning)
.closest(selectors.message)
.find(selectors.messageContent)
.should('exist')
.and('have.text', `demo ${theme}`);
});
});
Yasintrm marked this conversation as resolved.
Show resolved Hide resolved
});
});
Loading