summaryrefslogtreecommitdiff
path: root/includes/external/matrix/node_modules/loglevel/test/local-storage-test.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
committerRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
commit633c92eae865e957121e08de634aeee11a8b3992 (patch)
tree09d881bee1dae0b6eee49db1dfaf0f500240606c /includes/external/matrix/node_modules/loglevel/test/local-storage-test.js
parentc4657e4509733699c0f26a3c900bab47e915d5a0 (diff)
downloadpluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.gz
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.bz2
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.zip
Updated 18 files, added 1692 files and deleted includes/system/compare.inc (automated)
Diffstat (limited to 'includes/external/matrix/node_modules/loglevel/test/local-storage-test.js')
-rw-r--r--includes/external/matrix/node_modules/loglevel/test/local-storage-test.js208
1 files changed, 208 insertions, 0 deletions
diff --git a/includes/external/matrix/node_modules/loglevel/test/local-storage-test.js b/includes/external/matrix/node_modules/loglevel/test/local-storage-test.js
new file mode 100644
index 0000000..7e68dd4
--- /dev/null
+++ b/includes/external/matrix/node_modules/loglevel/test/local-storage-test.js
@@ -0,0 +1,208 @@
+"use strict";
+
+define(['test/test-helpers'], function(testHelpers) {
+ var describeIf = testHelpers.describeIf;
+ var it = testHelpers.itWithFreshLog;
+
+ var originalConsole = window.console;
+
+ describeIf(testHelpers.isLocalStorageAvailable(), "Local storage persistence tests:", function() {
+
+ beforeEach(function() {
+ window.console = {"log" : jasmine.createSpy("console.log")};
+ this.addMatchers({
+ "toBeAtLevel" : testHelpers.toBeAtLevel,
+ "toBeTheStoredLevel" : testHelpers.toBeTheLevelStoredByLocalStorage,
+ "toBeTheLevelStoredByLocalStorage": testHelpers.toBeTheLevelStoredByLocalStorage,
+ "toBeTheLevelStoredByCookie": testHelpers.toBeTheLevelStoredByCookie
+ });
+
+ testHelpers.clearStoredLevels();
+ });
+
+ afterEach(function() {
+ window.console = originalConsole;
+ });
+
+ describe("If no level is saved", function() {
+ it("log level is set to warn by default", function(log) {
+ expect(log).toBeAtLevel("warn");
+ });
+
+ it("warn is not persisted as the current level", function(log) {
+ expect("warn").not.toBeTheStoredLevel();
+ });
+
+ it("log can be set to info level", function(log) {
+ log.setLevel("info");
+ expect(log).toBeAtLevel("info");
+ });
+
+ it("log.setLevel() sets a cookie with the given level", function(log) {
+ log.setLevel("debug");
+ expect("debug").toBeTheStoredLevel();
+ });
+
+ it("log.setLevel() does not set a cookie if `persist` argument is false", function(log) {
+ log.setLevel("debug", false);
+ expect("debug").not.toBeTheStoredLevel();
+ });
+ });
+
+ describe("If trace level is saved", function () {
+ beforeEach(function () {
+ testHelpers.setStoredLevel("trace");
+ });
+
+ it("trace is the default log level", function (log) {
+ expect(log).toBeAtLevel("trace");
+ });
+ });
+
+ describe("If debug level is saved", function () {
+ beforeEach(function () {
+ testHelpers.setStoredLevel("debug");
+ });
+
+ it("debug is the default log level", function (log) {
+ expect(log).toBeAtLevel("debug");
+ });
+ });
+
+ describe("If info level is saved", function() {
+ beforeEach(function() {
+ testHelpers.setStoredLevel("info");
+ });
+
+ it("info is the default log level", function(log) {
+ expect(log).toBeAtLevel("info");
+ });
+
+ it("log can be changed to warn level", function(log) {
+ log.setLevel("warn");
+ expect(log).toBeAtLevel("warn");
+ });
+
+ it("log.setLevel() overwrites the saved level", function(log) {
+ log.setLevel("error");
+
+ expect("error").toBeTheStoredLevel();
+ expect("info").not.toBeTheStoredLevel();
+ });
+
+ it("log.setLevel() does not overwrite the saved level if `persist` argument is false", function(log) {
+ log.setLevel("error", false);
+
+ expect("info").toBeTheStoredLevel();
+ expect("error").not.toBeTheStoredLevel();
+ });
+
+ it("log.resetLevel() clears the saved level", function(log) {
+ log.resetLevel();
+
+ expect(undefined).toBeTheStoredLevel();
+ expect("info").not.toBeTheStoredLevel();
+ });
+ });
+
+ describe("If warn level is saved", function () {
+ beforeEach(function () {
+ testHelpers.setStoredLevel("warn");
+ });
+
+ it("warn is the default log level", function (log) {
+ expect(log).toBeAtLevel("warn");
+ });
+ });
+
+ describe("If error level is saved", function () {
+ beforeEach(function () {
+ testHelpers.setStoredLevel("error");
+ });
+
+ it("error is the default log level", function (log) {
+ expect(log).toBeAtLevel("error");
+ });
+ });
+
+
+ describe("If the level is saved with other data", function() {
+ beforeEach(function() {
+ window.localStorage['qwe'] = "asd";
+ window.localStorage['loglevel'] = "ERROR";
+ window.localStorage['msg'] = "hello world";
+ });
+
+ it("error is the default log level", function(log) {
+ expect(log).toBeAtLevel("error");
+ });
+
+ it("log can be changed to silent level", function(log) {
+ log.setLevel("silent");
+ expect(log).toBeAtLevel("silent");
+ });
+
+ it("log.setLevel() overrides the saved level only", function(log) {
+ log.setLevel("debug");
+
+ expect('debug').toBeTheStoredLevel();
+ expect(window.localStorage['msg']).toBe("hello world");
+ });
+ });
+
+ describe("If the level is stored incorrectly", function() {
+ beforeEach(function() {
+ testHelpers.setLocalStorageStoredLevel('gibberish');
+ });
+
+ it("warn is the default log level", function(log) {
+ expect(log).toBeAtLevel("warn");
+ });
+
+ it("warn is not persisted as the current level", function(log) {
+ expect("warn").not.toBeTheStoredLevel();
+ });
+
+ it("log can be changed to info level", function(log) {
+ log.setLevel("info");
+ expect(log).toBeAtLevel("info");
+ });
+
+ it("log.setLevel() overrides the saved level with the new level", function(log) {
+ expect('debug').not.toBeTheStoredLevel();
+
+ log.setLevel("debug");
+
+ expect('debug').toBeTheStoredLevel();
+ });
+ });
+
+ describeIf(testHelpers.isCookieStorageAvailable() && testHelpers.isLocalStorageAvailable(),
+ "if localStorage and cookies are both available", function () {
+
+ it("the level stored in cookies is ignored if a local storage level is set", function () {
+ testHelpers.setCookieStoredLevel("info");
+ testHelpers.setLocalStorageStoredLevel("debug");
+
+ testHelpers.withFreshLog(function (log) {
+ expect(log).toBeAtLevel("debug");
+ });
+ });
+
+ it("the level stored in cookies is used if no local storage level is set", function () {
+ testHelpers.setCookieStoredLevel("info");
+ window.localStorage.clear();
+
+ testHelpers.withFreshLog(function (log) {
+ expect(log).toBeAtLevel("info");
+ });
+ });
+
+ it("the local storage level is set and the cookie level is not", function (log) {
+ log.setLevel("error");
+ expect("error").toBeTheLevelStoredByLocalStorage();
+ expect("error").not.toBeTheLevelStoredByCookie();
+ });
+ });
+ });
+});