mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Migrate KeyValueStore to ES6 modules
This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
var store = Discourse.KeyValueStore;
|
||||
import KeyValueStore from "discourse/lib/key-value-store";
|
||||
|
||||
module("Discourse.KeyValueStore", {
|
||||
setup: function() {
|
||||
store.init("test");
|
||||
}
|
||||
});
|
||||
module("lib:key-value-store");
|
||||
|
||||
test("it's able to get the result back from the store", function() {
|
||||
test("it's able to get the result back from the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob", value: "uncle" });
|
||||
equal(store.get("bob"), "uncle");
|
||||
assert.equal(store.get("bob"), "uncle");
|
||||
});
|
||||
|
||||
test("is able to nuke the store", function() {
|
||||
test("is able to nuke the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob1", value: "uncle" });
|
||||
store.abandonLocal();
|
||||
localStorage.a = 1;
|
||||
equal(store.get("bob1"), void 0);
|
||||
equal(localStorage.a, "1");
|
||||
assert.equal(store.get("bob1"), void 0);
|
||||
assert.equal(localStorage.a, "1");
|
||||
});
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import { currentUser } from 'helpers/qunit-helpers';
|
||||
import KeyValueStore from 'discourse/lib/key-value-store';
|
||||
|
||||
module("model:composer");
|
||||
|
||||
const keyValueStore = new KeyValueStore("_test_composer");
|
||||
|
||||
function createComposer(opts) {
|
||||
opts = opts || {};
|
||||
opts.user = opts.user || currentUser();
|
||||
opts.site = Discourse.Site.current();
|
||||
opts.siteSettings = Discourse.SiteSettings;
|
||||
return Discourse.Composer.create(opts);
|
||||
opts.keyValueStore = keyValueStore;
|
||||
; return Discourse.Composer.create(opts);
|
||||
}
|
||||
|
||||
test('replyLength', function() {
|
||||
@@ -184,9 +188,9 @@ test('showPreview', function() {
|
||||
Discourse.Mobile.mobileView = true;
|
||||
equal(newComposer().get('showPreview'), false, "Don't show preview in mobile view");
|
||||
|
||||
Discourse.KeyValueStore.set({ key: 'composer.showPreview', value: 'true' });
|
||||
keyValueStore.set({ key: 'composer.showPreview', value: 'true' });
|
||||
equal(newComposer().get('showPreview'), false, "Don't show preview in mobile view even if KeyValueStore wants to");
|
||||
Discourse.KeyValueStore.remove('composer.showPreview');
|
||||
keyValueStore.remove('composer.showPreview');
|
||||
|
||||
Discourse.Mobile.mobileView = false;
|
||||
equal(newComposer().get('showPreview'), true, "Show preview by default in desktop view");
|
||||
|
||||
Reference in New Issue
Block a user