const LocalStorageInterface = require("../../source/web/LocalStorageInterface.js");

describe("LocalStorageInterface", function() {
    beforeEach(function() {
        this.localStorageInterface = new LocalStorageInterface();
        return this.localStorageInterface
            .getAllKeys()
            .then(keys => Promise.all(keys.map(key => this.localStorageInterface.removeKey(key))));
    });

    describe("getAllKeys", function() {
        it("gets all the keys", function() {
            window.localStorage.setItem("item1", "abc");
            window.localStorage.setItem("z z z", "...");
            return Promise.resolve()
                .then(() => this.localStorageInterface.getAllKeys())
                .then(keys => {
                    expect(keys).to.have.lengthOf(2);
                    expect(keys).to.contain("item1");
                    expect(keys).to.contain("z z z");
                });
        });
    });

    describe("getValue", function() {
        it("gets the correct value", function() {
            window.localStorage.setItem("my item", "my value");
            return this.localStorageInterface.getValue("my item").then(value => {
                expect(value).to.equal("my value");
            });
        });

        it("returns null if no item exists for the provided key", function() {
            return this.localStorageInterface.getValue("noitem").then(value => {
                expect(value).to.equal(null);
            });
        });
    });

    describe("removeKey", function() {
        it("removes items", function() {
            window.localStorage.setItem("my item", "my value");
            return this.localStorageInterface.removeKey("my item").then(() => {
                expect(window.localStorage.getItem("my item")).to.equal(null);
            });
        });

        it("does not throw if item doesn't exist", function() {
            const removal = this.localStorageInterface.removeKey("my item");
            return expect(removal).to.eventually.resolve;
        });
    });
});

@@ -2044,13 +2044,607 @@
 %0A    %7D);
+%0A%0A    describe(%22setValue%22, function() %7B%0A        it(%22sets a new value%22, function() %7B%0A            return this.localStorageInterface.setValue(%22some-thing%22, %22somevalue%22).then(() =%3E %7B%0A                expect(window.localStorage.getItem(%22some-thing%22)).to.equal(%22somevalue%22);%0A            %7D);%0A        %7D);%0A%0A        it(%22overwrites old values%22, function() %7B%0A            window.localStorage.setItem(%22myKey%22, %221%22);%0A            return this.localStorageInterface.setValue(%22myKey%22, %222%22).then(() =%3E %7B%0A                expect(window.localStorage.getItem(%22myKey%22)).to.equal(%222%22);%0A            %7D);%0A        %7D);%0A    %7D);
 %0A%7D);%0A

Add test for LocalStorageInterface's setValue