Skip to content

Commit

Permalink
Adding test cases for PHP errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltan-dulac committed Feb 7, 2023
1 parent 6bde9ef commit 18bb9a7
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
17 changes: 4 additions & 13 deletions content/body/carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,11 @@ class="enable-mobile-visible-on-focus enable-skip-link">Skip to
"notes": "After we create the carousel, we add three events: a focus event to capture when a CTA in a slide gains focus, a mouse event to detect when the mouse is used, and a key event to detect when the TAB key is pressed."
},
{
"label": "Carousel slide focus event",
"highlight": "%FILE% ./js/modules/enable-carousel.js ~ this.slideToTarget =",
"notes": "When a CTA in a slide gains focus, we tell the carousel to display the slide that contains that CTA"
},
{
"label": "Carousel mouse event",
"highlight": "%FILE% ./js/modules/enable-carousel.js ~ this.clickHandler =",
"notes": "When the user clicks the CTA, we assume they are a mouse user so we allow the carousel to animate between slides."
},
{
"label": "Carousel key up event",
"highlight": "%FILE% ./js/modules/enable-carousel.js ~ this.keyUpHandler =",
"notes": "When the user hits the TAB key, we assume they are a keyboard user and tell the carousel to turn animations off."
"label": "Set up events the manage focus when a new slide comes into view.",
"highlight": "%FILE% ./js/modules/enable-carousel.js ~ \\s*// Sets events for the \"List of Content\" ([\\s\\S]*?\\};)",
"notes": "<p>When a slide comes into view, focus is applied to it (or to the first keyboard accessible control inside of it). When a slide is hidden, it is marked as <code>inert</code> so keyboard focus is never applied to it or its children.</p><p>Note as well that we ensure that when the previous and next buttons are pressed with the Enter key, it prevents page scrolling. Just preventing a small annoyance that some keyboard users have had in the past.</p>"
}

]
}
</script>
Expand Down
8 changes: 5 additions & 3 deletions js/modules/enable-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ const EnableCarousel = function (container, options) {
if (this.useArrowButtons) {
import('../../enable-node-libs/accessibility-js-routines/dist/accessibility.module.js')
.then((accessibilityObj) => {

accessibility = accessibilityObj.default;
console.log('loaded accessibility', accessibility);

// If the inert attribute is not supported by this browser, then load
// the polyfill before using it.
if (!supportsInertNatively) {
Expand All @@ -72,6 +73,7 @@ const EnableCarousel = function (container, options) {
} else {
this.setArrowButtonEvents();
}

});
// If userArrowButtons is *not* set as an option, just initialize the event
// handler routines.
Expand Down Expand Up @@ -110,8 +112,8 @@ const EnableCarousel = function (container, options) {
// Let's make all the carousel panels inert except the first one.
this.setSlidesInert(true, 0);

// We should ensure the first
// CTA inside the visible panel gains focus when it first comes into view.
// This ensures when the slide comes into view, that focus is applied to it
// (or inside of it if it has an interactive element).
this.container.addEventListener("glider-slide-visible", this.slideVisibleEvent);
this.container.addEventListener("glider-slide-hidden", this.slideHiddenEvent);

Expand Down
8 changes: 5 additions & 3 deletions js/modules/es4/enable-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ const EnableCarousel = function (container, options) {
if (this.useArrowButtons) {
import('../../enable-node-libs/accessibility-js-routines/dist/accessibility.module.js')
.then((accessibilityObj) => {

accessibility = accessibilityObj.default;
console.log('loaded accessibility', accessibility);

// If the inert attribute is not supported by this browser, then load
// the polyfill before using it.
if (!supportsInertNatively) {
Expand All @@ -71,6 +72,7 @@ const EnableCarousel = function (container, options) {
} else {
this.setArrowButtonEvents();
}

});
// If userArrowButtons is *not* set as an option, just initialize the event
// handler routines.
Expand Down Expand Up @@ -109,8 +111,8 @@ const EnableCarousel = function (container, options) {
// Let's make all the carousel panels inert except the first one.
this.setSlidesInert(true, 0);

// We should ensure the first
// CTA inside the visible panel gains focus when it first comes into view.
// This ensures when the slide comes into view, that focus is applied to it
// (or inside of it if it has an interactive element).
this.container.addEventListener("glider-slide-visible", this.slideVisibleEvent);
this.container.addEventListener("glider-slide-hidden", this.slideHiddenEvent);

Expand Down
68 changes: 68 additions & 0 deletions js/test/phpErrors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict'

import config from './test-config.js';
import testHelpers from './test-helpers.js';
import fs from 'fs';

const fileList = testHelpers.getPageList();
let mobileBrowser, mobilePage, desktopBrowser, desktopPage;

describe('Test for PHP errors on all pages on Enable', () => {
beforeAll(async () => {
// Put code here that should execute before starting tests.
desktopBrowser = await testHelpers.getDesktopBrowser();
desktopPage = await desktopBrowser.newPage();
});

afterAll(async () => {
await desktopBrowser.close();
});

async function testPage(filename, page) {
let domInfo;

await page.goto(`${config.BASE_URL}/${filename}`);

// Test on initial load.

// Step 1: Wait for whole page to load (this is so scripts
// like `enable-visible-on-focus` can initialize)
await page.waitForSelector('footer');


//await testHelpers.fastPause();
domInfo = await page.evaluate(() => {
const { body } = document;
const { innerHTML } = body;
let PHPErrors = innerHTML.match(/Warning:[^<]* on line [0-9]+/);

if (PHPErrors === null) {
PHPErrors = [];
}

return {
PHPErrors
}

});

//console.log(`checking `, domInfo.html, domInfo.parentClass);
// Step 4: Do Tests ... but not on enable skip link (we'll handle that
// someplace else)
if (domInfo.PHPErrors.length > 0) {
console.log(`PHP Errors in ${filename}:`, domInfo.PHPErrors);
}

expect(domInfo.PHPErrors.length).toBe(0);
}



for (let i=0; i<fileList.length; i++) {
const file = fileList[i];
it(`Desktop Breakpoint: Test PHP errors on ${fileList[i]}`, async () => {
await testPage(fileList[i], desktopPage);
});
}

});
7 changes: 5 additions & 2 deletions templates/includes/npm.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@
import '~enable-a11y/css/<?= $moduleName ?>';
<?php
}
if (!$noInit) {
if (!$noInit && ($other["customInit"] ?? '') != '') {
?>
// How to initialize the <?= $moduleVar ?> library
<?= $moduleVar ?>.init();
<?php
} else {
}

if ($noInit)
{
?>
// There is no .init() function to call.
<?php
Expand Down

0 comments on commit 18bb9a7

Please sign in to comment.