diff --git a/README.md b/README.md index 06be680f8..580afc0e0 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,4 @@ If you need to support every single locale on the planet, we recommend to polyfi [floating-vue](https://floating-vue.starpad.dev/) -[mitt](https://www.npmjs.com/package/mitt) - [svg-country-flags](https://www.npmjs.com/package/svg-country-flags) diff --git a/package-lock.json b/package-lock.json index c4b97842e..d68b341c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ebury/chameleon-components", - "version": "2.6.0", + "version": "2.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ebury/chameleon-components", - "version": "2.6.0", + "version": "2.6.1", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -17,7 +17,6 @@ "floating-vue": "2.0.0-beta.16", "focus-trap": "6.9.4", "lodash": "4.17.21", - "mitt": "3.0.1", "svg-country-flags": "1.2.10", "tailwindcss": "3.3.5", "vue": "3.3.4" @@ -19643,11 +19642,6 @@ "node": ">=8" } }, - "node_modules/mitt": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", - "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==" - }, "node_modules/mixin-deep": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", @@ -42471,11 +42465,6 @@ } } }, - "mitt": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", - "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==" - }, "mixin-deep": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", diff --git a/package.json b/package.json index b6a23bdbf..81b1ac9f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ebury/chameleon-components", - "version": "2.6.0", + "version": "2.6.1", "main": "src/main.js", "sideEffects": false, "author": "Ebury Team (http://labs.ebury.rocks/)", @@ -45,7 +45,6 @@ "floating-vue": "2.0.0-beta.16", "focus-trap": "6.9.4", "lodash": "4.17.21", - "mitt": "3.0.1", "svg-country-flags": "1.2.10", "tailwindcss": "3.3.5", "vue": "3.3.4" diff --git a/src/components/ec-timer/__snapshots__/ec-timer.spec.js.snap b/src/components/ec-timer/__snapshots__/ec-timer.spec.js.snap index 05f1305f7..f384536d6 100644 --- a/src/components/ec-timer/__snapshots__/ec-timer.spec.js.snap +++ b/src/components/ec-timer/__snapshots__/ec-timer.spec.js.snap @@ -46,6 +46,98 @@ exports[`EcTimer > :props > should render as expected 1`] = ` `; +exports[`EcTimer > :props > should restart when seconds prop is updated > after restart 1`] = ` +
+ + + + + 30 + + s + + + +
+`; + +exports[`EcTimer > :props > should restart when seconds prop is updated > before restart 1`] = ` +
+ + + + + 10 + + s + + + +
+`; + exports[`EcTimer > :props > when "showMinutes" is true > when "isRunning" is false > should render as expected 1`] = `
{ + let clock; + + beforeEach(() => { + clock = fakeTimers.install(); + }); + + afterEach(() => { + if (clock) { + clock.uninstall(); + } + }); + function mountTimer(props, mountOpts) { return mount(EcTimer, { props, @@ -60,13 +71,11 @@ describe('EcTimer', () => { }); it('should clear the interval if we set "isRunning" to false', async () => { - const clearTimeoutSpy = vi.spyOn(window, 'clearInterval'); const wrapper = mountTimer({ seconds: 20, isRunning: true }); - - expect(clearTimeoutSpy).toHaveBeenCalledTimes(0); + expect(clock.countTimers()).toBe(1); await wrapper.setProps({ isRunning: false }); - expect(clearTimeoutSpy).toHaveBeenCalledTimes(1); + expect(clock.countTimers()).toBe(0); }); it('should render as expected', () => { @@ -75,6 +84,17 @@ describe('EcTimer', () => { expect(wrapper.element).toMatchSnapshot(); }); + it('should restart when seconds prop is updated', async () => { + const wrapper = mountTimer({ seconds: 20, isRunning: true }); + clock.tick(10000); + await wrapper.vm.$nextTick(); + expect(wrapper.element).toMatchSnapshot('before restart'); + + await wrapper.setProps({ seconds: 30 }); + + expect(wrapper.element).toMatchSnapshot('after restart'); + }); + describe('when "showMinutes" is true', () => { describe('when "isRunning" is false', () => { it('should render as expected', () => { @@ -92,11 +112,17 @@ describe('EcTimer', () => { }); }); - it('should render a timer with minutes', () => { + it('should render a timer with leading zero in minutes', () => { const wrapper = mountTimer({ seconds: 20, isRunning: true, showMinutes: true }); expect(wrapper.findByDataTest('ec-timer__text-with-minutes').text()).toBe('0:20'); }); + + it('should render a timer with minutes', () => { + const wrapper = mountTimer({ seconds: 80, isRunning: true, showMinutes: true }); + + expect(wrapper.findByDataTest('ec-timer__text-with-minutes').text()).toBe('1:20'); + }); }); }); @@ -119,18 +145,6 @@ describe('EcTimer', () => { }); describe('@events', () => { - let clock; - - beforeEach(() => { - clock = fakeTimers.install(); - }); - - afterEach(() => { - if (clock) { - clock.uninstall(); - } - }); - it('should emit an event called "time-expired" after the countdown completes', async () => { const wrapper = mountTimer({ seconds: 20, isRunning: true }); @@ -165,12 +179,11 @@ describe('EcTimer', () => { }); }); - it('should clear the interval before we destroy the components', () => { - const clearTimeoutSpy = vi.spyOn(window, 'clearInterval'); + it('should clear the interval before destroying the component', () => { const wrapper = mountTimer({ seconds: 20, isRunning: true }); + expect(clock.countTimers()).toBe(1); - expect(clearTimeoutSpy).toHaveBeenCalledTimes(0); wrapper.unmount(); - expect(clearTimeoutSpy).toHaveBeenCalledTimes(1); + expect(clock.countTimers()).toBe(0); }); }); diff --git a/src/components/ec-timer/ec-timer.vue b/src/components/ec-timer/ec-timer.vue index 681e28fb6..6b0452065 100644 --- a/src/components/ec-timer/ec-timer.vue +++ b/src/components/ec-timer/ec-timer.vue @@ -58,11 +58,9 @@