import OnlyNumberFormatter from '../../etc/only-number-formatter';

describe('OnlyNumberFormatter', function() {
    it('should allow integers', function() {
        const formatter = new OnlyNumberFormatter();

        expect(formatter.isChangeValid({
            proposed: {
                text: '1234'
            }
        })).to.be.true;
    });

    it('should allow floats', function() {
        const formatter = new OnlyNumberFormatter();

        expect(formatter.isChangeValid({
            proposed: {
                text: '12.34'
            }
        })).to.be.true;
    });

    it('should not allow strings', function() {
        const formatter = new OnlyNumberFormatter();

        expect(formatter.isChangeValid({
            proposed: {
                text: 'beans'
            }
        })).to.be.false;
    });

    it('should only continue numbers', function() {
        const formatter = new OnlyNumberFormatter();

        sinon.stub(formatter, 'positivePrefix', function() {
            return '123';
        });

        expect(formatter.isChangeValid({
            proposed: {
                text: '123'
            }
        })).to.be.true;

        expect(formatter.isChangeValid({
            proposed: {
                text: '12345'
            }
        })).to.be.true;

        expect(formatter.isChangeValid({
            proposed: {
                text: '45',
                selectedRange: {
                    start: 0
                }
            }
        })).to.be.true;

        expect(formatter.isChangeValid({
            proposed: {
                text: '123bc'
            }
        })).to.be.false;
    });
});
