Move TopicTrackingState to injected object

This commit is contained in:
Robin Ward
2015-09-03 16:55:55 -04:00
parent 064b62199e
commit 8e776d0fd7
33 changed files with 256 additions and 263 deletions

View File

@@ -1,6 +1,8 @@
import { blank } from 'helpers/qunit-helpers';
import { currentUser } from 'helpers/qunit-helpers';
import KeyValueStore from 'discourse/lib/key-value-store';
import Composer from 'discourse/models/composer';
import createStore from 'helpers/create-store';
module("model:composer");
@@ -9,10 +11,13 @@ 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;
opts.keyValueStore = keyValueStore;
; return Discourse.Composer.create(opts);
return createStore().createRecord('composer', opts);
}
function openComposer(opts) {
const composer = createComposer(opts);
composer.open(opts);
return composer;
}
test('replyLength', function() {
@@ -111,7 +116,7 @@ test("Title length for regular topics", function() {
test("Title length for private messages", function() {
Discourse.SiteSettings.min_private_message_title_length = 5;
Discourse.SiteSettings.max_topic_title_length = 10;
const composer = createComposer({action: Discourse.Composer.PRIVATE_MESSAGE});
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
composer.set('title', 'asdf');
ok(!composer.get('titleLengthValid'), "short titles are not valid");
@@ -126,7 +131,7 @@ test("Title length for private messages", function() {
test("Title length for private messages", function() {
Discourse.SiteSettings.min_private_message_title_length = 5;
Discourse.SiteSettings.max_topic_title_length = 10;
const composer = createComposer({action: Discourse.Composer.PRIVATE_MESSAGE});
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
composer.set('title', 'asdf');
ok(!composer.get('titleLengthValid'), "short titles are not valid");
@@ -143,7 +148,7 @@ test('editingFirstPost', function() {
ok(!composer.get('editingFirstPost'), "it's false by default");
const post = Discourse.Post.create({id: 123, post_number: 2});
composer.setProperties({post: post, action: Discourse.Composer.EDIT });
composer.setProperties({post: post, action: Composer.EDIT });
ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
post.set('post_number', 1);
@@ -170,19 +175,19 @@ test('clearState', function() {
test('initial category when uncategorized is allowed', function() {
Discourse.SiteSettings.allow_uncategorized_topics = true;
const composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
equal(composer.get('categoryId'),undefined,"Uncategorized by default");
});
test('initial category when uncategorized is not allowed', function() {
Discourse.SiteSettings.allow_uncategorized_topics = false;
const composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
ok(composer.get('categoryId') === undefined, "Uncategorized by default. Must choose a category.");
});
test('showPreview', function() {
const newComposer = function() {
return Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
return openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
};
Discourse.Mobile.mobileView = true;
@@ -199,7 +204,7 @@ test('showPreview', function() {
test('open with a quote', function() {
const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
const newComposer = function() {
return Discourse.Composer.open({action: Discourse.Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
return openComposer({action: Discourse.Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
};
equal(newComposer().get('originalText'), quote, "originalText is the quote" );
@@ -212,7 +217,7 @@ test("Title length for static page topics as admin", function() {
const composer = createComposer();
const post = Discourse.Post.create({id: 123, post_number: 2, static_doc: true});
composer.setProperties({post: post, action: Discourse.Composer.EDIT });
composer.setProperties({post: post, action: Composer.EDIT });
composer.set('title', 'asdf');
ok(composer.get('titleLengthValid'), "admins can use short titles");