-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from xsolla/PAYMENTS-17869
feat(PAYMENTS-17869): QR code component
- Loading branch information
Showing
8 changed files
with
124 additions
and
16 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
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,5 @@ | ||
import { Action } from './action.interface'; | ||
|
||
export type ShowQrCodeActionType = 'show_qr_code'; | ||
|
||
export type ShowQrCodeAction = Action<ShowQrCodeActionType, null>; |
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
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
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
61 changes: 61 additions & 0 deletions
61
src/features/headless-checkout/web-components/qr-code/qr-code.component.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,61 @@ | ||
import { container } from 'tsyringe'; | ||
import { HeadlessCheckoutSpy } from '../../../../core/spy/headless-checkout-spy/headless-checkout-spy'; | ||
import { WebComponentTagName } from '../../../../core/web-components/web-component-tag-name.enum'; | ||
import { noopStub } from '../../../../tests/stubs/noop.stub'; | ||
import { HeadlessCheckout } from '../../headless-checkout'; | ||
import { QrCodeComponent } from './qr-code.component'; | ||
|
||
class HeadlessCheckoutMock { | ||
public events = { | ||
onCoreEvent: noopStub, | ||
}; | ||
} | ||
|
||
function createComponent(): void { | ||
const element = document.createElement(WebComponentTagName.QrCodeComponent); | ||
|
||
(document.getElementById('container')! as HTMLElement).appendChild(element); | ||
} | ||
|
||
describe('QrCodeComponent', () => { | ||
let headlessCheckout: HeadlessCheckoutMock; | ||
let headlessCheckoutSpy: HeadlessCheckoutSpy; | ||
|
||
window.customElements.define( | ||
WebComponentTagName.QrCodeComponent, | ||
QrCodeComponent, | ||
); | ||
|
||
beforeEach(() => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
|
||
headlessCheckout = new HeadlessCheckoutMock(); | ||
headlessCheckoutSpy = { | ||
listenAppInit: noopStub, | ||
get appWasInit() { | ||
return; | ||
}, | ||
} as unknown as HeadlessCheckoutSpy; | ||
|
||
container.clearInstances(); | ||
|
||
container | ||
.register<HeadlessCheckoutSpy>(HeadlessCheckoutSpy, { | ||
useValue: headlessCheckoutSpy, | ||
}) | ||
.register<HeadlessCheckout>(HeadlessCheckout, { | ||
useValue: headlessCheckout as unknown as HeadlessCheckout, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.innerHTML = ''; | ||
}); | ||
|
||
it('Should create component', () => { | ||
createComponent(); | ||
expect( | ||
document.querySelector(WebComponentTagName.QrCodeComponent), | ||
).not.toBeNull(); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/features/headless-checkout/web-components/qr-code/qr-code.component.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,31 @@ | ||
import { SecureComponentAbstract } from '../../../../core/web-components/secure-component/secure-component.abstract'; | ||
import { EventName } from '../../../../core/event-name.enum'; | ||
import { finishLoadComponentHandler } from '../../post-messages-handlers/finish-load-component.handler'; | ||
import { container } from 'tsyringe'; | ||
import { HeadlessCheckout } from '../../headless-checkout'; | ||
|
||
export class QrCodeComponent extends SecureComponentAbstract { | ||
protected componentName = 'qr-code'; | ||
private readonly headlessCheckout: HeadlessCheckout; | ||
|
||
public constructor() { | ||
super(); | ||
this.headlessCheckout = container.resolve(HeadlessCheckout); | ||
} | ||
|
||
protected connectedCallback(): void { | ||
this.startLoadingComponentHandler(); | ||
|
||
this.headlessCheckout.events.onCoreEvent( | ||
EventName.finishLoadComponent, | ||
finishLoadComponentHandler, | ||
() => this.finishLoadingComponentHandler('qr-code'), | ||
); | ||
|
||
super.connectedCallback(); | ||
} | ||
|
||
protected getHtml(): string { | ||
return this.getSecureHtml(); | ||
} | ||
} |
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