-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,527 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...ion/src/app/component/swag-paypal-onboarding-button/swag-paypal-onboarding-button.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import SwagPayPalOnboardingButton from '.'; | ||
|
||
Shopware.Component.register('swag-paypal-onboarding-button', Promise.resolve(SwagPayPalOnboardingButton)); | ||
|
||
async function loadScript(script: Element) { | ||
window.PAYPAL = { | ||
apps: { | ||
// @ts-expect-error - not fully implemented on purpose | ||
Signup: { | ||
setup: jest.fn(), | ||
render: jest.fn(), | ||
}, | ||
}, | ||
}; | ||
|
||
script.dispatchEvent(new Event('load')); | ||
|
||
await flushPromises(); | ||
} | ||
|
||
async function createWrapper() { | ||
return mount( | ||
await Shopware.Component.build('swag-paypal-onboarding-button') as typeof SwagPayPalOnboardingButton, | ||
{ | ||
global: { | ||
mocks: { $t: (key: string) => key }, | ||
provide: { | ||
acl: { can: () => true }, | ||
SwagPayPalSettingsService: { | ||
getApiCredentials: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
describe('swag-paypal-onboarding-button', () => { | ||
it('should be a Vue.js component', async () => { | ||
const wrapper = await createWrapper(); | ||
|
||
expect(wrapper.vm).toBeTruthy(); | ||
}); | ||
|
||
it('should initialize component', async () => { | ||
const wrapper = await createWrapper(); | ||
|
||
const renderSpy = jest.spyOn(wrapper.vm, 'renderPayPalButton'); | ||
|
||
const script = document.head.querySelector('#paypal-js'); | ||
expect(script).toBeTruthy(); | ||
await loadScript(script!); | ||
|
||
expect(renderSpy).toHaveBeenCalled(); | ||
expect(window.PAYPAL!.apps.Signup.render).toHaveBeenCalled(); | ||
expect(window.PAYPAL!.apps.Signup.setup).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set config', async () => { | ||
const wrapper = await createWrapper(); | ||
const store = Shopware.Store.get('swagPayPalSettings'); | ||
|
||
store.setConfig(null, {}); | ||
wrapper.setProps({ type: 'live' }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.suffix).toBe(''); | ||
wrapper.vm.setConfig('client-id', 'client-secret', 'payer-id'); | ||
|
||
expect(store.allConfigs).toStrictEqual({ | ||
null: { | ||
'SwagPayPal.settings.clientId': 'client-id', | ||
'SwagPayPal.settings.clientSecret': 'client-secret', | ||
'SwagPayPal.settings.merchantPayerId': 'payer-id', | ||
'SwagPayPal.settings.sandbox': false, | ||
}, | ||
}); | ||
|
||
store.setConfig(null, {}); | ||
wrapper.setProps({ type: 'sandbox' }); | ||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.suffix).toBe('Sandbox'); | ||
wrapper.vm.setConfig('client-id', 'client-secret', 'payer-id'); | ||
|
||
expect(store.allConfigs).toStrictEqual({ | ||
null: { | ||
'SwagPayPal.settings.clientIdSandbox': 'client-id', | ||
'SwagPayPal.settings.clientSecretSandbox': 'client-secret', | ||
'SwagPayPal.settings.merchantPayerIdSandbox': 'payer-id', | ||
'SwagPayPal.settings.sandbox': true, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.