Skip to content

Commit

Permalink
test: add cypress test for language options
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderBodurri committed Sep 12, 2024
1 parent a0510c4 commit 3634906
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
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 @@ -12,4 +12,18 @@ describe('tests the ngx-turnstile library', () => {
cy.wait(3000);
cy.contains('Value: XXXX.DUMMY.TOKEN.XXXX');
});

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

0 comments on commit 3634906

Please sign in to comment.