Skip to content

Commit

Permalink
PPI-1041 - Moved tests to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
cyl3x committed Dec 9, 2024
1 parent fe82133 commit 3b538d7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { mount } from '@vue/test-utils';
import 'SwagPayPal/module/swag-paypal/components/swag-paypal-checkout-method';
import SwagPayPalCheckoutMethod from '.';

Shopware.Component.register('swag-paypal-checkout-method', () => import('.'));
Shopware.Component.register('swag-paypal-checkout-method', Promise.resolve(SwagPayPalCheckoutMethod));
Shopware.Component.register('swag-paypal-checkout-domain-association', () => import('../swag-paypal-checkout-domain-association'));

async function createWrapper(customOptions = {}) {
const options = {
global: {
mocks: {
$tc: (key) => key,
$te: (key) => key,
$tc: (key: string) => key,
$te: (key: string) => key,
},
provide: {
acl: {
Expand Down Expand Up @@ -37,15 +37,15 @@ async function createWrapper(customOptions = {}) {
},
};
return mount(
await Shopware.Component.build('swag-paypal-checkout-method'),
await Shopware.Component.build('swag-paypal-checkout-method') as typeof SwagPayPalCheckoutMethod,
Shopware.Utils.object.mergeWith(options, customOptions),
);
}
describe('Paypal Domain Association Component', () => {
it('should be a Vue.js component', async () => {
const wrapper = await createWrapper();

await new Promise(process.nextTick);
await flushPromises();

expect(wrapper.vm).toBeTruthy();
});
Expand All @@ -59,7 +59,7 @@ describe('Paypal Domain Association Component', () => {
},
});

await new Promise(process.nextTick);
await flushPromises();

let alert = wrapper.find('.swag-plugin-apple-pay-warning');

Expand All @@ -73,10 +73,10 @@ describe('Paypal Domain Association Component', () => {
translated: {
name: 'Apple Pay',
},
},
} as TEntity<'payment_method'>,
});

await new Promise(process.nextTick);
await flushPromises();

alert = wrapper.find('.swag-plugin-apple-pay-warning');

Expand All @@ -92,7 +92,7 @@ describe('Paypal Domain Association Component', () => {
},
});

await new Promise(process.nextTick);
await flushPromises();

let alert = wrapper.find('.swag-plugin-apple-pay-warning');

Expand All @@ -106,10 +106,10 @@ describe('Paypal Domain Association Component', () => {
translated: {
name: 'Apple Pay',
},
},
} as TEntity<'payment_method'>,
});

await new Promise(process.nextTick);
await flushPromises();

alert = wrapper.find('.swag-plugin-apple-pay-warning');

Expand All @@ -125,14 +125,14 @@ describe('Paypal Domain Association Component', () => {
},
});

await new Promise(process.nextTick);
await flushPromises();

expect(wrapper.find('.swag-plugin-apple-pay-warning').exists()).toBeTruthy();

const button = wrapper.find('.sw-alert__close');
await button.trigger('click');

await new Promise(process.nextTick);
await flushPromises();

expect(wrapper.find('.swag-plugin-apple-pay-warning').exists()).toBeFalsy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils';
import 'SwagPayPal/module/swag-paypal/components/swag-paypal-checkout';
import SwagPayPalCheckout from '.';

Shopware.Component.register('swag-paypal-checkout', () => import('.'));
Shopware.Component.register('swag-paypal-checkout', Promise.resolve(SwagPayPalCheckout));

const onboardingCallbackLive = 'onboardingCallbackLive';
const onboardingCallbackSandbox = 'onboardingUrlSandbox';
Expand All @@ -10,7 +10,7 @@ async function createWrapper(customOptions = {}) {
const options = {
global: {
mocks: {
$tc: (key) => key,
$tc: (key: string) => key,
},
provide: {
acl: {
Expand Down Expand Up @@ -50,10 +50,11 @@ async function createWrapper(customOptions = {}) {
},
};

return mount(await Shopware.Component.build('swag-paypal-checkout'), {
...options,
...customOptions,
});
return mount(
await Shopware.Component.build('swag-paypal-checkout') as typeof SwagPayPalCheckout,
// @ts-expect-error - data() is incomplete
Shopware.Utils.object.merge(options, customOptions),
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { mount } from '@vue/test-utils';
import SwagPayPalCrossBorder from '.';

Shopware.Component.register('swag-paypal-cross-border', () => import('.'));
Shopware.Component.register('swag-paypal-cross-border', Promise.resolve(SwagPayPalCrossBorder));

async function createWrapper(customOptions = {}) {
const options = {
global: {
mocks: { $tc: (key) => key, $t: (key) => key },
mocks: { $tc: (key: string) => key, $t: (key: string) => key },
provide: {
acl: { can: () => true },
},
Expand All @@ -30,7 +31,7 @@ async function createWrapper(customOptions = {}) {
};

return mount(
await Shopware.Component.build('swag-paypal-cross-border'),
await Shopware.Component.build('swag-paypal-cross-border') as typeof SwagPayPalCrossBorder,
Shopware.Utils.object.mergeWith(options, customOptions),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mount } from '@vue/test-utils';
import 'SwagPayPal/module/swag-paypal/components/swag-paypal-vaulting';
import SwagPayPalVaulting from '.';

Shopware.Component.register('swag-paypal-vaulting', () => import('.'));
Shopware.Component.register('swag-paypal-vaulting', Promise.resolve(SwagPayPalVaulting));

const onboardingCallbackLive = 'onboardingCallbackLive';
const onboardingCallbackSandbox = 'onboardingUrlSandbox';
Expand All @@ -10,7 +10,7 @@ async function createWrapper(customOptions = {}) {
const options = {
global: {
mocks: {
$tc: (key) => key,
$tc: (key: string) => key,
},
provide: {
acl: {
Expand Down Expand Up @@ -54,7 +54,7 @@ async function createWrapper(customOptions = {}) {
};

return mount(
await Shopware.Component.build('swag-paypal-vaulting'),
await Shopware.Component.build('swag-paypal-vaulting') as typeof SwagPayPalVaulting,
Shopware.Utils.object.mergeWith(options, customOptions),
);
}
Expand All @@ -63,7 +63,7 @@ describe('Paypal Vaulting Component', () => {
it('should be a Vue.js component', async () => {
const wrapper = await createWrapper();

await new Promise(process.nextTick);
await flushPromises();

expect(wrapper.vm).toBeTruthy();
});
Expand Down Expand Up @@ -94,10 +94,10 @@ describe('Paypal Vaulting Component', () => {
it('should render onboarding buttons', async () => {
const wrapper = await createWrapper();

await new Promise(process.nextTick);
await flushPromises();

const liveButton = await wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackLive']");
const sandboxButton = await wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackSandbox']");
const liveButton = wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackLive']");
const sandboxButton = wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackSandbox']");

expect(liveButton.exists()).toBe(true);
expect(sandboxButton.exists()).toBe(true);
Expand All @@ -106,19 +106,19 @@ describe('Paypal Vaulting Component', () => {
it('should link to the live onboarding guide', async () => {
const wrapper = await createWrapper();

await new Promise(process.nextTick);
await flushPromises();

const liveButton = await wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackLive']");
const liveButton = wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackLive']");

expect(liveButton.attributes('href')).toBe(onboardingCallbackLive);
});

it('should link to the sandbox onboarding guide', async () => {
const wrapper = await createWrapper();

await new Promise(process.nextTick);
await flushPromises();

const sandboxButton = await wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackSandbox']");
const sandboxButton = wrapper.find("a[data-paypal-onboard-complete='onboardingCallbackSandbox']");

expect(sandboxButton.attributes('href')).toBe(onboardingCallbackSandbox);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { mount } from '@vue/test-utils';
import 'SwagPayPal/module/swag-paypal/components/swag-paypal-webhook';
import SwagPayPalWebhook from '.';

Shopware.Component.register('swag-paypal-webhook', () => import('.'));
Shopware.Component.register('swag-paypal-webhook', Promise.resolve(SwagPayPalWebhook));

async function createWrapper(customOptions = {}) {
const options = {
global: {
mocks: { $tc: (key) => key },
mocks: { $tc: (key: string) => key },
provide: {
acl: {
can: () => true,
Expand All @@ -27,8 +27,8 @@ async function createWrapper(customOptions = {}) {
};

return mount(
await Shopware.Component.build('swag-paypal-webhook'),
Shopware.Utils.object.mergeWith(options, customOptions),
await Shopware.Component.build('swag-paypal-webhook') as typeof SwagPayPalWebhook,
Shopware.Utils.object.merge(options, customOptions),
);
}

Expand Down Expand Up @@ -153,7 +153,6 @@ describe('swag-paypal-webhook', () => {
const wrapper = await createWrapper();

wrapper.vm.createNotificationError = jest.fn();
// eslint-disable-next-line prefer-promise-reject-errors
wrapper.vm.SwagPayPalWebhookService.register = jest.fn(() => Promise.reject({ response: {} }));

wrapper.vm.onRefreshWebhook();
Expand Down

0 comments on commit 3b538d7

Please sign in to comment.