Skip to content

Commit

Permalink
Merge pull request #66 from internetarchive/false-positive-diff-util-…
Browse files Browse the repository at this point in the history
…tests

Add unit tests for false-positive-diff-util
  • Loading branch information
vbanos committed Mar 27, 2019
2 parents 9291fec + 531a6f0 commit 6f03b6a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"eslint": "^4.19.1",
"eslint-plugin-mocha": "^5.0.0",
"eslint-plugin-react": "^7.12.3",
"jsdom": "^12.2.0",
"rollup": "^1.7.3",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^9.1.3",
Expand Down
67 changes: 67 additions & 0 deletions src/components/__tests__/fast-positive-diff-util.test.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/components/__tests__/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md
// Used to include headless DOM
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);
module.exports = {jsdom: jsdom};
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ export function getTimestampCleanDiff(insertions, deletions) {
return {insertions: domIns.outerHTML, deletions: domDel.outerHTML};
}

function getLinkFromElement (hasLink) {
export function getLinkFromElement (hasLink) {
if (!_.isNil(hasLink.src))
return hasLink.src;
if (!_.isNil(hasLink.href))
return hasLink.href;
return hasLink.action;
}

function isNotAResource (element) {
export function isNotAResource (element) {
return (!element.src && !element.href && !element.action);
}

function checkTimestampInLink (element) {
export function checkTimestampInLink (element) {
let link = getLinkFromElement(element);
if (_.isNil(link)) {
link = getLinkFromElement(element.parentNode.parentNode);
Expand Down Expand Up @@ -169,7 +169,7 @@ function addNotNill (array, element) {
}
}

function getWBMCleanURL (element) {
export function getWBMCleanURL (element) {
if (!_.isNil(element.src))
return removeWBM(element.src);
if (!_.isNil(element.href))
Expand All @@ -178,12 +178,14 @@ function getWBMCleanURL (element) {
return removeWBM(element.action);
}

function removeWBM (url){
export function removeWBM (url){
let urlArray = url.split('/');
urlArray = urlArray.slice(7);
return urlArray.join('/');
}
function removeDiffXPATH (xpath, mode){

// mode can be 'ins' or 'del'
export function removeDiffXPATH (xpath, mode){
let xpathArray = xpath.split('/');
for (let i = 0, len = xpathArray.length; i < len; i++) {
if (xpathArray[i].includes(mode+'[')){
Expand All @@ -193,7 +195,7 @@ function removeDiffXPATH (xpath, mode){
}
}

function normalizeURL (url) {
export function normalizeURL (url) {
let lowercaseString = url.toLowerCase();
if (lowercaseString.startsWith('/www.')){
return '/' + url.slice(5);
Expand Down
2 changes: 1 addition & 1 deletion src/components/side-by-side-rendered-diff.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import SandboxedHtml from './sandboxed-html.jsx';
import {getTimestampCleanDiff} from './false-positive-diff-util.jsx';
import {getTimestampCleanDiff} from './false-positive-diff-util.js';

const showRemovals = showType.bind(null, 'removals');
const showAdditions = showType.bind(null, 'additions');
Expand Down

0 comments on commit 6f03b6a

Please sign in to comment.