<commit_before>/*eslint-env jasmine*/
define([
    'widgets/appWidgets2/input/floatInput',
    'common/runtime',
    'testUtil'
], function(
    FloatInput,
    Runtime,
    TestUtil
) {
    'use strict';

    describe('Test float data input widget', function() {
        let testConfig = {},
            runtime = Runtime.make(),
            bus;

        beforeEach(function() {
            bus = runtime.bus().makeChannelBus({
                description: 'float testing',
                // name: 'float-test-' + Math.floor(Math.random()*10000)
            });
            testConfig = {
                bus: bus,
                parameterSpec: {
                    data: {
                        defaultValue: 1.0,
                        nullValue: '',
                        constraints: {
                            required: false,
                            min: -1000,
                            max: 1000
                        }

                    },
                    original: {
                        text_subdata_options: {}
                    }
                },
                channelName: bus.channelName,
            };
        });

        afterEach(() => {
            bus.stop();
        })

        it('should be real!', function() {
            expect(FloatInput).not.toBeNull();
        });

        it('should instantiate with a test config', function() {
            TestUtil.pendingIfNoToken();
            var widget = FloatInput.make(testConfig);
            expect(widget).toEqual(jasmine.any(Object));
        });

        it('should start and stop properly without initial value', (done) => {
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    expect(node.childElementCount).toBeGreaterThan(0);
                    const input = node.querySelector('input[data-type="float"]');
                    expect(input).toBeDefined();
                    expect(input.getAttribute('value')).toBeNull();
                    return widget.stop();
                })
                .then(() => {
                    expect(node.childElementCount).toBe(0);
                    done();
                });
        });

        it('should start and stop properly with initial value', (done) => {
            testConfig.initialValue = 10.0;
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    expect(node.childElementCount).toBeGreaterThan(0);
                    const input = node.querySelector('input[data-type="float"]');
                    expect(input).toBeDefined();
                    expect(input.getAttribute('value')).toBe(String(testConfig.initialValue));
                    return widget.stop();
                })
                .then(() => {
                    expect(node.childElementCount).toBe(0);
                    done();
                });
        });

        it('should update model properly with change event', (done) => {
            bus.on('changed', (value) => {
                expect(value).toEqual({newValue: 1.2});
                done();
            });
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 1.2);
                    input.dispatchEvent(new Event('change'));
                })
        });

        it('should update model properly with keyup/touch event', (done) => {
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            bus.on('validation', (message) => {
                expect(message.isValid).toBeTruthy();
                widget.stop()
                    .then(done);
            });
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 1.23);
                    input.dispatchEvent(new Event('keyup'));
                    TestUtil.wait(500);
                });
        });

        it('should show message when configured', (done) => {
            testConfig.showOwnMessages = true;
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 5);
                    input.dispatchEvent(new Event('change'));
                    return widget.stop();
                })
                .then(done);
        });

        it('should respond to bus commands', (done) => {
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    bus.emit('update', {value: '12345.6'});
                    return TestUtil.wait(500);
                })
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    // console.log(input);
                    // console.log(node);
                    // expect(input.getAttribute('value')).toBe(12345.6);
                    bus.emit('reset-to-defaults');
                    return TestUtil.wait(200);
                })
                // .then(() => {
                //     // const input = node.querySelector('input[data-type="float"]');
                //     // expect(input.getAttribute('value')).toBe(1.0);
                //     return widget.stop();
                // })
                .then(done);
        });
    });
});<commit_msg>fix float input spec<commit_after>/*eslint-env jasmine*/
define([
    'widgets/appWidgets2/input/floatInput',
    'common/runtime',
    'testUtil'
], function(
    FloatInput,
    Runtime,
    TestUtil
) {
    'use strict';

    describe('Test float data input widget', function() {
        let testConfig = {},
            runtime = Runtime.make(),
            bus;

        beforeEach(function() {
            bus = runtime.bus().makeChannelBus({
                description: 'float testing',
                // name: 'float-test-' + Math.floor(Math.random()*10000)
            });
            testConfig = {
                bus: bus,
                parameterSpec: {
                    data: {
                        defaultValue: 1.0,
                        nullValue: '',
                        constraints: {
                            required: false,
                            min: -1000,
                            max: 1000
                        }

                    },
                    original: {
                        text_subdata_options: {}
                    }
                },
                channelName: bus.channelName,
            };
        });

        afterEach(() => {
            bus.stop();
        })

        it('should be real!', function() {
            expect(FloatInput).not.toBeNull();
        });

        it('should instantiate with a test config', function() {
            TestUtil.pendingIfNoToken();
            var widget = FloatInput.make(testConfig);
            expect(widget).toEqual(jasmine.any(Object));
        });

        it('should start and stop properly without initial value', (done) => {
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    expect(node.childElementCount).toBeGreaterThan(0);
                    const input = node.querySelector('input[data-type="float"]');
                    expect(input).toBeDefined();
                    expect(input.getAttribute('value')).toBeNull();
                    return widget.stop();
                })
                .then(() => {
                    expect(node.childElementCount).toBe(0);
                    done();
                });
        });

        it('should start and stop properly with initial value', (done) => {
            testConfig.initialValue = 10.0;
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    expect(node.childElementCount).toBeGreaterThan(0);
                    const input = node.querySelector('input[data-type="float"]');
                    expect(input).toBeDefined();
                    expect(input.getAttribute('value')).toBe(String(testConfig.initialValue));
                    return widget.stop();
                })
                .then(() => {
                    expect(node.childElementCount).toBe(0);
                    done();
                });
        });

        it('should update model properly with change event', (done) => {
            bus.on('changed', (value) => {
                expect(value).toEqual({newValue: 1.2});
                done();
            });
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 1.2);
                    input.dispatchEvent(new Event('change'));
                })
        });

        it('should update model properly with keyup/touch event', (done) => {
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            bus.on('validation', (message) => {
                expect(message.isValid).toBeTruthy();
                widget.stop()
                    .then(done);
            });
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 1.23);
                    input.dispatchEvent(new Event('keyup'));
                    TestUtil.wait(500);
                });
        });

        it('should show message when configured', (done) => {
            testConfig.showOwnMessages = true;
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    const input = node.querySelector('input[data-type="float"]');
                    input.setAttribute('value', 5);
                    input.dispatchEvent(new Event('change'));
                    return widget.stop();
                })
                .then(done);
        });

        it('should respond to bus commands', (done) => {
            bus.on('validation', done);
            let widget = FloatInput.make(testConfig);
            let node = document.createElement('div');
            widget.start({node: node})
                .then(() => {
                    bus.emit('update', {value: '12345.6'});
                    return TestUtil.wait(500);
                });
        });
    });
});
{'fraction_non_alphanumeric': 0.13605677687380993, 'fraction_numerical': 0.008395360913969188, 'mean_word_length': 1.2813425468904245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6809465', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2648, 'n_words': 495}