|
| 1 | +import { TestBed } from '@angular/core/testing'; |
| 2 | +import { RegexService } from './regex.service'; |
| 3 | + |
| 4 | +describe('RegexService', () => { |
| 5 | + let service: RegexService; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + jasmine.clock().uninstall(); |
| 9 | + jasmine.clock().install(); |
| 10 | + |
| 11 | + TestBed.configureTestingModule({ |
| 12 | + providers: [], |
| 13 | + }); |
| 14 | + |
| 15 | + service = new RegexService(); |
| 16 | + }); |
| 17 | + |
| 18 | + afterEach(() => { |
| 19 | + jasmine.clock().uninstall(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should be instantiated', () => { |
| 23 | + expect(service).toBeTruthy(); |
| 24 | + }); |
| 25 | + |
| 26 | + // Email |
| 27 | + |
| 28 | + it('should validate email with just alphabetic characters', () => { |
| 29 | + expect(service.getRegex('mail').test('[email protected]')).toBeTruthy(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should validate email with numbers', () => { |
| 33 | + expect(service.getRegex('mail').test('[email protected]')).toBeTruthy(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should validate email with multiple numbers in domain', () => { |
| 37 | + expect(service.getRegex('mail').test('[email protected]')).toBeTruthy(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should validate email with a mix of numbers and and alphabetic chars', () => { |
| 41 | + expect(service.getRegex('mail').test('[email protected]')).toBeTruthy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should validate email with a mix of numbers and valid alphabetic chars', () => { |
| 45 | + expect(service.getRegex('mail').test('[email protected]')).toBeTruthy(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should validate email with a mix of special chars in username', () => { |
| 49 | + expect( |
| 50 | + service.getRegex('mail').test('t#e!s$t%1.&[email protected]') |
| 51 | + ).toBeTruthy(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should NOT validate an email without a domain name', () => { |
| 55 | + expect(service.getRegex('mail').test('[email protected]')).toBeFalsy(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should NOT validate an email without a domain name OR TDL', () => { |
| 59 | + expect(service.getRegex('mail').test('test@')).toBeFalsy(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should NOT validate an email without a username', () => { |
| 63 | + expect(service.getRegex('mail').test('@minds.com')).toBeFalsy(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should NOT validate an email without a TLD', () => { |
| 67 | + expect(service.getRegex('mail').test('test@minds')).toBeFalsy(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should NOT validate @ as an email', () => { |
| 71 | + expect(service.getRegex('mail').test('@')).toBeFalsy(); |
| 72 | + }); |
| 73 | +}); |
0 commit comments