// Regression smoke test for the dependency-free remote module. const assert = require('node:assert/strict'); const fs = require('node:fs'); const vm = require('node:vm'); const source = require('esbuild').transformSync(fs.readFileSync('src/remote/ui/TabSelector/TabSelector.remote.jsx', 'utf8'), {loader:'jsx', jsxFactory:'React.createElement', jsxFragment:'React.Fragment'}).code; assert.equal(/^\s*import\s/m.test(source), false, 'Remote must be import-free'); assert.equal(/@chakra-ui\/react|@emotion\/|framer-motion/.test(source), false, 'Remote must be self-contained'); let component; const callbacks = { next: null }; const fakeReact = { Fragment: 'fragment', isValidElement: node => !!node && typeof node === 'object' && 'type' in node, createElement: (type, props, ...children) => ({ type, props: {...props, children: children.length === 1 ? children[0] : children} }), useEffect() {}, useLayoutEffect() {}, useRef: value => ({current: value}), useState: initial => [initial, () => {}] }; let latestTree; const scope = { console, queueMicrotask, window: { __UIKIT_REACT_REMOTE_DEPS__: { React: fakeReact, createRoot: () => ({ render(node) { latestTree = node.type(node.props); }, unmount() {} }), }}, document: { createElement(tag) { return { tagName: tag, style: {}, set textContent(value) { this._text = value; }, append() {} }; } }, HTMLElement: class { attachShadow() { return {append() {}}; } setAttribute(name, value) { this[name] = value; } get isConnected() {return true;} }, customElements: { get() {return component;}, define(name, ctor) {component = ctor; } }, }; vm.runInNewContext(source, scope); assert.equal(typeof component, 'function'); const element = new component(); const items = [ {id:'a', desktopTitle:{title:'Desktop', subtitle:'Detail'}, mobileTitle:{title:'Mobile'}, count:12}, {id:'b', label:'Second', count:0}, {id:'c', label:'Disabled', disabled:true}, ]; element.componentProps = {items, value:'a', onChange:value=>{callbacks.next=value;}}; const mobile = latestTree.props.children[0].props.children.props.children; const desktop = latestTree.props.children[1].props.children; assert.equal(mobile[0].props['aria-selected'], true); assert.equal(desktop[0].props.tabIndex, 0); assert.equal(desktop[1].props.tabIndex, -1); assert.equal(mobile[0].props.children[1].props.children[0].props.children, 'Mobile'); assert.equal(desktop[0].props.children[1].props.children[1].props.children[0].props.children, 'Desktop'); assert.equal(mobile[0].props.children[2].props.children, '۱۲'); desktop[1].props.onClick(); assert.equal(callbacks.next, 'b'); desktop[2].props.onClick(); assert.equal(callbacks.next, 'b'); let focused = false; desktop[0].props.onKeyDown({key:'ArrowLeft', preventDefault(){}, currentTarget:{parentElement:{children:[{}, {focus(){focused=true;}}, {}]}}}); assert.equal(callbacks.next, 'b'); assert.equal(focused, true); console.log('PASS: TabSelector independence, responsive titles, counts, disabled items and RTL keyboard');