Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react';
import { mount } from 'enzyme';
import { EditorState, ContentState } from 'draft-js';
import DraftPasteProcessor from 'draft-js/lib/DraftPasteProcessor';
import chai from 'chai';
const expect = chai.expect;
import createRichButtonsPlugin from '../index';
import { MAX_LIST_DEPTH, INLINE_STYLES, BLOCK_TYPES } from '../config/types';
process.env.NODE_ENV = 'test';
const exposedProperties = ['window', 'navigator', 'document'];
const blankEvent = {preventDefault: () => null}
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
// chaiEnzyme needs to be initialised here, so that canUseDOM is set
// to true when react-dom initialises (which chai-enzyme depends upon)
const chaiEnzyme = require('chai-enzyme');
chai.use(chaiEnzyme());
describe('Draft RichButtons Plugin', () => {
const createEditorStateFromHTML = (html) => {
const blocks = DraftPasteProcessor.processHTML(html);
\
\
\
<p id="\"para1\"">Some text here</p>\
<button>blue</button>\
<button>red</button>\
\
\
";
//Create the document
document = jsdom.jsdom(docStr);
window = document.defaultView;
DOMParser = require('xmldom').DOMParser;
alert = function(msg) {}
document.adoptNode = function(node) {return node;};
document.createCDATASection = function(str) {return {};};
document.createNodeIterator = function(a, b, c) {return {};};
document.enableStyleSheetsForSet = function (name) {};
document.createRange = function() {};
document.hasFocus = function() {};
document.getSelection = function () {};
}
// --- end loading pseudo DOM ---
// https://developer.mozilla.org/en-US/docs/Web/API/Document/createRange
var range = document.createRange();
// range.setStart(startNode, startOffset);
\
\
\
<p id="\"para1\"">Some text here</p>\
<button>blue</button>\
<button>red</button>\
\
\
";
//Create the document
document = jsdom.jsdom(docStr);
window = document.defaultView;
DOMParser = require('xmldom').DOMParser;
alert = function(msg) {}
document.adoptNode = function(node) {return node;};
document.createCDATASection = function(str) {return {};};
document.createNodeIterator = function(a, b, c) {return {};};
document.enableStyleSheetsForSet = function (name) {};
document.createRange = function() {};
document.hasFocus = function() {};
document.getSelection = function () {};
}
// --- end loading pseudo DOM ---
// the first argument should be a string
var cdata = document.createElement(true);
})();
/* eslint-disable no-undef */
import jsdom from 'jsdom';
global.document = jsdom.jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach(function mapProperties(property) {
if (typeof global[property] === 'undefined') {
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js'
};
/* eslint-enable no-undef */
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const jsdom = require('jsdom').jsdom;
global.expect = chai.expect;
global.sinon = sinon;
chai.use(sinonChai);
// Set up JS DOM
const exposedProperties = ['window', 'navigator', 'document'];
global.document = jsdom('<style></style>');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js'
};
documentRef = document;
import { assert } from 'chai';
import * as jsdom from 'jsdom';
import { getRandomShape } from '../../src/shapes/index';
import { shapes, deprecatedShapes } from '../../src/shapes/shapes-list';
global.document = jsdom.jsdom('');
describe('shapes', () => {
describe('#getRandomShape', () => {
it('should NOT generate the specified excluded shape types', () => {
const randomShapes = [];
const excludedShapes = Object.keys(shapes);
const removedShape = excludedShapes.splice(0, 1)[0];
let containsExcludedShape = false;
for (let i = 0; i < 30; i++) {
randomShapes.push(getRandomShape(excludedShapes));
}
containsExcludedShape = randomShapes.some(shape => shape !== removedShape);
assert.isNotOk(containsExcludedShape, 'an excluded shape was generated');
module.exports = function(markup) {
if (typeof document !== 'undefined') return;
var jsdom = require('jsdom').jsdom;
global.document = jsdom(markup || '');
global.window = document.parentWindow;
global.$ = global.jQuery = require('jquery')(global.window);
global.navigator = {
userAgent: 'node.js'
};
};
import 'babel-polyfill';
import { jsdom } from 'jsdom';
import chai from 'chai';
import dirtyChai from 'dirty-chai';
/**
* jsdom setup
*/
global.document = jsdom('<div id="root"></div>');
global.window = document.defaultView;
global.navigator = global.window.navigator;
window.localStorage = window.sessionStorage = {
getItem(key) {
return this[key];
},
setItem(key, value) {
this[key] = value;
},
removeItem(key) {
this[key] = undefined;
},
};
/**
* Get rid of those dirty dirty assertions on property access that chai loves
module.exports = function( markup, features ) {
features = assign( {}, defaultFeatures, features );
global.document = jsdom( markup, {
url: 'http://example.com/',
features: {
FetchExternalResources: false,
ProcessExternalResources: false
}
} );
global.window = document.defaultView;
global.navigator = window.navigator;
global.Element = window.Element;
global.history = window.history;
if ( features.localStorage ) {
require( 'lib/local-storage' )( global );
}
if ( features.XMLHttpRequest ) {
function parseDescription(filepath) {
let data = { properties: [] };
let values = data.properties;
let contents = fs.readFileSync(filepath).toString();
let doc = jsdom(contents, {
features: { FetchExternalResources: false }
});
let tables = doc.getElementsByClassName('bikitable');
if (tables.length != 1) {
throw new Error("Failed to find correct .bikitable. Found: " + tables.length + " tables");
}
let table = tables[0];
let rows = table.children[0].children;
for (var i = 0; i < rows.length; i++) {
if (i == 0) continue;
let row = rows[i];
let name = clearText(row.children[1].textContent);