From c38f4a4d47bf11734646ccf04232e07deecfb0ff Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 25 Jul 2026 15:16:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixes=20bug=20in=20continous=20s?= =?UTF-8?q?tatus=20check=20rounding=20if=20less=20than=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mixins/ItemMixin.js | 8 +++---- tests/components/item.test.js | 44 +++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/mixins/ItemMixin.js b/src/mixins/ItemMixin.js index 26b601e4..51d39e11 100644 --- a/src/mixins/ItemMixin.js +++ b/src/mixins/ItemMixin.js @@ -83,8 +83,8 @@ export default { if (!interval) interval = this.appConfig.pingCheckInterval; if (!interval) return 0; interval = Math.floor(interval); - if (interval < 0) interval = 0; - if (interval > 5) interval = 5; + if (interval < 1) return 0; + if (interval < 5) interval = 5; return interval; }, /* Determine the number of ping icmp packets to send per check */ @@ -99,10 +99,10 @@ export default { }, /* Determine delay in milliseconds for a ping check to complete */ pingCheckTimeout() { + const maxTimeout = this.pingCheckCount * 1000; let timeout = this.item.pingCheckTimeout; if (!timeout) timeout = this.appConfig.pingCheckTimeout; - if (!timeout) return this.pingCheckInterval * 1000; - let maxTimeout = this.pingCheckCount * 1000; + if (!timeout) return Math.min(this.pingCheckInterval * 1000, maxTimeout); if (timeout > maxTimeout) timeout = maxTimeout; if (timeout < 1) timeout = 0; return timeout; diff --git a/tests/components/item.test.js b/tests/components/item.test.js index 484fa486..b5e9bb43 100644 --- a/tests/components/item.test.js +++ b/tests/components/item.test.js @@ -284,30 +284,39 @@ describe('Computed: pingCheckInterval', () => { it('reads from item', () => { const { wrapper } = mountItem({ item: { - id: '1', title: 'X', url: '#', pingCheckInterval: 3, + id: '1', title: 'X', url: '#', pingCheckInterval: 8, }, }); - expect(wrapper.vm.pingCheckInterval).toBe(3); + expect(wrapper.vm.pingCheckInterval).toBe(8); }); it('falls back to appConfig', () => { const { wrapper } = mountItem({ item: { id: '1', title: 'X', url: '#' }, - appConfig: { pingCheckInterval: 4 }, + appConfig: { pingCheckInterval: 20 }, }); - expect(wrapper.vm.pingCheckInterval).toBe(4); + expect(wrapper.vm.pingCheckInterval).toBe(20); }); - it('clamps to max 5', () => { + it('does not cap large intervals', () => { const { wrapper } = mountItem({ item: { - id: '1', title: 'X', url: '#', pingCheckInterval: 15, + id: '1', title: 'X', url: '#', pingCheckInterval: 60, + }, + }); + expect(wrapper.vm.pingCheckInterval).toBe(60); + }); + + it('clamps to a minimum of 5', () => { + const { wrapper } = mountItem({ + item: { + id: '1', title: 'X', url: '#', pingCheckInterval: 3, }, }); expect(wrapper.vm.pingCheckInterval).toBe(5); }); - it('clamps values less than 1 to 0', () => { + it('treats values below 1 as only-on-load (0)', () => { const { wrapper } = mountItem({ item: { id: '1', title: 'X', url: '#', pingCheckInterval: 0.5, @@ -317,6 +326,27 @@ describe('Computed: pingCheckInterval', () => { }); }); +describe('Computed: pingCheckTimeout', () => { + it('caps the interval-derived default at pingCheckCount * 1000', () => { + const { wrapper } = mountItem({ + item: { + id: '1', title: 'X', url: '#', pingCheckInterval: 60, + }, + }); + // count defaults to 3, so the default timeout is capped at 3000ms, not 60000ms + expect(wrapper.vm.pingCheckTimeout).toBe(3000); + }); + + it('clamps an explicit timeout to pingCheckCount * 1000', () => { + const { wrapper } = mountItem({ + item: { + id: '1', title: 'X', url: '#', pingCheckCount: 2, pingCheckTimeout: 99000, + }, + }); + expect(wrapper.vm.pingCheckTimeout).toBe(2000); + }); +}); + describe('Computed: accumulatedTarget', () => { it('uses item.target first', () => { const { wrapper } = mountItem({