ncc-express-scaffold
Version:
Northumberland Council Front End Scaffold
104 lines (80 loc) • 3.18 kB
text/typescript
import { emailValidator, postCodeValidator, selectddlValidator } from "../../libs/formValidators";
/* email validator test */
describe("emailvalidator", () => {
test("should return false in incorrect email address entered", () => {
const email = 'phil@northumberland'
const isValid = emailValidator(email);
expect(isValid).toBe(false)
});
test("should return true if email address entered", () => {
const email = 'phil@northumberland.gov.uk'
const isValid = emailValidator(email);
expect(isValid).toBe(true)
});
})
/* postcode validator test */
describe("postcodevalidator", () => {
test("should return true when a valid postcode ne27 0jz", () => {
const postCode = 'ne27 0jz'
const isValid = postCodeValidator(postCode);
expect(isValid).toBe(true)
});
test('should return true when an valid postcode without space ne270jz', () => {
const validPostcode = 'ne270jz';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return true when an valid postcode AA9A 9AA', () => {
const validPostcode = 'AA9A 9AA';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return true when an valid postcode A9A 9AA', () => {
const validPostcode = 'A9A 9AA';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return true when an valid postcode A9 9AA', () => {
const validPostcode = 'A9A 9AA';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return true when an valid postcode AA9 9AA', () => {
const validPostcode = 'AA9 9AA';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return true when an valid postcode AA99 9AA', () => {
const validPostcode = 'AA99 9AA';
const isValid = postCodeValidator(validPostcode);
expect(isValid).toBe(true);
});
test('should return false when an invalid postcode', () => {
const invalidPostcode = 'invalid postcode';
const isValid = postCodeValidator(invalidPostcode);
expect(isValid).toBe(false);
});
test('should return false when an invalid postcode empty string', () => {
const invalidPostcode = '';
const isValid = postCodeValidator(invalidPostcode);
expect(isValid).toBe(false);
});
test('should return false when an invalid postcode empty string', () => {
const invalidPostcode = 'ner4t';
const isValid = postCodeValidator(invalidPostcode);
expect(isValid).toBe(false);
});
})
/* ddl validator test (select address */
describe('selectddlValidator', () => {
test('should return false when string is empty', () => {
const dropdownValue = ''
const isValid = selectddlValidator(dropdownValue);
expect(isValid).toBe(false)
})
test('should return true when string is not empty', () => {
const dropdownValue = 'test'
const isValid = selectddlValidator(dropdownValue);
expect(isValid).toBe(true)
})
})