Skip to content

Commit

Permalink
Add tests for translation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGillespie committed Mar 11, 2024
1 parent 53bcb6a commit 5805261
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
58 changes: 58 additions & 0 deletions cypress/e2e/pf-iframe.technical.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,63 @@ for (const config of runConfigurations) {
});

});

describe('translation', () => {
it('english translation is applied', () => {
cy.visit(config.baseUrl);

cy.get('pf-iframe').invoke('text').should('contain', 'By continuing, you consent');
cy.get('button').invoke('text').should('contain', 'Yes, proceed');
});

it('english templates successfully', () => {
cy.visit(config.baseUrl);

cy.get('pf-iframe').invoke('text').should('contain', config.youtubeUrl);
cy.get('pf-iframe').invoke('text').should('contain', ' www.youtube.com.');
});

it('translation passed to window is applied', () => {
cy.visit(config.noTranslationUrl, {
onBeforeLoad: (win: TestWindow) => {
win._pfiFrameConfig = {
translation: {
consentPromptMessage: 'This is a custom message',
consentButtonLabel: 'Custom label',
},
};
},
});

cy.get('pf-iframe').invoke('text').should('contain', 'This is a custom message');
cy.get('button').invoke('text').should('contain', 'Custom label');

cy.get('pf-iframe').invoke('text').should('not.contain', 'By continuing, you consent');
cy.get('button').invoke('text').should('not.contain', 'Yes, proceed');

// Checking that no template is applied as well as non is given
cy.get('pf-iframe').invoke('text').should('not.contain', 'youtube');
cy.get('button').invoke('text').should('not.contain', 'youtube');
});

it('templating works with custom translation', () => {
cy.visit(config.noTranslationUrl, {
onBeforeLoad: (win: TestWindow) => {
win._pfiFrameConfig = {
translation: {
consentPromptMessage: 'This is the src: ${src}. This is the domain: ${domain}.',
consentButtonLabel: 'This is the src: ${src}. This is the domain: ${domain}.',
},
};
},
});

cy.get('pf-iframe').invoke('text').should('contain', config.youtubeUrl);
cy.get('pf-iframe').invoke('text').should('contain', ' www.youtube.com.');

cy.get('button').invoke('text').should('contain', config.youtubeUrl);
cy.get('button').invoke('text').should('contain', ' www.youtube.com.');
});
})
});
}
3 changes: 1 addition & 2 deletions cypress/e2e/run-configurations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const runConfigurations = [
// {baseUrl: '/lib/', name: 'Library'},
{baseUrl: '/', name: 'Production'},
{name: 'Production', baseUrl: '/', noTranslationUrl: '/no-translation.html', youtubeUrl: 'https://www.youtube.com/embed/bHQqvYy5KYo?si=qwupSWrLGQcMmRMI'},
]

export const attributeMap = [
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/util/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PFIFrameConfig } from '../../../src/types';
import { PFIFrameConfig, PFIFrameTranslation } from '../../../src/types';
export type TestWindow = {
executed: boolean;
caughtData: any;
Expand All @@ -7,5 +7,6 @@ export type TestWindow = {
byId?: {
[id: string]: PFIFrameConfig;
};
translation?: PFIFrameTranslation;
};
} & Cypress.AUTWindow;
17 changes: 17 additions & 0 deletions test/no-translation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<script src="/pf-iframe/pf-iframe.min.js"></script>
<link rel="stylesheet" href="/pf-iframe/pf-iframe.min.css">
</link>
</head>

<body>
<pf-iframe id="test-pf-iframe" width="560" height="315" src="https://www.youtube.com/embed/bHQqvYy5KYo?si=qwupSWrLGQcMmRMI"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></pf-iframe>
</body>

</html>

0 comments on commit 5805261

Please sign in to comment.