// @ts-nocheck import { assert } from "chai" import TestComponent from "@mwater/react-library/lib/TestComponent" import ReactTestUtils from "react-dom/test-utils" import BarcodeAnswerComponent from "../../src/answers/BarcodeAnswerComponent" import React from "react" import ReactDOM from "react-dom" describe("BarcodeAnswerComponent", function () { describe("Works without scanBarcode", function () { beforeEach(function () { this.toDestroy = [] return (this.render = (options = {}) => { const elem = str }} /> const comp = new TestComponent(elem) this.toDestroy.push(comp) return comp }) }) afterEach(function () { return this.toDestroy.map((comp: any) => comp.destroy()) }) return it("shows text if not supported", function () { // If no context is passed, scanBarcode is not defined and so the feature is not supported const comp = this.render({ onValueChange() { return null } }) const component = comp.findDOMNodeByText(/not supported/i) return assert(component != null, "Not showing not supported text") }) }) return describe("Works with scanBarcode", function () { beforeEach(function () { this.toDestroy = [] return (this.render = (options = {}) => { const elem = callback.success("0123456789") return setTimeout(f, 30) }, T: (str: any) => str }} /> const comp = new TestComponent(elem) this.toDestroy.push(comp) return comp }) }) afterEach(function () { return this.toDestroy.map((comp: any) => comp.destroy()) }) it("shows scan button", function () { const comp = this.render({ onValueChange() { return null } }) const button = ReactTestUtils.findRenderedDOMComponentWithClass(comp.getComponent(), "btn") return assert(button != null, "Not showing scan button") }) it("shows clear button when value is set", function () { const comp = this.render({ onValueChange() { return null }, value: "sometext" }) // TODO: the method to find the Scan button doesn't seem to work const component = comp.findDOMNodeByText(/Clear/i) return assert(component != null, "Not showing clear button") }) it("shows scan button", function (done) { const comp = this.render({ onValueChange(value: any) { assert.equal(value, "0123456789") return done() } }) const button = ReactTestUtils.findRenderedDOMComponentWithClass(comp.getComponent(), "btn") return TestComponent.click(button) }) return it("clears when clear pressed", function (done) { const comp = this.render({ value: "sometext", onValueChange(value: any) { assert.equal(value, null) return done() } }) const button = ReactTestUtils.findRenderedDOMComponentWithClass(comp.getComponent(), "btn") return TestComponent.click(button) }) }) })