diff --git a/lib/core/Cetra.test.js b/lib/core/Cetra.test.js new file mode 100644 index 0000000..98210d8 --- /dev/null +++ b/lib/core/Cetra.test.js @@ -0,0 +1,76 @@ +import Cetra from './Cetra'; + +describe('Cetra', () => { + let cetra; + + beforeEach(() => { + cetra = new Cetra(); + }); + + afterEach(() => { + cetra = null; + }); + + describe('general', () => { + it('should emit the onAfterInit event', () => { + const spy = jest.fn(); + let _test = new Cetra(new Map([['onAfterInit', spy]])); + expect(spy).toHaveBeenCalled().withArgs('onAfterInit'); + }); + }); + + describe('uid', () => { + it('should generate a unique identifier', () => { + const identifier = cetra.uid(); + + expect(typeof identifier).toBe('string'); + expect(identifier.length).toBeGreaterThan(0); + }); + + it('should generate a unique identifier with the specified number of groups and group length', () => { + const numGroups = 3; + const groupLength = 4; + + const identifier = cetra.uid(numGroups, groupLength); + + const groups = identifier.split('-'); + expect(groups.length).toBe(numGroups); + groups.forEach((group) => { + expect(group.length).toBe(groupLength); + }); + }); + }); + + describe('isUrl', () => { + it('should return true for a valid url', () => { + const url = 'https://www.google.com'; + + expect(cetra.isUrl(url)).toBe(true); + }); + + it('should return false for an invalid url', () => { + const url = 'https://www.google'; + + expect(cetra.isUrl(url)).toBe(false); + }); + + it('should return false for a non-string', () => { + const url = 123; + + expect(cetra.isUrl(url)).toBe(false); + }); + + it('should return false for an empty string', () => { + const url = ''; + + expect(cetra.isUrl(url)).toBe(false); + }); + + it('should return true for a relative path', () => { + const url = '/test'; + + expect(cetra.isUrl(url)).toBe(true); + }); + }); +}); +import Cetra from './Cetra';