forked from OpenDroneMap/WebODM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ModelView frontend tests, moved jquery-i18next, updated docs, jest co…
…nfig
- Loading branch information
Showing
12 changed files
with
165 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { mount } from 'enzyme'; | ||
import Map from '../Map'; | ||
import sinon from 'sinon'; | ||
|
||
sinon.useFakeXMLHttpRequest(); | ||
|
||
describe('<Map />', () => { | ||
it('renders without exploding', () => { | ||
const wrapper = shallow(<Map | ||
const wrapper = mount(<Map | ||
tiles={['/tiles.json']} />); | ||
|
||
// TODO: componentDidUpdate method is never called | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import TaskListItem from '../TaskListItem'; | ||
|
||
import createHistory from 'history/createBrowserHistory'; | ||
const taskMock = require('../../tests/utils/MockLoader').load("task.json"); | ||
|
||
describe('<TaskListItem />', () => { | ||
it('renders without exploding', () => { | ||
// TODO: load history mock | ||
const wrapper = shallow(<TaskListItem history={{}} data={taskMock} />); | ||
const wrapper = shallow(<TaskListItem history={createHistory()} data={taskMock} />); | ||
expect(wrapper.exists()).toBe(true); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
// import ModelView from '../ModelView'; | ||
|
||
// TODO: this needs some debugging since Potree has troubles with requirements | ||
import ModelView from '../ModelView'; | ||
const taskMock = require('./utils/MockLoader').load("task.json"); | ||
|
||
describe('<ModelView />', () => { | ||
it('TODO: renders without exploding', () => { | ||
expect(true).toBe(true); | ||
// const wrapper = shallow(<ModelView task={{id: 1, project: 1}} />); | ||
// expect(wrapper.exists()).toBe(true); | ||
it('renders without exploding', () => { | ||
const wrapper = shallow(<ModelView task={taskMock} />); | ||
expect(wrapper.exists()).toBe(true); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Define certain DOM elements | ||
// that are not defined in the JEST environment | ||
|
||
const currentScript = document.createElement('script'); | ||
currentScript.src = "http://bogus"; | ||
|
||
Object.defineProperty(document, 'currentScript', { | ||
value: currentScript | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'use strict'; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var defaults = { | ||
tName: 't', | ||
i18nName: 'i18n', | ||
handleName: 'localize', | ||
selectorAttr: 'data-i18n', | ||
targetAttr: 'i18n-target', | ||
optionsAttr: 'i18n-options', | ||
useOptionsAttr: false, | ||
parseDefaultValueFromContent: true | ||
}; | ||
|
||
function init(i18next, $) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
|
||
|
||
options = _extends({}, defaults, options); | ||
|
||
function parse(ele, key, opts) { | ||
if (key.length === 0) return; | ||
|
||
var attr = 'text'; | ||
|
||
if (key.indexOf('[') === 0) { | ||
var parts = key.split(']'); | ||
key = parts[1]; | ||
attr = parts[0].substr(1, parts[0].length - 1); | ||
} | ||
|
||
if (key.indexOf(';') === key.length - 1) { | ||
key = key.substr(0, key.length - 2); | ||
} | ||
|
||
function extendDefault(o, val) { | ||
if (!options.parseDefaultValueFromContent) return o; | ||
return _extends({}, o, { defaultValue: val }); | ||
} | ||
|
||
if (attr === 'html') { | ||
ele.html(i18next.t(key, extendDefault(opts, ele.html()))); | ||
} else if (attr === 'text') { | ||
ele.text(i18next.t(key, extendDefault(opts, ele.text()))); | ||
} else if (attr === 'prepend') { | ||
ele.prepend(i18next.t(key, extendDefault(opts, ele.html()))); | ||
} else if (attr === 'append') { | ||
ele.append(i18next.t(key, extendDefault(opts, ele.html()))); | ||
} else if (attr.indexOf('data-') === 0) { | ||
var dataAttr = attr.substr('data-'.length); | ||
var translated = i18next.t(key, extendDefault(opts, ele.data(dataAttr))); | ||
|
||
// we change into the data cache | ||
ele.data(dataAttr, translated); | ||
// we change into the dom | ||
ele.attr(attr, translated); | ||
} else { | ||
ele.attr(attr, i18next.t(key, extendDefault(opts, ele.attr(attr)))); | ||
} | ||
} | ||
|
||
function localize(ele, opts) { | ||
var key = ele.attr(options.selectorAttr); | ||
if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); | ||
if (!key) return; | ||
|
||
var target = ele, | ||
targetSelector = ele.data(options.targetAttr); | ||
|
||
if (targetSelector) target = ele.find(targetSelector) || ele; | ||
|
||
if (!opts && options.useOptionsAttr === true) opts = ele.data(options.optionsAttr); | ||
|
||
opts = opts || {}; | ||
|
||
if (key.indexOf(';') >= 0) { | ||
var keys = key.split(';'); | ||
|
||
$.each(keys, function (m, k) { | ||
if (k !== '') parse(target, k, opts); | ||
}); | ||
} else { | ||
parse(target, key, opts); | ||
} | ||
|
||
if (options.useOptionsAttr === true) { | ||
var clone = {}; | ||
clone = _extends({ clone: clone }, opts); | ||
|
||
delete clone.lng; | ||
ele.data(options.optionsAttr, clone); | ||
} | ||
} | ||
|
||
function handle(opts) { | ||
return this.each(function () { | ||
// localize element itself | ||
localize($(this), opts); | ||
|
||
// localize children | ||
var elements = $(this).find('[' + options.selectorAttr + ']'); | ||
elements.each(function () { | ||
localize($(this), opts); | ||
}); | ||
}); | ||
}; | ||
|
||
// $.t $.i18n shortcut | ||
$[options.tName] = i18next.t.bind(i18next); | ||
$[options.i18nName] = i18next; | ||
|
||
// selector function $(mySelector).localize(opts); | ||
$.fn[options.handleName] = handle; | ||
} | ||
|
||
module.exports = init; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module.exports = { | ||
roots: ["./app/static/app/js"], | ||
"moduleNameMapper": { | ||
moduleNameMapper: { | ||
"^.*\\.s?css$": "<rootDir>/app/static/app/js/tests/mocks/empty.scss.js", | ||
"jquery": "<rootDir>/app/static/app/js/vendor/jquery-1.11.2.min.js" | ||
} | ||
}, | ||
setupFiles: ["<rootDir>/app/static/app/js/tests/setup/browserMock.js"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters