diff --git a/src/iss-components/cart-dropdown/__snapshots__/cart-dropdown.spec.js.snap b/src/iss-components/cart-dropdown/__snapshots__/cart-dropdown.spec.js.snap new file mode 100644 index 00000000..f0fe9808 --- /dev/null +++ b/src/iss-components/cart-dropdown/__snapshots__/cart-dropdown.spec.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`cart-dropdown component initial data rendered as expected 1`] = ` +Object { + "currencyFormatter": NumberFormat {}, + "isExpanded": false, + "widget": Object { + "amountDue": "AmountDueTextWidget", + }, +} +`; diff --git a/src/iss-components/cart-dropdown/cart-dropdown.spec.js b/src/iss-components/cart-dropdown/cart-dropdown.spec.js new file mode 100644 index 00000000..e55bdc36 --- /dev/null +++ b/src/iss-components/cart-dropdown/cart-dropdown.spec.js @@ -0,0 +1,159 @@ +import { shallowMount } from '@vue/test-utils'; +import { createTestingPinia } from '@pinia/testing'; +import cartDropdown from '@/iss-components/cart-dropdown/cart-dropdown.vue'; + +// Supporting Files +import { getMountOptions } from '@/helpers/unit-test-helper.js'; +import { useMainStore } from '@/store'; + +function getMountedComponent(mainInitialState = {}, initialData = {}, propsData = {}) { + const mountOptions = getMountOptions({ + router: { + navigate: jest.fn() + } + }); + + const testingPinia = createTestingPinia({ + initialState: { + main: mainInitialState + } + }); + useMainStore(testingPinia); + + mountOptions.global.plugins = [testingPinia]; + mountOptions.data = () => (initialData); + mountOptions.propsData = propsData; + + const wrapper = shallowMount(cartDropdown, mountOptions); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => {}); + wrapper.vm.setCmsContent = jest.fn(); + return { wrapper }; +} + +describe('cart-dropdown component', () => { + test('initial data rendered as expected', () => { + // Arrange + const { wrapper } = getMountedComponent(); + + // Assert + expect(wrapper.vm.$data).toMatchSnapshot(); + }); + describe('displays', () => { + test('cart dropdown head', () => { + // Arrange + const reference = '#cart-dropdown-head'; + const { wrapper } = getMountedComponent(cartDropdown); + + // Act + const head = wrapper.find(reference); + + // Assert + expect(head.exists()).toBeTruthy(); + }); + test('cart table', () => { + // Arrange + const reference = '#cart-table'; + const isExpanded = true; + const initialData = { isExpanded }; + const { wrapper } = getMountedComponent(cartDropdown, {}, initialData); + + // Act + const cartTable = wrapper.find(reference); + + // Assert + expect(cartTable.exists()).toBeTruthy(); + }); + }); + describe('computed', () => { + test.each([ + [true, true], + [false, false], + [false, null] + ])('isVerified returns %p when isVerified store value is %p', (expected, isVerified) => { + // Arrange + const storeData = { + order: { + payment: { + insuranceCoverage: { isVerified } + } + } + }; + const { wrapper } = getMountedComponent(storeData); + + // Act + const result = wrapper.vm.isVerified; + + // Assert + expect(result).toBe(expected); + }); + describe('amountDueDisplayed', () => { + test('returns verifying coverage text when isVerified false', () => { + // Arrange + const VERIFYING_COVERAGE = 'Verifying coverage'; + const storeData = { + order: { + payment: { + insuranceCoverage: { + isVerified: false + } + } + } + }; + const { wrapper } = getMountedComponent(storeData); + + // Act + const result = wrapper.vm.amountDueDisplayed; + + // Assert + expect(result).toBe(VERIFYING_COVERAGE); + }); + test('returns formatted amount due when isVerified false', () => { + // TODO finish when methods done + }); + }); + describe('amountDue', () => { + test('returns 0 when showAsPaid is true', () => { + // Arrange + const propsData = { + showAsPaid: true + }; + const { wrapper } = getMountedComponent({}, {}, propsData); + + // Act + const result = wrapper.vm.amountDue; + + // Assert + expect(result).toBe(0); + }); + test('returns sum of subTotal and salesTax when showAsPaid is false', () => { + // TODO when subTotal and salesTax are finished + }); + }); + describe('subTotal', () => { + // TODO when method implemented + }); + describe('salesTax', () => { + // TODO when method implemented + }); + }); + describe('method', () => { + test.each([ + ['$0.00', 0], + ['$12.00', 12], + ['$12.30', 12.3], + ['$12.34', 12.34], + ['$12.35', 12.345], + ['$12.34', 12.344], + ['-$1.00', -1] + ])('get FormattedAmount returns `%` when amount %', (expected, amount) => { + // Arrange + const { wrapper } = getMountedComponent(); + + // Act + const result = wrapper.vm.getFormattedAmount(amount); + + // Assert + expect(result).toBe(expected); + }); + }); +}); diff --git a/src/iss-components/cart-dropdown/cart-dropdown.vue b/src/iss-components/cart-dropdown/cart-dropdown.vue new file mode 100644 index 00000000..a7e3e08b --- /dev/null +++ b/src/iss-components/cart-dropdown/cart-dropdown.vue @@ -0,0 +1,136 @@ + + + + + diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index 5d50380d..8b03a875 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -19,8 +19,10 @@

-
Cart Placeholder
-
+ +
Pia Alert Placeholder