Index: test/filterStorage.js |
=================================================================== |
--- a/test/filterStorage.js |
+++ b/test/filterStorage.js |
@@ -34,21 +34,28 @@ |
{FilterNotifier} = sandboxedRequire("../lib/filterNotifier"), |
{FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
{Subscription} = sandboxedRequire("../lib/subscriptionClasses") |
); |
callback(); |
}; |
-function compareSubscriptionList(test, testMessage, list) |
+function compareSubscriptionList(test, testMessage, list, |
+ knownSubscriptions = null) |
{ |
let result = FilterStorage.subscriptions.map(subscription => subscription.url); |
let expected = list.map(subscription => subscription.url); |
test.deepEqual(result, expected, testMessage); |
+ |
+ if (knownSubscriptions) |
+ { |
+ test.deepEqual([...Subscription.knownSubscriptions.values()], |
+ knownSubscriptions, testMessage); |
+ } |
} |
function compareFiltersList(test, testMessage, list) |
{ |
let result = FilterStorage.subscriptions.map( |
subscription => subscription.filters.map( |
filter => filter.text)); |
test.deepEqual(result, list, testMessage); |
@@ -113,34 +120,44 @@ |
let changes = []; |
function listener(action, subscription) |
{ |
if (action.indexOf("subscription.") == 0) |
changes.push(action + " " + subscription.url); |
} |
FilterNotifier.addListener(listener); |
- compareSubscriptionList(test, "Initial state", [subscription1, subscription2]); |
+ compareSubscriptionList(test, "Initial state", [subscription1, subscription2], |
+ [subscription1, subscription2]); |
test.deepEqual(changes, [], "Received changes"); |
changes = []; |
FilterStorage.removeSubscription(subscription1); |
- compareSubscriptionList(test, "Removing first subscription", [subscription2]); |
+ compareSubscriptionList(test, "Removing first subscription", [subscription2], |
+ [subscription2]); |
test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes"); |
changes = []; |
FilterStorage.removeSubscription(subscription1); |
- compareSubscriptionList(test, "Removing already removed subscription", [subscription2]); |
+ compareSubscriptionList(test, "Removing already removed subscription", [subscription2], |
+ [subscription2]); |
test.deepEqual(changes, [], "Received changes"); |
changes = []; |
FilterStorage.removeSubscription(subscription2); |
- compareSubscriptionList(test, "Removing remaining subscription", []); |
+ compareSubscriptionList(test, "Removing remaining subscription", [], []); |
test.deepEqual(changes, ["subscription.removed http://test2/"], "Received changes"); |
+ // Compare references to make sure that a new object is created for the same |
+ // subscription URL. |
+ test.notEqual(Subscription.fromURL(subscription2.url), subscription2, |
+ "Subscription forgotten"); |
+ |
+ // Adding a removed Subscription object back still works but is not |
+ // recommended. |
FilterStorage.addSubscription(subscription1); |
compareSubscriptionList(test, "Add", [subscription1]); |
changes = []; |
FilterStorage.removeSubscription(subscription1); |
compareSubscriptionList(test, "Re-removing previously added subscription", []); |
test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes"); |