import { mount } from '@vue/test-utils'
import Design from './design'
import * as BackgroundColorMapping from '../../constants/colorsConstant'
BackgroundColorMapping.getBackgroundStyleFromFamilyCode = jest.fn(familyCode => familyCode === 'WH' ? 'BackgroundStyle' : null)
describe('Background Style', () => {
const testData = [
{
description: 'Should have the thumbnail as background-image',
props: { designKey: 'designKey', colorFamilyCodes: [{code: 'WH'}], thumbnailUrl: 'theTHUrl', hexadecimalColorCode: '123456' },
expectedResult: { backgroundImage: 'url("theThumbnailUrl")', backgroundColor: '#123456' }
},
{
description: 'Should get color from hexadecimal color code',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WH' }], thumbnailName: null, hexadecimalColorCode: '123456' },
expectedResult: { backgroundColor: '#123456' }
},
{
description: 'Should get the color from the color family',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WH' }], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: 'BackgroundStyle'
},
{
description: 'Should get default white the color family is not mapped to a color',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WrongCode' }], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: { backgroundColor: 'white' }
},
{
description: 'Should get default white color if no data is provided',
props: { designKey: 'designKey', colorFamilyCodes: [], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: { backgroundColor: 'white' }
}
]
testData.map(({ description, props, expectedResult }) => {
it(description, () => {
const wrapper = mount(Design, { propsData: props })
expect(wrapper.vm.backgroundColorStyle).toEqual(expectedResult)
})
})
import { mount } from '@vue/test-utils'
import Design from './design'
import * as BackgroundColorMapping from '../../constants/colorsConstant'
BackgroundColorMapping.getBackgroundStyleFromFamilyCode = jest.fn(familyCode => familyCode === 'WH' ? 'BackgroundStyle' : null)
describe('Background Style', () => {
const testData = [
{
description: 'Should have the thumbnail as background-image',
props: { designKey: 'designKey', colorFamilyCodes: [{code: 'WH'}], thumbnailUrl: 'theTHUrl', hexadecimalColorCode: '123456' },
expectedResult: { backgroundImage: 'url("theThumbnailUrl")', backgroundColor: '#123456' }
},
{
description: 'Should get color from hexadecimal color code',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WH' }], thumbnailName: null, hexadecimalColorCode: '123456' },
expectedResult: { backgroundColor: '#123456' }
},
{
description: 'Should get the color from the color family',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WH' }], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: 'BackgroundStyle'
},
{
description: 'Should get default white the color family is not mapped to a color',
props: { designKey: 'designKey', colorFamilyCodes: [{ code: 'WrongCode' }], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: { backgroundColor: 'white' }
},
{
description: 'Should get default white color if no data is provided',
props: { designKey: 'designKey', colorFamilyCodes: [], thumbnailName: null, hexadecimalColorCode: null },
expectedResult: { backgroundColor: 'white' }
}
]
testData.map(({ description, props, expectedResult }) => {
it(description, () => {
const wrapper = mount(Design, { propsData: props })
expect(wrapper.vm.backgroundColorStyle).toEqual(expectedResult)
})
})