import CVVFormatter from '../../etc/cvv-formatter';

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

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

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

        expect(formatter.isChangeValid({
            inserted: {
                text: 'beans'
            },
            proposed: {
                text: 'beans',
                selectedRange: {
                    start: 0
                }
            }
        })).to.be.false;
    });

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

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

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

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

        expect(formatter.isChangeValid({
            inserted: {
                text: '123b'
            },
            proposed: {
                text: '123b',
                selectedRange: {
                    start: 0
                }
            }
        })).to.be.false;
    });
});
