From 33428d86230064d70ec6b2a638f947d0cdb31968 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:35:26 -0600 Subject: [PATCH] fix(heading-order): handle iframe as first result (#2876) --- lib/checks/navigation/heading-order-after.js | 5 +- test/checks/navigation/heading-order.js | 53 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/checks/navigation/heading-order-after.js b/lib/checks/navigation/heading-order-after.js index b23c039353..14cb93acce 100644 --- a/lib/checks/navigation/heading-order-after.js +++ b/lib/checks/navigation/heading-order-after.js @@ -34,10 +34,11 @@ function headingOrderAfter(results) { // start by replacing all array ancestry paths with a flat string // path - let headingOrder = results[0].data.headingOrder.map(heading => { + const pageResult = results.find(result => !result.node._fromFrame); + let headingOrder = pageResult.data.headingOrder.map(heading => { return { ...heading, - ancestry: getFramePath(results[0].node.ancestry, heading.ancestry) + ancestry: getFramePath(pageResult.node.ancestry, heading.ancestry) }; }); diff --git a/test/checks/navigation/heading-order.js b/test/checks/navigation/heading-order.js index f37b6b9f8d..944dd6543e 100644 --- a/test/checks/navigation/heading-order.js +++ b/test/checks/navigation/heading-order.js @@ -522,5 +522,58 @@ describe('heading-order', function() { checks['heading-order'].after(results); }); }); + + it('should not error if iframe is first result', function() { + var results = [ + { + data: { + headingOrder: [ + { + ancestry: 'path2', + level: 1 + } + ] + }, + node: { + _fromFrame: true, + ancestry: ['iframe', 'path2'] + }, + result: true + }, + { + data: { + headingOrder: [ + { + ancestry: 'iframe', + level: -1 + }, + { + ancestry: 'path1', + level: 2 + }, + { + ancestry: 'path3', + level: 3 + } + ] + }, + node: { + _fromFrame: false, + ancestry: ['path1'] + }, + result: true + }, + { + node: { + _fromFrame: false, + ancestry: ['path3'] + }, + result: true + } + ]; + var afterResults = checks['heading-order'].after(results); + assert.isTrue(afterResults[1].result); + assert.isTrue(afterResults[2].result); + }); }); });