From e976ed918acd94ed9a590d9261f4e6b2ffdc2961 Mon Sep 17 00:00:00 2001 From: Jimmy Sanford Date: Fri, 15 Mar 2019 15:21:10 -0700 Subject: [PATCH] Add unit tests for getOptionType --- .../__tests__/getOptionType.spec.js | 17 +++++++++++++++++ .../components/ProductOptions/getOptionType.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/venia-concept/src/components/ProductOptions/__tests__/getOptionType.spec.js diff --git a/packages/venia-concept/src/components/ProductOptions/__tests__/getOptionType.spec.js b/packages/venia-concept/src/components/ProductOptions/__tests__/getOptionType.spec.js new file mode 100644 index 0000000000..f54d3a3af1 --- /dev/null +++ b/packages/venia-concept/src/components/ProductOptions/__tests__/getOptionType.spec.js @@ -0,0 +1,17 @@ +import getOptionType from '../getOptionType'; + +test('returns undefined by default', () => { + expect(getOptionType()).toBeUndefined(); +}); + +test('returns undefined for unrecognized attribute code', () => { + const option = { attribute_code: '__foo' }; + + expect(getOptionType(option)).toBeUndefined(); +}); + +test('identifies `fashion_color` as a `swatch` attribute', () => { + const option = { attribute_code: 'fashion_color' }; + + expect(getOptionType(option)).toBe('swatch'); +}); diff --git a/packages/venia-concept/src/components/ProductOptions/getOptionType.js b/packages/venia-concept/src/components/ProductOptions/getOptionType.js index c77b5aae09..fe58f9fe7e 100644 --- a/packages/venia-concept/src/components/ProductOptions/getOptionType.js +++ b/packages/venia-concept/src/components/ProductOptions/getOptionType.js @@ -2,4 +2,4 @@ const customAttributes = { fashion_color: 'swatch' }; -export default ({ attribute_code: code }) => customAttributes[code]; +export default ({ attribute_code: code } = {}) => customAttributes[code];