From ac75e0b8a5bd4b08ddabe6dba1e4f65aeee0622a Mon Sep 17 00:00:00 2001 From: Pixelastic Date: Tue, 26 Jan 2016 17:38:32 +0100 Subject: [PATCH] test(formatURL): Add tests for formatURL --- test/DocSearch-test.js | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/test/DocSearch-test.js b/test/DocSearch-test.js index d0390c63..3e05c94f 100644 --- a/test/DocSearch-test.js +++ b/test/DocSearch-test.js @@ -28,6 +28,9 @@ describe('DocSearch', () => { span span `; + + // We prevent the logging of expected errors + window.console.warn = sinon.spy(); }); describe('constructor', () => { @@ -804,6 +807,86 @@ describe('DocSearch', () => { }); }); + describe('formatUrl', () => { + it('concatenates url and anchor', () => { + // Given + let input = { + url: 'url', + anchor: 'anchor' + }; + + // When + let actual = DocSearch.formatURL(input); + + // Then + expect(actual).toEqual('url#anchor'); + }); + + it('returns only the url if no anchor', () => { + // Given + let input = { + url: 'url' + }; + + // When + let actual = DocSearch.formatURL(input); + + // Then + expect(actual).toEqual('url'); + }); + + it('returns the anchor if no url', () => { + // Given + let input = { + anchor: 'anchor' + }; + + // When + let actual = DocSearch.formatURL(input); + + // Then + expect(actual).toEqual('#anchor'); + }); + + it('does not concatenate if already an anchor', () => { + // Given + let input = { + url: 'url#anchor', + anchor: 'anotheranchor' + }; + + // When + let actual = DocSearch.formatURL(input); + + // Then + expect(actual).toEqual('url#anchor'); + }); + + it('returns null if no anchor nor url', () => { + // Given + let input = { + }; + + // When + let actual = DocSearch.formatURL(input); + + // Then + expect(actual).toEqual(null); + }); + + it('emits a warning if no anchor nor url', () => { + // Given + let input = { + }; + + // When + DocSearch.formatURL(input); + + // Then + expect(window.console.warn.calledOnce).toBe(true); + }); + }); + describe('getSuggestionTemplate', () => { beforeEach(() => { let templates = {