DigitalConsumer.ISS/src/digital-components/text-block/text-block.spec.js
2023-09-14 14:19:47 -04:00

63 lines
2.1 KiB
JavaScript

import { shallowMount } from '@vue/test-utils';
import TextBlock from '@/digital-components/text-block/text-block.vue';
const mockCmsContent = {
Text: 'Sample text here.'
};
const mockMixin = {
methods: {
getCmsContent: jest.fn((widgetName, cmsFieldName) => mockCmsContent[cmsFieldName])
}
};
const mockProps = {
fontWeight: 'mockFontWeight',
typeStyle: 'mockTypeStyle',
justifyText: 'mockJustifyText'
};
// Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({
doesCopyContainRouterLink: jest.fn(),
doesCopyContainTextLink: jest.fn(),
splitCopyOnCMSPlaceHolder: jest.fn(() => mockCmsContent.Text.split(/{(.*?)}/g)),
getRouterLinkRouteFromCopy: jest.fn(),
getRouterLinkDisplayTextFromCopy: jest.fn(),
getExternalLink: jest.fn()
}));
describe('modal.vue', () => {
it("Should display 'Text' when 'Text' is defined in the CMS", async () => {
// Act
const wrapper = shallowMount(TextBlock, {
mixins: [mockMixin]
});
expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent.Text));
});
it('Should contain the typeStyle class as defined by the prop', async () => {
// Act
const wrapper = shallowMount(TextBlock, {
mixins: [mockMixin],
propsData: mockProps
});
expect(wrapper.html()).toEqual(expect.stringContaining(mockProps.typeStyle));
});
it('Should contain the justifyText class as defined by the prop', async () => {
// Act
const wrapper = shallowMount(TextBlock, {
mixins: [mockMixin],
propsData: mockProps
});
expect(wrapper.html()).toEqual(expect.stringContaining(mockProps.justifyText));
});
it('Should contain the fontWeight class as defined by the prop', async () => {
// Act
const wrapper = shallowMount(TextBlock, {
mixins: [mockMixin],
propsData: mockProps
});
expect(wrapper.html()).toEqual(expect.stringContaining(mockProps.fontWeight));
});
});