digitransit-ui/test/unit/component/MessageBarMessage.test.js
2024-03-15 15:25:50 +02:00

47 lines
1.6 KiB
JavaScript

import React from 'react';
import MessageBarMessage from '../../../app/component/MessageBarMessage';
import { shallowWithIntl } from '../helpers/mock-intl-enzyme';
import TruncatedMessage from '../../../app/component/TruncatedMessage';
describe('<MessageBarMessage />', () => {
it('should not render tag "a" if the href is missing', () => {
const props = {
content: [{ type: 'a', content: 'This is a link', href: undefined }],
breakpoint: 'small',
onShowMore: () => {},
};
const context = { config: { showAlertHeader: true } };
const wrapper = shallowWithIntl(<MessageBarMessage {...props} />, {
context,
});
expect(wrapper.find('a')).to.have.lengthOf(0);
});
it('should render tag "h2" for type "heading"', () => {
const props = {
content: [{ type: 'heading', content: 'This is a header' }],
breakpoint: 'small',
onMaximize: () => {},
onShowMore: () => {},
};
const context = { config: { showAlertHeader: true } };
const wrapper = shallowWithIntl(<MessageBarMessage {...props} />, {
context,
});
expect(wrapper.find('h2').text()).to.equal('This is a header');
});
it('should render text for type "text"', () => {
const props = {
content: [{ type: 'text', content: 'This is text' }],
breakpoint: 'small',
onShowMore: () => {},
};
const context = { config: { showAlertHeader: true } };
const wrapper = shallowWithIntl(<MessageBarMessage {...props} />, {
context,
});
expect(wrapper.find(TruncatedMessage)).to.have.lengthOf(1);
});
});