diff --git a/app/assets/javascripts/colourPreview.js b/app/assets/javascripts/colourPreview.js deleted file mode 100644 index 05d82e64b..000000000 --- a/app/assets/javascripts/colourPreview.js +++ /dev/null @@ -1,29 +0,0 @@ -(function(Modules) { - "use strict"; - - let isSixDigitHex = value => value.match(/^#[0-9A-F]{6}$/i); - let colourOrWhite = value => isSixDigitHex(value) ? value : '#FFFFFF'; - - Modules.ColourPreview = function() { - - this.start = component => { - - this.$input = $(component); - - this.$input.closest('.usa-form-group').append( - this.$preview = $('') - ); - - this.$input - .on('input', this.update) - .trigger('input'); - - }; - - this.update = () => this.$preview.css( - 'background', colourOrWhite(this.$input.val()) - ); - - }; - -})(window.GOVUK.Modules); diff --git a/app/assets/javascripts/homepage.js b/app/assets/javascripts/homepage.js deleted file mode 100644 index dd0a2ab1e..000000000 --- a/app/assets/javascripts/homepage.js +++ /dev/null @@ -1,24 +0,0 @@ -(function(window) { - "use strict"; - - window.GOVUK.Modules.Homepage = function() { - - this.start = function(component) { - - let $component = $(component); - let iterations = 0; - let timeout = null; - - $component.on('click', () => { - if (++iterations == 5) { - $component.toggleClass('product-page-intro-wrapper--alternative'); - } - clearTimeout(timeout); - timeout = setTimeout(() => iterations = 0, 1500); - }); - - }; - - }; - -})(window); diff --git a/gulpfile.js b/gulpfile.js index f6389f3c9..f360747b2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -68,13 +68,11 @@ const javascripts = () => { paths.src + 'javascripts/errorTracking.js', paths.src + 'javascripts/preventDuplicateFormSubmissions.js', paths.src + 'javascripts/fullscreenTable.js', - paths.src + 'javascripts/colourPreview.js', paths.src + 'javascripts/templateFolderForm.js', paths.src + 'javascripts/collapsibleCheckboxes.js', paths.src + 'javascripts/radioSlider.js', paths.src + 'javascripts/updateStatus.js', paths.src + 'javascripts/errorBanner.js', - paths.src + 'javascripts/homepage.js', paths.src + 'javascripts/timeoutPopup.js', paths.src + 'javascripts/date.js', paths.src + 'javascripts/loginAlert.js', diff --git a/tests/javascripts/activityChart.test.js b/tests/javascripts/activityChart.test.js index 4e0393e7e..3d0087ec1 100644 --- a/tests/javascripts/activityChart.test.js +++ b/tests/javascripts/activityChart.test.js @@ -18,6 +18,12 @@ Object.defineProperty(HTMLElement.prototype, 'clientWidth', { }); // beforeAll hook to set up the DOM and load D3.js script +beforeAll(() => { + jest.spyOn(Intl, 'DateTimeFormat').mockImplementation(() => ({ + resolvedOptions: () => ({ timeZone: 'UTC' }) + })); +}); + beforeAll(done => { // Set up the DOM with the D3 script included document.body.innerHTML = ` diff --git a/tests/javascripts/colourPreview.test.js b/tests/javascripts/colourPreview.test.js deleted file mode 100644 index 855c2a048..000000000 --- a/tests/javascripts/colourPreview.test.js +++ /dev/null @@ -1,139 +0,0 @@ -const helpers = require('./support/helpers.js'); - -beforeAll(() => { - require('../../app/assets/javascripts/colourPreview.js'); -}); - -afterAll(() => { - require('./support/teardown.js'); -}); - -describe('Colour preview', () => { - - let field; - let textbox; - let swatchEl; - - beforeEach(() => { - - // set up DOM - document.body.innerHTML = ` -
- - -
`; - - field = document.querySelector('.usa-form-group'); - textbox = document.querySelector('input[type=text]'); - - }); - - afterEach(() => { - - document.body.innerHTML = ''; - - }); - - describe("When the page loads", () => { - - test("It should add a swatch element for the preview", () => { - - // start the module - window.GOVUK.modules.start(); - - swatchEl = document.querySelector('.textbox-colour-preview'); - - expect(swatchEl).not.toBeNull(); - - }); - - test("If the textbox is empty it should make the swatch white", () => { - - // start the module - window.GOVUK.modules.start(); - - swatchEl = document.querySelector('.textbox-colour-preview'); - - // textbox defaults to empty - // colours are output in RGB - expect(swatchEl.style.background).toEqual('rgb(255, 255, 255)'); - - }); - - test("If the textbox has a value which is a hex code it should add that colour to the swatch", () => { - - textbox.setAttribute('value', '#00FF00'); - - // start the module - window.GOVUK.modules.start(); - - swatchEl = document.querySelector('.textbox-colour-preview'); - - // colours are output in RGB - expect(swatchEl.style.background).toEqual('rgb(0, 255, 0)'); - - }); - - test("If the textbox has a value which isn't a hex code it should make the swatch white", () => { - - textbox.setAttribute('value', 'green'); - - // start the module - window.GOVUK.modules.start(); - - swatchEl = document.querySelector('.textbox-colour-preview'); - - // colours are output in RGB - expect(swatchEl.style.background).toEqual('rgb(255, 255, 255)'); - - }); - - }); - - describe("When input is added to the textbox", () => { - - beforeEach(() => { - - // start the module - window.GOVUK.modules.start(); - - swatchEl = document.querySelector('.textbox-colour-preview'); - - }); - - test("If the textbox is empty it should make the swatch white", () => { - - helpers.triggerEvent(document.querySelector('input[type=text]'), 'input'); - - // textbox defaults to empty - expect(swatchEl.style.background).toEqual('rgb(255, 255, 255)'); - - }); - - test("If the textbox has a value which is a hex code it should add that colour to the swatch", () => { - - textbox.setAttribute('value', '#00FF00'); - - helpers.triggerEvent(document.querySelector('input[type=text]'), 'input'); - - // textbox defaults to empty - expect(swatchEl.style.background).toEqual('rgb(0, 255, 0)'); - - }); - - test("If the textbox has a value which isn't a hex code it should make the swatch white", () => { - - textbox.setAttribute('value', 'green'); - - helpers.triggerEvent(document.querySelector('input[type=text]'), 'input'); - - // textbox defaults to empty - expect(swatchEl.style.background).toEqual('rgb(255, 255, 255)'); - - }); - - }); - -});