" + @@ -1348,23 +1349,28 @@ OSApp.UIDom.launchApp = function() { currentSite = siteSelect.val(); OSApp.Storage.get( "sites", function( data ) { sites = OSApp.Sites.parseSites( data.sites ); - if ( typeof sites[ currentSite ].images !== "object" || $.isEmptyObject( sites[ currentSite ].images ) ) { + // Prevent errors during test: page navigation checks + if ( !sites || $.isEmptyObject(sites) || !currentSite ) { + return; + } + + if ( typeof sites[ currentSite ]?.images !== "object" || $.isEmptyObject( sites[ currentSite ].images ) ) { sites[ currentSite ].images = {}; page.removeClass( "has-images" ); } else { page.addClass( "has-images" ); } - if ( typeof sites[ currentSite ].notes !== "object" ) { + if ( typeof sites[ currentSite ]?.notes !== "object" ) { sites[ currentSite ].notes = {}; } - if ( typeof sites[ currentSite ].lastRunTime !== "object" ) { + if ( typeof sites[ currentSite ]?.lastRunTime !== "object" ) { sites[ currentSite ].lastRunTime = {}; } callback(); } ); - }, - cards, siteSelect, currentSite, i, sites; + }; + page.one( "pageshow", function() { $( "html" ).on( "datarefresh", updateContent ); From cbe4f256a433befbb235ceebacffba6242381a77 Mon Sep 17 00:00:00 2001 From: Joel Mello Date: Fri, 29 Nov 2024 11:20:10 -0700 Subject: [PATCH 3/4] chore(tests): refactor test structure --- test/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 9de9115a..7c18d8c4 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -22,7 +22,7 @@ module.exports = function (config) { { pattern: 'www/js/modules/**/*.js', included: true, watched: false }, { pattern: 'www/js/main.js', included: true, watched: false }, 'node_modules/sinon/pkg/sinon.js', - // Prepare the test framework/server + // Prepare the test environment server 'test/prepare_tests.js', // Load all tests 'test/tests/**/*.js', From 4aeddfeba121c41de53ec7ee081ffe75b4bfbc78 Mon Sep 17 00:00:00 2001 From: Joel Mello Date: Fri, 29 Nov 2024 11:40:52 -0700 Subject: [PATCH 4/4] chore(tests): remove duplicate code --- test/prepare_tests.js | 1 - test/tests/general_function_checks.js | 59 --------------------- test/tests/initial_definition_check.js | 59 --------------------- test/tests/logout_cleanup.js | 59 --------------------- test/tests/os_firmware_version_functions.js | 59 --------------------- test/tests/page_navigation_checks.js | 59 --------------------- test/tests/popup_checks.js | 59 --------------------- 7 files changed, 355 deletions(-) diff --git a/test/prepare_tests.js b/test/prepare_tests.js index 991e05bf..dba1f3f9 100644 --- a/test/prepare_tests.js +++ b/test/prepare_tests.js @@ -17,7 +17,6 @@ before(function () { }); before(function() { - console.log("*** tests.js before()"); server = sinon.fakeServer.create(); server.autoRespond = true; diff --git a/test/tests/general_function_checks.js b/test/tests/general_function_checks.js index 9457c67e..1079db35 100644 --- a/test/tests/general_function_checks.js +++ b/test/tests/general_function_checks.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("General Function Checks", function () { it("OSApp.Utils.parseIntArray(array) should convert all members into integers", function () { assert.deepEqual([9, 394, 29193, -1], OSApp.Utils.parseIntArray(["9", "394", "29193", "-1"])); diff --git a/test/tests/initial_definition_check.js b/test/tests/initial_definition_check.js index 9c681f5e..11ec6a99 100644 --- a/test/tests/initial_definition_check.js +++ b/test/tests/initial_definition_check.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("Initial Definition Check", function () { it("storage.set(object,callback) should accept an object of key/value pairs to be set into localStorage and respond with callback", function (done) { assert.doesNotThrow(function () { diff --git a/test/tests/logout_cleanup.js b/test/tests/logout_cleanup.js index edea6d3c..af54f774 100644 --- a/test/tests/logout_cleanup.js +++ b/test/tests/logout_cleanup.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("Logout / Clean up", function () { it("Remove all variables", function (done) { OSApp.Storage.remove(["sites", "current_site", "lang", "runonce"], function () { diff --git a/test/tests/os_firmware_version_functions.js b/test/tests/os_firmware_version_functions.js index a3bb9e38..5d5b27b3 100644 --- a/test/tests/os_firmware_version_functions.js +++ b/test/tests/os_firmware_version_functions.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("OpenSprinkler Firmware Version Functions", function () { describe("Test against Arduino Firmware Version", function () { diff --git a/test/tests/page_navigation_checks.js b/test/tests/page_navigation_checks.js index 4b010e08..f8032b6f 100644 --- a/test/tests/page_navigation_checks.js +++ b/test/tests/page_navigation_checks.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("Page Navigation Checks", function () { before(function () { OSApp.currentSession.ip = "demo.opensprinkler.com"; diff --git a/test/tests/popup_checks.js b/test/tests/popup_checks.js index 62721a18..f35335d0 100644 --- a/test/tests/popup_checks.js +++ b/test/tests/popup_checks.js @@ -13,65 +13,6 @@ * along with this program. If not, see . */ -var assert = chai.assert; -var server; - -before(function() { - server = sinon.fakeServer.create(); - server.autoRespond = true; - - // Mock responses using a function to handle requests - server.respondWith(function(request) { - var url = request.url; - var baseUrl = 'https://demo.opensprinkler.com'; - var urlObj = new URL(url, baseUrl); - var pathname = urlObj.pathname; - var params = new URLSearchParams(urlObj.search); - - if (pathname === '/jp') { - request.respond(200, { "Content-Type": "application/json" }, - '{"nprogs":0,"nboards":1,"mnp":40,"mnst":4,"pnsize":32,"pd":[]}' - ); - } else if (pathname === '/jn') { - request.respond(200, { "Content-Type": "application/json" }, - '{"masop":[255],"masop2":[0],"ignore_rain":[0],"ignore_sn1":[0],"ignore_sn2":[0],"stn_dis":[0],"stn_spe":[0],"stn_grp":[0,0,0,0,0,0,0,0],"snames":["S01","S02","S03","S04","S05","S06","S07","S08"],"maxlen":32}' - ); - } else if (pathname === '/jo') { - request.respond(200, { "Content-Type": "application/json" }, - '{"fwv":221,"tz":28,"hp0":144,"hp1":31,"hwv":255,"ext":0,"sdt":0,"mas":0,"mton":0,"mtof":0,"wl":100,"den":1,"ipas":0,"devid":0,"uwt":0,"ntp1":0,"ntp2":0,"ntp3":0,"ntp4":0,"lg":1,"mas2":0,"mton2":0,"mtof2":0,"fwm":0,"fpr0":100,"fpr1":0,"re":0,"sar":0,"ife":0,"sn1t":0,"sn1o":1,"sn2t":0,"sn2o":1,"sn1on":0,"sn1of":0,"sn2on":0,"sn2of":0,"resv1":0,"resv2":0,"resv3":0,"resv4":0,"resv5":0,"resv6":0,"resv7":0,"resv8":0,"wimod":169,"reset":0,"dexp":-1,"mexp":24,"hwt":255,"ms":[0,0,0,0,0,0]}' - ); - } else if (pathname === '/js') { - request.respond(200, { "Content-Type": "application/json" }, - '{"sn":[0,0,0,0,0,0,0,0],"nstations":8}' - ); - } else if (pathname === '/jc') { - request.respond(200, { "Content-Type": "application/json" }, - '{"devt":1732789106,"nbrd":1,"en":1,"sn1":0,"sn2":0,"rd":0,"rdst":0,"sunrise":412,"sunset":975,"eip":2728304343,"lwc":1732784441,"lswc":1732784441,"lupt":0,"lrbtc":1,"lrun":[0,0,0,0],"pq":0,"pt":0,"nq":0,"otc":{},"otcs":0,"mac":"02:42:AC:12:00:02","loc":"42.36,-71.06","jsp":"https://ui.opensprinkler.com/js","wsp":"weather.opensprinkler.com","wto":{},"ifkey":"","mqtt":{},"wtdata":{"wp":"Manual"},"wterr":0,"dname":"My OpenSprinkler","email":{},"sbits":[0,0],"ps":[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],"gpio":[]}' - ); - } else if (pathname === '/jl') { - // Handle dynamic URLs with start and end query parameters - var type = params.get('type'); - var response; - if (type === 'wl') { - response = `[[0,"wl",100,1732158027],[0,"wl",100,1732179641],[0,"wl",100,1732201255],[0,"wl",100,1732222812],[0,"wl",100,1732244426],[0,"wl",100,1732266040],[0,"wl",100,1732287654],[0,"wl",100,1732309212],[0,"wl",100,1732330826],[0,"wl",100,1732352440],[0,"wl",100,1732374054],[0,"wl",100,1732395613],[0,"wl",100,1732417227],[0,"wl",100,1732438841],[0,"wl",100,1732460455],[0,"wl",100,1732482013],[0,"wl",100,1732503627],[0,"wl",100,1732525241],[0,"wl",100,1732546855],[0,"wl",100,1732568414],[0,"wl",100,1732590028],[0,"wl",100,1732611642],[0,"wl",100,1732633256],[0,"wl",100,1732639575],[0,"wl",100,1732654813],[0,"wl",100,1732676427],[0,"wl",100,1732698041],[0,"wl",100,1732719655],[0,"wl",100,1732741213],[0,"wl",100,1732762827],[0,"wl",100,1732784441]]`; - } else if (type === 'fl') { - response = '[]'; - } else { - response = `[[99,0,64,1732207586],[99,0,64,1732505562],[1,0,60,1732514461],[1,1,60,1732514521]]`; - } - request.respond(200, { "Content-Type": "application/json" }, response); - } else { - request.respond(404, { "Content-Type": "application/json" }, '{"error": "Not Found"}'); - } - }); -}); - -after(function() { - if (server) { - server.restore(); - } -}); - describe("Popup Checks", function () { it( "Show main menu popup", function( done ) {