Spaces:
Running
Running
Download test-editor.cjs from PabloRod11/intake-desk: direct link, hf CLI and curl.
- Browser
- Download file 998 Bytes
-
https://huggingface.co/spaces/PabloRod11/intake-desk/resolve/main/test-editor.cjs
- Command line
-
hf download hf://spaces/PabloRod11/intake-desk/test-editor.cjs
-
curl -L -o test-editor.cjs https://huggingface.co/spaces/PabloRod11/intake-desk/resolve/main/test-editor.cjs
998 Bytes
| const assert=require('node:assert/strict'),fs=require('node:fs'),vm=require('node:vm'); | |
| const source=fs.readFileSync(__dirname+'/app.js','utf8'); | |
| const fn=source.slice(source.indexOf('function dismissEditor'),source.indexOf("$('dismiss').onclick")); | |
| let closed=0,allowed=false,prevented=0; | |
| const context=vm.createContext({form:{},FormData:class{*[Symbol.iterator](){yield ['customer','Edited'];}},editorSnapshot:'[["customer","Original"]]',confirm:()=>allowed,$:()=>({close:()=>closed++})}); | |
| vm.runInContext(fn,context); | |
| context.event={preventDefault:()=>prevented++};vm.runInContext('dismissEditor(event)',context);assert.equal(closed,0);assert.equal(prevented,1); | |
| allowed=true;vm.runInContext('dismissEditor(event)',context);assert.equal(closed,1); | |
| allowed=false;context.editorSnapshot='[["customer","Edited"]]';vm.runInContext('dismissEditor(event)',context);assert.equal(closed,2); | |
| console.log('PASS: changed editor retains edits on cancel, discards on confirmation, unchanged editor closes'); | |