-
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.
- Loading branch information
Showing
18 changed files
with
153 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'reflect-metadata'; | ||
import { container } from 'tsyringe'; | ||
import { FormSpy } from './form-spy'; | ||
|
||
class Observer { | ||
public formInitHandler(): void { | ||
return; | ||
} | ||
} | ||
|
||
describe('FormSpy', () => { | ||
let formSpy: FormSpy; | ||
|
||
beforeEach(() => { | ||
container.clearInstances(); | ||
formSpy = container.createChildContainer().resolve(FormSpy); | ||
}); | ||
|
||
it('Should return true for init form', () => { | ||
formSpy.formWasInit = true; | ||
expect(formSpy.formWasInit).toBeTrue(); | ||
}); | ||
|
||
it('Should call formWasInitHandler', () => { | ||
const observer = new Observer(); | ||
const spy = spyOn(observer, 'formInitHandler'); | ||
formSpy.listenFormInit(observer.formInitHandler); | ||
formSpy.formWasInit = true; | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('Should call formWasInitHandler once', () => { | ||
const observer = new Observer(); | ||
const spy = spyOn(observer, 'formInitHandler'); | ||
formSpy.listenFormInit(observer.formInitHandler); | ||
formSpy.formWasInit = true; | ||
formSpy.formWasInit = true; | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Should call appWasInitHandler once', () => { | ||
const observer = new Observer(); | ||
const spy = spyOn(observer, 'formInitHandler'); | ||
formSpy.listenFormInit(observer.formInitHandler); | ||
formSpy.formWasInit = true; | ||
formSpy.formWasInit = false; | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,29 @@ | ||
import { singleton } from 'tsyringe'; | ||
|
||
@singleton() | ||
export class FormSpy { | ||
private _formWasInit = false; | ||
private readonly _callbacks: Array<() => void> = []; | ||
|
||
public set formWasInit(value: boolean) { | ||
if (this._formWasInit === value) { | ||
return; | ||
} | ||
this._formWasInit = value; | ||
if (value) { | ||
this.formWasInitHandler(); | ||
} | ||
} | ||
|
||
public get formWasInit(): boolean { | ||
return this._formWasInit; | ||
} | ||
|
||
public listenFormInit(callback: () => void): void { | ||
this._callbacks.push(callback); | ||
} | ||
|
||
private formWasInitHandler(): void { | ||
this._callbacks.forEach((callback) => callback()); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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
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
15 changes: 0 additions & 15 deletions
15
src/features/headless-checkout/web-components/card-number/card-number.component.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/features/headless-checkout/web-components/legal/legal.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
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
2 changes: 1 addition & 1 deletion
2
...atures/headless-checkout/web-components/payment-methods/payment-methods.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
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
3 changes: 3 additions & 0 deletions
3
...eatures/headless-checkout/web-components/text-component/text-component-attributes.enum.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,3 @@ | ||
export enum TextComponentAttributes { | ||
name = 'name', | ||
} |
11 changes: 5 additions & 6 deletions
11
...card-number/card-number.component.spec.ts → ...nts/text-component/text.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
41 changes: 41 additions & 0 deletions
41
src/features/headless-checkout/web-components/text-component/text.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,41 @@ | ||
import { SecureComponentAbstract } from '../../../../core/web-components/secure-component/secure-component.abstract'; | ||
import { TextComponentAttributes } from './text-component-attributes.enum'; | ||
import { container } from 'tsyringe'; | ||
import { FormSpy } from '../../../../core/spy/form-spy/form-spy'; | ||
|
||
export class TextComponent extends SecureComponentAbstract { | ||
private readonly formSpy: FormSpy; | ||
public constructor() { | ||
super(); | ||
this.formSpy = container.resolve(FormSpy); | ||
} | ||
|
||
public static get observedAttributes(): string[] { | ||
return [TextComponentAttributes.name]; | ||
} | ||
|
||
protected connectedCallback(): void { | ||
if (!this.formSpy.formWasInit) { | ||
this.formSpy.listenFormInit(() => this.connectedCallback()); | ||
return; | ||
} | ||
|
||
const inputName = this.getAttribute(TextComponentAttributes.name); | ||
if (!inputName) { | ||
return; | ||
} | ||
|
||
this.componentName = `text-input/${inputName}`; | ||
super.render(); | ||
} | ||
|
||
protected attributeChangedCallback(): void { | ||
this.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { SubmitButtonComponent } from './features/headless-checkout/web-components/submit-button/submit-button.component'; | ||
import { CardNumberComponent } from './features/headless-checkout/web-components/card-number/card-number.component'; | ||
import { TextComponent } from './features/headless-checkout/web-components/text-component/text.component'; | ||
import { PaymentMethodsComponent } from './features/headless-checkout/web-components/payment-methods/payment-methods.component'; | ||
import { LegalComponent } from './features/headless-checkout/web-components/legal/legal.component'; | ||
|
||
export { | ||
SubmitButtonComponent, | ||
CardNumberComponent, | ||
TextComponent, | ||
PaymentMethodsComponent, | ||
LegalComponent, | ||
}; |