|
| 1 | +import { mount } from '@vue/test-utils'; |
| 2 | + |
| 3 | +Shopware.Component.register( |
| 4 | + 'sw-in-app-purchase-checkout-subscription-change', |
| 5 | + () => import('SwagExtensionStore/module/sw-in-app-purchases/component/sw-in-app-purchase-checkout-subscription-change') |
| 6 | +); |
| 7 | + |
| 8 | +jest.mock('SwagExtensionStore/module/sw-in-app-purchases/types', () => ({ |
| 9 | + InAppPurchase: jest.fn() |
| 10 | +})); |
| 11 | + |
| 12 | +const defaultCart = { |
| 13 | + netPrice: 5.99, |
| 14 | + grossPrice: 7.13, |
| 15 | + taxPrice: 7.13, |
| 16 | + taxValue: 19, |
| 17 | + positions: [{ |
| 18 | + variant: 'monthly', |
| 19 | + proratedNetPrice: 3.50, |
| 20 | + nextBookingDate: '2026-04-01', |
| 21 | + subscriptionChange: { |
| 22 | + isIncludedInPluginLicense: false, |
| 23 | + currentFeature: { |
| 24 | + name: 'Basic Plan', |
| 25 | + priceModels: [{ |
| 26 | + type: 'rent', |
| 27 | + price: 2.99, |
| 28 | + duration: 1, |
| 29 | + variant: 'monthly' |
| 30 | + }] |
| 31 | + } |
| 32 | + } |
| 33 | + }] |
| 34 | +}; |
| 35 | + |
| 36 | +async function createWrapper(props = {}) { |
| 37 | + return mount(await Shopware.Component.build('sw-in-app-purchase-checkout-subscription-change'), { |
| 38 | + props: { |
| 39 | + purchase: { |
| 40 | + priceModels: [{ |
| 41 | + type: 'rent', |
| 42 | + price: 5.99, |
| 43 | + duration: 1, |
| 44 | + variant: 'monthly' |
| 45 | + }] |
| 46 | + }, |
| 47 | + cart: defaultCart, |
| 48 | + ...props |
| 49 | + }, |
| 50 | + global: { |
| 51 | + stubs: { |
| 52 | + 'mt-banner': true |
| 53 | + } |
| 54 | + } |
| 55 | + }); |
| 56 | +} |
| 57 | + |
| 58 | +describe('sw-in-app-purchase-checkout-subscription-change', () => { |
| 59 | + let wrapper; |
| 60 | + |
| 61 | + beforeEach(async () => { |
| 62 | + wrapper = await createWrapper(); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should be a Vue.js component', () => { |
| 66 | + expect(wrapper.vm).toBeTruthy(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should render correctly', () => { |
| 70 | + expect(wrapper.exists()).toBe(true); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should compute cartPosition from first cart position', () => { |
| 74 | + expect(wrapper.vm.cartPosition).toEqual(defaultCart.positions[0]); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should compute isIncludedInPluginLicense as false by default', () => { |
| 78 | + expect(wrapper.vm.isIncludedInPluginLicense).toBe(false); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should compute isIncludedInPluginLicense as true when set', async () => { |
| 82 | + wrapper = await createWrapper({ |
| 83 | + cart: { |
| 84 | + ...defaultCart, |
| 85 | + positions: [{ |
| 86 | + ...defaultCart.positions[0], |
| 87 | + subscriptionChange: { |
| 88 | + ...defaultCart.positions[0].subscriptionChange, |
| 89 | + isIncludedInPluginLicense: true |
| 90 | + } |
| 91 | + }] |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + expect(wrapper.vm.isIncludedInPluginLicense).toBe(true); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should compute getCurrentPrice from matching variant price model', () => { |
| 99 | + expect(wrapper.vm.getCurrentPrice).toContain('2.99'); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should compute getCurrentPlanName from current feature', () => { |
| 103 | + expect(wrapper.vm.getCurrentPlanName).toBe('Basic Plan'); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should compute formattedStartingDate from nextBookingDate', () => { |
| 107 | + expect(wrapper.vm.formattedStartingDate).toBeTruthy(); |
| 108 | + }); |
| 109 | + |
| 110 | + it('should not render access-grant-hint banner when not included in plugin license', () => { |
| 111 | + expect(wrapper.find('.sw-in-app-purchase-checkout-subscription-change__access-grant-hint').exists()).toBe(false); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should render access-grant-hint banner when included in plugin license', async () => { |
| 115 | + wrapper = await createWrapper({ |
| 116 | + cart: { |
| 117 | + ...defaultCart, |
| 118 | + positions: [{ |
| 119 | + ...defaultCart.positions[0], |
| 120 | + subscriptionChange: { |
| 121 | + ...defaultCart.positions[0].subscriptionChange, |
| 122 | + isIncludedInPluginLicense: true |
| 123 | + } |
| 124 | + }] |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + expect(wrapper.find('.sw-in-app-purchase-checkout-subscription-change__access-grant-hint').exists()).toBe(true); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should render current plan and new plan sections', () => { |
| 132 | + const items = wrapper.findAll('.sw-in-app-purchase-checkout-subscription-change__item'); |
| 133 | + expect(items).toHaveLength(3); |
| 134 | + }); |
| 135 | + |
| 136 | + it('should render the divider', () => { |
| 137 | + expect(wrapper.find('.sw-in-app-purchase-checkout-subscription-change__divider').exists()).toBe(true); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should render the info hint', () => { |
| 141 | + expect(wrapper.find('.sw-in-app-purchase-checkout-subscription-change__info-hint').exists()).toBe(true); |
| 142 | + expect(wrapper.find('.sw-in-app-purchase-checkout-subscription-change__info-hint').text()).toBeTruthy(); |
| 143 | + }); |
| 144 | +}); |
0 commit comments