This commit is contained in:
parent
c59715e912
commit
f611c731bd
|
@ -3,3 +3,4 @@
|
||||||
/dist
|
/dist
|
||||||
/gadjo.egg-info
|
/gadjo.egg-info
|
||||||
/gadjo/static/css/icons
|
/gadjo/static/css/icons
|
||||||
|
node_modules
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^28.1.3",
|
||||||
|
"jquery": "^3.6.3",
|
||||||
|
"jsdom": "^19.0.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
const assert = require('assert')
|
||||||
|
const { loadDom } = require('./test-utils')
|
||||||
|
|
||||||
|
test('test foldable sections', async () => {
|
||||||
|
const { window } = await loadDom(`
|
||||||
|
<div class="section foldable">
|
||||||
|
<h2>Section Title</h2>
|
||||||
|
</div>
|
||||||
|
`)
|
||||||
|
|
||||||
|
const foldableSection = window.document.querySelector('.section.foldable')
|
||||||
|
const title = window.document.querySelector('.section.foldable > h2')
|
||||||
|
|
||||||
|
title.click()
|
||||||
|
assert(foldableSection.classList.contains('folded'))
|
||||||
|
|
||||||
|
title.click()
|
||||||
|
assert(!foldableSection.classList.contains('folded'))
|
||||||
|
})
|
|
@ -0,0 +1,31 @@
|
||||||
|
const path = require('path')
|
||||||
|
const { JSDOM } = require('jsdom')
|
||||||
|
|
||||||
|
async function loadDom (content) {
|
||||||
|
const dom = new JSDOM(`
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html >
|
||||||
|
<body>
|
||||||
|
${content}
|
||||||
|
</body>
|
||||||
|
<script src="file://${require.resolve('jquery')}"></script>
|
||||||
|
<script src="file://${path.join(__dirname, '../../gadjo/static/js/gadjo.js')}"></script>
|
||||||
|
<script>
|
||||||
|
jQuery(() => document.dispatchEvent(new Event("test:ready")))
|
||||||
|
</script>
|
||||||
|
</html>`, {
|
||||||
|
runScripts: 'dangerously',
|
||||||
|
resources: 'usable'
|
||||||
|
})
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
dom.window.document.addEventListener('test:ready', () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return dom
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { loadDom }
|
||||||
|
|
Loading…
Reference in New Issue