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

chore: add language options #35

Merged
merged 2 commits into from
Sep 12, 2024
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
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default defineConfig({
baseUrl: 'http://0.0.0.0:4200',
reactiveFormUrl: 'http://0.0.0.0:4200/reactive-form-example',
templateDrivenFormUrl: 'http://0.0.0.0:4200/template-driven-form-example',
languageOptionUrl: 'http://0.0.0.0:4200/language-option-example',
},
e2e: {
setupNodeEvents(on, config) {
Expand Down
14 changes: 14 additions & 0 deletions cypress/e2e/ngx-turnstile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ describe('tests the ngx-turnstile library', () => {
'[Cloudflare Turnstile] Turnstile already has been loaded. Was Turnstile imported multiple times?.',
);
});

it('Passes Language Option Example', () => {
cy.visit(Cypress.env('languageOptionUrl'));
cy.wait(3000);
cy.get('ngx-turnstile').should('have.attr', 'ng-reflect-language', 'FR');

// checks the iframe src attribute to make sure the language option was sent to cloudflare correctly
cy.get('ngx-turnstile div')
.shadow()
.find('iframe')
.then(($iframe) => {
cy.wrap($iframe).should('have.attr', 'src').and('include', 'FR');
});
});
});
6 changes: 6 additions & 0 deletions projects/ngx-turnstile-demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ import { RouterModule } from '@angular/router';
[routerLinkActive]="['route-active']"
>Template Driven Form Example</a
>

<a
routerLink="/language-option-example"
[routerLinkActive]="['route-active']"
>Language Option Example</a
>
</div>
<main class="form-signin">
<form action="https://demo.turnstile.workers.dev/handler" method="POST">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from '@angular/core';
import { NgxTurnstileModule } from 'ngx-turnstile';

@Component({
selector: 'app-regular-example',
standalone: true,
template: `
<ng-container>
<ngx-turnstile
[siteKey]="siteKey"
theme="light"
[language]="language"
></ngx-turnstile>
</ng-container>
`,
imports: [NgxTurnstileModule],
})
export class LanguageOptionComponent {
siteKey = '1x00000000000000000000AA';
language = 'FR';
}
6 changes: 6 additions & 0 deletions projects/ngx-turnstile-demo/src/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Routes } from '@angular/router';
import { EventBindingExampleComponent } from './examples/event-binding/event-binding-example.component';
import { ReactiveFormExampleComponent } from './examples/reactive-form/reactive-form-example.component';
import { TemplateDrivenFormExampleComponent } from './examples/template-driven-form/template-driven-form-example.component';
import { LanguageOptionComponent } from './examples/language-option/language-option.component';

export const APP_ROUTES: Routes = [
{
Expand All @@ -15,6 +16,11 @@ export const APP_ROUTES: Routes = [
component: ReactiveFormExampleComponent,
title: 'Reactive Form Example',
},
{
path: 'language-option-example',
component: LanguageOptionComponent,
title: 'Language Option Example',
},
{
path: 'template-driven-form-example',
component: TemplateDrivenFormExampleComponent,
Expand Down
11 changes: 11 additions & 0 deletions projects/ngx-turnstile-demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { APP_ROUTES } from './app/routes';

import { environment } from './environments/environment';

function overWriteAttachShadowToPreventClosedShadowDoms() {
const og = HTMLDivElement.prototype.attachShadow;
HTMLDivElement.prototype.attachShadow = function (options: ShadowRootInit) {
if (options.mode === 'closed') {
options.mode = 'open';
}
return og.call(this, options);
};
}
overWriteAttachShadowToPreventClosedShadowDoms(); // Open shadow DOMS to enable cypress testing

if (environment.production) {
enableProdMode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface TurnstileOptions {
'error-callback'?: (errorCode: string) => boolean;
'expired-callback'?: () => void;
theme?: 'light' | 'dark' | 'auto';
language?: string;
tabindex?: number;
appearance?: 'always' | 'execute' | 'interaction-only';
}
2 changes: 2 additions & 0 deletions projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class NgxTurnstileComponent implements AfterViewInit, OnDestroy {
@Input() action?: string;
@Input() cData?: string;
@Input() theme?: 'light' | 'dark' | 'auto' = 'auto';
@Input() language?: string = 'auto';
@Input() version: SupportedVersion = '0';
@Input() tabIndex?: number;
@Input() appearance?: 'always' | 'execute' | 'interaction-only' = 'always';
Expand Down Expand Up @@ -70,6 +71,7 @@ export class NgxTurnstileComponent implements AfterViewInit, OnDestroy {
let turnstileOptions: TurnstileOptions = {
sitekey: this.siteKey,
theme: this.theme,
language: this.language,
tabindex: this.tabIndex,
action: this.action,
cData: this.cData,
Expand Down
Loading