UNPKG

accessibility-checker

Version:

An automated testing tools for accessibility testing using Puppeteer, Selenium, or Zombie

190 lines (187 loc) 8.33 kB
"use strict"; /****************************************************************************** Copyright:: 2020- IBM, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiScanData = void 0; var stringHash = require("string-hash"); var MultiScanData = /** @class */ (function () { function MultiScanData(config) { this.Config = config; } // this class barrows heavily from singlePageReport // however, our purpose here is just to generate the data // needed for a multiScanReport which will replace singlePageReport // also when saving scans we will be saving a reduced set of the // scan data which is the smallest set of data needed for a // multiScanReport // more specifically we will only store the data for the issue // sheet as all other data is either static or can be calculated // from the issue data MultiScanData.prototype.issues_sheet_rows = function (xlsx_props) { var ret = []; var report = xlsx_props.report; var tab_url = xlsx_props.tabURL; var tab_title = xlsx_props.tabTitle; var engine_end_point = xlsx_props.helpPath; // const engine_end_point = "process.env.engineEndpoint"; var rule_map = MultiScanData.id_rule_map(xlsx_props); var rule_checkpoints_map = MultiScanData.ruleId_checkpoints_map(xlsx_props); var valueMap = { "VIOLATION": { "POTENTIAL": "Needs review", "FAIL": "Violation", "PASS": "Pass", "MANUAL": "Needs review" }, "RECOMMENDATION": { "POTENTIAL": "Recommendation", "FAIL": "Recommendation", "PASS": "Pass", "MANUAL": "Recommendation" }, "INFORMATION": { "POTENTIAL": "Needs review", "FAIL": "Violation", "PASS": "Pass", "MANUAL": "Recommendation" } }; if (report == null) { return []; } for (var _i = 0, _a = report.results; _i < _a.length; _i++) { var item = _a[_i]; if (item.value[1] === "PASS") { continue; } var test = MultiScanData.checkpoints_string(rule_checkpoints_map, item.ruleId); var test2 = MultiScanData.wcag_string(rule_checkpoints_map, item.ruleId); MultiScanData.get_element(item.snippet); MultiScanData.format_date(report.timestamp); stringHash(item.ruleId + item.path.dom); parseInt(rule_map.get(item.ruleId).toolkitLevel); var row = [ tab_title, tab_url, MultiScanData.format_date(report.timestamp), stringHash(item.ruleId + item.path.dom), valueMap[item.value[0]][item.value[1]], parseInt(rule_map.get(item.ruleId).toolkitLevel), MultiScanData.checkpoints_string(rule_checkpoints_map, item.ruleId), MultiScanData.wcag_string(rule_checkpoints_map, item.ruleId), item.ruleId, item.message.substring(0, 32767), MultiScanData.get_element(item.snippet), item.snippet, item.path.aria, // engine_end_point + '/tools/help/' + item.ruleId engine_end_point + item.ruleId + ".html" ]; ret.push(row); } return ret; }; MultiScanData.checkpoints_string = function (rule_checkpoints_map, rule_id) { var checkpoint_string = ''; var checkpoint_array = rule_checkpoints_map.get(rule_id); for (var _i = 0, checkpoint_array_1 = checkpoint_array; _i < checkpoint_array_1.length; _i++) { var checkpoint = checkpoint_array_1[_i]; if (checkpoint_string.length > 1) { checkpoint_string = checkpoint_string + '; '; } checkpoint_string = checkpoint_string + checkpoint.num + ' ' + checkpoint.name; } return checkpoint_string; }; MultiScanData.wcag_string = function (rule_checkpoints_map, rule_id) { var wcag_string = ''; var checkpoint_array = rule_checkpoints_map.get(rule_id); for (var _i = 0, checkpoint_array_2 = checkpoint_array; _i < checkpoint_array_2.length; _i++) { var checkpoint = checkpoint_array_2[_i]; if (wcag_string.length > 0) { wcag_string = wcag_string + '; '; } wcag_string = wcag_string + checkpoint.wcagLevel; } return wcag_string; }; MultiScanData.id_rule_map = function (xlsx_props) { var ruleset = xlsx_props.report.ruleset; var checkpoints = ruleset.checkpoints; var rule_map = new Map(); for (var _i = 0, checkpoints_1 = checkpoints; _i < checkpoints_1.length; _i++) { var checkpoint = checkpoints_1[_i]; var rules = checkpoint.rules; if (rules && rules.length > 0) { for (var _a = 0, rules_1 = rules; _a < rules_1.length; _a++) { var rule = rules_1[_a]; if (!rule_map.get(rule.id)) { rule_map.set(rule.id, rule); } } } } return rule_map; }; MultiScanData.ruleId_checkpoints_map = function (xlsx_props) { // const guideline_id = xlsx_props.report.option.guideline.id; //ruleset used for scanning // const ruleset = xlsx_props.rulesets.find((element: any) => element.id == guideline_id); var ruleset = xlsx_props.report.ruleset; var checkpoints = ruleset.checkpoints; var checkpoint_map = new Map(); for (var _i = 0, checkpoints_2 = checkpoints; _i < checkpoints_2.length; _i++) { var checkpoint = checkpoints_2[_i]; var temp_checkpoint = { name: checkpoint.name, num: checkpoint.num, summary: checkpoint.summary, wcagLevel: checkpoint.wcagLevel }; var rules = checkpoint.rules; if (rules && rules.length > 0) { for (var _a = 0, rules_2 = rules; _a < rules_2.length; _a++) { var rule = rules_2[_a]; if (!checkpoint_map.get(rule.id)) { checkpoint_map.set(rule.id, [temp_checkpoint]); } else { var checkpoint_array = checkpoint_map.get(rule.id); checkpoint_array.push(temp_checkpoint); checkpoint_map.set(rule.id, checkpoint_array); } } } } return checkpoint_map; }; MultiScanData.get_element = function (code) { if (code) { var ind_s = code.indexOf(' '); var ind_br = code.indexOf('>'); return (ind_s > 0 && ind_s < ind_br) ? code.substring(1, ind_s) : code.substring(1, ind_br); } return ''; }; MultiScanData.format_date = function (timestamp) { var date = new Date(timestamp); return date.getFullYear() + '-' + ("00" + (date.getMonth() + 1)).slice(-2) + "-" + ("00" + date.getDate()).slice(-2) + "-" + ("00" + date.getHours()).slice(-2) + "-" + ("00" + date.getMinutes()).slice(-2) + "-" + ("00" + date.getSeconds()).slice(-2); }; return MultiScanData; }()); exports.MultiScanData = MultiScanData; //# sourceMappingURL=multiScanData.js.map