🐛 Fixes bug in continous status check rounding if less than 5

This commit is contained in:
Alicia Sykes
2026-07-25 15:16:39 +01:00
parent cc94f223a7
commit c38f4a4d47
2 changed files with 41 additions and 11 deletions

View File

@@ -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;

View File

@@ -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({