import { MaskFormatter } from '../../src/utils/MaskFormatter'; describe('Mask Formatter', () => { //CPF-------------------------------------- it('mask:CPF complete valid', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(mf.format("12345678901")).toEqual("123.456.789-01"); }); it('mask:CPF complete valid literals', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(mf.format("123.456.789-01")).toEqual("123.456.789-01"); }); it('mask:CPF incomplete valid', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(mf.format("123456")).toEqual("123.456. - "); }); it('mask:CPF incomplete valid placeholder', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); mf.placeholder = "_"; expect(mf.format("123456")).toEqual("123.456.___-__"); }); it('mask:CPF too long valid', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(mf.format("012345678901")).toEqual("012.345.678-90"); }); it('mask:CPF invalid for string', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(() => { mf.format("aaaaaaaaaaa"); }).toThrowError(); }); it('mask:CPF invalid for being too long', async () => { const mf: MaskFormatter = new MaskFormatter("###.###.###-##"); expect(mf.format("10018297609")).toEqual("100.182.976-09"); }); //Car's Licence plate it('mask:Licence plate valid uppercase', async () => { const mf: MaskFormatter = new MaskFormatter("UUU-####"); expect(mf.format("zzz1234")).toEqual("ZZZ-1234"); }); it('mask:Licence plate valid lowercase', async () => { const mf: MaskFormatter = new MaskFormatter("LLL-####"); expect(mf.format("ABC1234")).toEqual("abc-1234"); }); it('mask:Licence plate invalid', async () => { const mf: MaskFormatter = new MaskFormatter("UUU-####"); expect(() => { mf.format("ABCD1234"); }).toThrowError(); }); it('mask:Licence plate invalid for being too short', async () => { const mf: MaskFormatter = new MaskFormatter("UUU-####"); expect(mf.format("ABC123")).toEqual("ABC-123 "); }); it('mask:Licence plate invalid for being too short with placeholder', async () => { const mf: MaskFormatter = new MaskFormatter("UUU-####"); mf.placeholder = "_"; expect(mf.format("ABC123")).toEqual("ABC-123_"); }); it('mask:Licence plate invalid', async () => { const mf: MaskFormatter = new MaskFormatter("UUU-####"); expect(() => { mf.format("1111111"); }).toThrowError(); }); //Alphanumerical Value it('mask:Licence plate with AlphaNumerical Mask', async () => { const mf: MaskFormatter = new MaskFormatter("AAA-####"); expect(mf.format("ABC123")).toEqual("ABC-123 "); }); it('mask:Licence plate with AlphaNumerical Mask with placeholder', async () => { const mf: MaskFormatter = new MaskFormatter("AAA-####"); mf.placeholder = "_"; expect(mf.format("ABC123")).toEqual("ABC-123_"); }); it('mask:Licence plate invalid', async () => { const mf: MaskFormatter = new MaskFormatter("AAA-####"); expect(() => { mf.format("#3"); }).toThrowError(); }); //Character Value it('mask:Licence plate with AlphaNumerical Mask', async () => { const mf: MaskFormatter = new MaskFormatter("???-####"); expect(mf.format("ABC123")).toEqual("ABC-123 "); }); it('mask:Licence plate with AlphaNumerical Mask with placeholder', async () => { const mf: MaskFormatter = new MaskFormatter("???-####"); mf.placeholder = "_"; expect(mf.format("ABC123")).toEqual("ABC-123_"); }); it('mask:Licence plate invalid', async () => { const mf: MaskFormatter = new MaskFormatter("???-####"); expect(() => { mf.format("111DDD"); }).toThrowError(); }); //Anything Value it('mask:Licence plate with AlphaNumerical Mask', async () => { const mf: MaskFormatter = new MaskFormatter("***-####"); expect(mf.format("ABC123")).toEqual("ABC-123 "); }); it('mask:Licence plate with AlphaNumerical Mask with placeholder', async () => { const mf: MaskFormatter = new MaskFormatter("***-####"); mf.placeholder = "_"; expect(mf.format("ABC123")).toEqual("ABC-123_"); }); it('mask:Licence plate invalid', async () => { const mf: MaskFormatter = new MaskFormatter("***-####"); expect(() => { mf.format("111DDD"); }).toThrowError(); }); });