Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide divider if no giftcards enabled #935

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Render Generic Component should hide giftcard container 1`] = `
{
"amount": "mocked_amount",
"countryCode": "mocked_countrycode",
"paymentMethodsConfiguration": {
"amazonpay": {
"addressDetails": {
"addressLine1": "test",
"city": "test",
"countryCode": "test",
"name": "test test",
"phoneNumber": "test",
"postalCode": "test",
"stateOrRegion": "test",
},
"configuration": undefined,
},
},
"session": {
"adyenDescriptions": {},
"id": "mock_id",
"imagePath": "example.com",
"sessionData": "mock_session_data",
},
}
`;

exports[`Render Generic Component should render 1`] = `
{
"amount": "mocked_amount",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@ const { renderGenericComponent } = require('../renderGenericComponent');
const { createSession } = require('../../commons');
const { fetchGiftCards } = require('../../commons');
const store = require('../../../../../store');
const giftCardHtml = `
<div id="paymentMethodsList"></div>
<input type="radio" name="brandCode" value="card" />
<button value="submit-payment">Submit</button>
<div id="component_card"></div>
<div class="gift-card-selection"></div>
<div class="gift-card-separator"></div>
<div id="adyenPosTerminals">
<span>Child #1</span>
</div>
<div>
<input type="text" id="shippingFirstNamedefault" value="test">
<input type="text" id="shippingLastNamedefault" value="test">
<input type="text" id="shippingAddressOnedefault" value="test">
<input type="text" id="shippingAddressCitydefault" value="test">
<input type="text" id="shippingZipCodedefault" value="test">
<input type="text" id="shippingCountrydefault" value="test">
<input type="text" id="shippingPhoneNumberdefault" value="test">
<input type="text" id="shippingZipCodedefault" value="test">
</div>
`;
const availableGiftCards = {
giftCards: [
{
orderAmount: {
currency: '',
value: '',
},
},
],
}

beforeEach(() => {
window.AdyenCheckout = jest.fn(async () => ({
Expand Down Expand Up @@ -35,41 +66,11 @@ beforeEach(() => {
imagePath: 'example.com',
adyenDescriptions: {},
});

fetchGiftCards.mockReturnValue({
giftCards: [
{
orderAmount: {
currency: '',
value: '',
},
},
],
});
});
describe('Render Generic Component', () => {
it('should render', async () => {
document.body.innerHTML = `
<div id="paymentMethodsList"></div>
<input type="radio" name="brandCode" value="card" />
<button value="submit-payment">Submit</button>
<div id="component_card"></div>
<div class="gift-card-selection"></div>
<div id="adyenPosTerminals">
<span>Child #1</span>
</div>
<div>
<input type="text" id="shippingFirstNamedefault" value="test">
<input type="text" id="shippingLastNamedefault" value="test">
<input type="text" id="shippingAddressOnedefault" value="test">
<input type="text" id="shippingAddressCitydefault" value="test">
<input type="text" id="shippingZipCodedefault" value="test">
<input type="text" id="shippingCountrydefault" value="test">
<input type="text" id="shippingPhoneNumberdefault" value="test">
<input type="text" id="shippingZipCodedefault" value="test">
</div>
`;

fetchGiftCards.mockReturnValue(availableGiftCards);
document.body.innerHTML = giftCardHtml;
store.componentsObj = { foo: 'bar', bar: 'baz' };
store.checkoutConfiguration.paymentMethodsConfiguration = { amazonpay: {} };
await renderGenericComponent();
Expand All @@ -79,4 +80,20 @@ describe('Render Generic Component', () => {
document.querySelector('input[type=radio][name=brandCode]').value,
).toBeTruthy();
});

it('should hide giftcard container', async () => {
fetchGiftCards.mockReturnValue({ giftCards: [] });
document.body.innerHTML = giftCardHtml;
store.componentsObj = { foo: 'bar', bar: 'baz' };
store.checkoutConfiguration.paymentMethodsConfiguration = { amazonpay: {} };
await renderGenericComponent();
expect(createSession).toBeCalled();
expect(store.checkoutConfiguration).toMatchSnapshot();
expect(
document.querySelector('.gift-card-selection').style.display,
).toEqual('none');
expect(
document.querySelector('.gift-card-separator').style.display,
).toEqual('none');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ function setGiftCardContainerVisibility() {
if (availableGiftCards.length === 0) {
const giftCardContainer = document.querySelector('.gift-card-selection');
giftCardContainer.style.display = 'none';
const giftCardSeparator = document.querySelector('.gift-card-separator');
giftCardSeparator.style.display = 'none';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<input id="selectedIssuer" type="hidden" name="${adyenPaymentFields.issuer.htmlName}"/>

<ul id="paymentMethodsList" class="payment-methods-container"></ul>
<div class="adyen-checkout__content-separator adyen-checkout-ctp__separator">
<div class="gift-card-separator adyen-checkout__content-separator adyen-checkout-ctp__separator">
${Resource.msg('separator.giftCard', 'adyen', null)}
</div>
<div class="gift-card-selection">
Expand Down