mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Upgrade QUnit to latest version
This commit is contained in:
@@ -1,51 +1,51 @@
|
||||
import Badge from 'discourse/models/badge';
|
||||
|
||||
module("model:badge");
|
||||
QUnit.module("model:badge");
|
||||
|
||||
test('newBadge', function() {
|
||||
QUnit.test('newBadge', assert => {
|
||||
const badge1 = Badge.create({name: "New Badge"}),
|
||||
badge2 = Badge.create({id: 1, name: "Old Badge"});
|
||||
ok(badge1.get('newBadge'), "badges without ids are new");
|
||||
ok(!badge2.get('newBadge'), "badges with ids are not new");
|
||||
assert.ok(badge1.get('newBadge'), "badges without ids are new");
|
||||
assert.ok(!badge2.get('newBadge'), "badges with ids are not new");
|
||||
});
|
||||
|
||||
|
||||
test('createFromJson array', function() {
|
||||
QUnit.test('createFromJson array', assert => {
|
||||
const badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]};
|
||||
|
||||
const badges = Badge.createFromJson(badgesJson);
|
||||
|
||||
ok(Array.isArray(badges), "returns an array");
|
||||
equal(badges[0].get('name'), "Badge 1", "badge details are set");
|
||||
equal(badges[0].get('badge_type.name'), "Silver 1", "badge_type reference is set");
|
||||
assert.ok(Array.isArray(badges), "returns an array");
|
||||
assert.equal(badges[0].get('name'), "Badge 1", "badge details are set");
|
||||
assert.equal(badges[0].get('badge_type.name'), "Silver 1", "badge_type reference is set");
|
||||
});
|
||||
|
||||
test('createFromJson single', function() {
|
||||
QUnit.test('createFromJson single', assert => {
|
||||
const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}};
|
||||
|
||||
const badge = Badge.createFromJson(badgeJson);
|
||||
|
||||
ok(!Array.isArray(badge), "does not returns an array");
|
||||
assert.ok(!Array.isArray(badge), "does not returns an array");
|
||||
});
|
||||
|
||||
test('updateFromJson', function() {
|
||||
QUnit.test('updateFromJson', assert => {
|
||||
const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}};
|
||||
const badge = Badge.create({name: "Badge 1"});
|
||||
badge.updateFromJson(badgeJson);
|
||||
equal(badge.get('id'), 1126, "id is set");
|
||||
equal(badge.get('badge_type.name'), "Silver 1", "badge_type reference is set");
|
||||
assert.equal(badge.get('id'), 1126, "id is set");
|
||||
assert.equal(badge.get('badge_type.name'), "Silver 1", "badge_type reference is set");
|
||||
});
|
||||
|
||||
test('save', function() {
|
||||
expect(0);
|
||||
QUnit.test('save', assert => {
|
||||
assert.expect(0);
|
||||
const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
|
||||
return badge.save(["name", "description", "badge_type_id"]);
|
||||
});
|
||||
|
||||
test('destroy', function() {
|
||||
expect(0);
|
||||
QUnit.test('destroy', assert => {
|
||||
assert.expect(0);
|
||||
const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
|
||||
badge.destroy();
|
||||
badge.set('id', 3);
|
||||
return badge.destroy();
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import createStore from 'helpers/create-store';
|
||||
import Category from 'discourse/models/category';
|
||||
|
||||
module("model:category");
|
||||
QUnit.module("model:category");
|
||||
|
||||
test('slugFor', function(){
|
||||
QUnit.test('slugFor', assert =>{
|
||||
const store = createStore();
|
||||
|
||||
const slugFor = function(cat, val, text) {
|
||||
equal(Discourse.Category.slugFor(cat), val, text);
|
||||
assert.equal(Discourse.Category.slugFor(cat), val, text);
|
||||
};
|
||||
|
||||
slugFor(store.createRecord('category', {slug: 'hello'}), "hello", "It calculates the proper slug for hello");
|
||||
@@ -31,8 +31,8 @@ test('slugFor', function(){
|
||||
});
|
||||
|
||||
|
||||
test('findBySlug', function() {
|
||||
expect(6);
|
||||
QUnit.test('findBySlug', assert => {
|
||||
assert.expect(6);
|
||||
|
||||
const store = createStore();
|
||||
const darth = store.createRecord('category', {id: 1, slug: 'darth'}),
|
||||
@@ -45,18 +45,18 @@ test('findBySlug', function() {
|
||||
|
||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||
|
||||
deepEqual(Discourse.Category.findBySlug('darth'), darth, 'we can find a category');
|
||||
deepEqual(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find the other category with parent category');
|
||||
deepEqual(Discourse.Category.findBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('darth'), darth, 'we can find a category');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find the other category with parent category');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
assert.deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('findSingleBySlug', function() {
|
||||
expect(6);
|
||||
QUnit.test('findSingleBySlug', assert => {
|
||||
assert.expect(6);
|
||||
|
||||
const store = createStore();
|
||||
const darth = store.createRecord('category', {id: 1, slug: 'darth'}),
|
||||
@@ -69,15 +69,15 @@ test('findSingleBySlug', function() {
|
||||
|
||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth'), darth, 'we can find a category');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth/luke'), luke, 'we can find the other category with parent category');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/뉴스피드'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth/时间'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/bah'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('darth'), darth, 'we can find a category');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('darth/luke'), luke, 'we can find the other category with parent category');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/뉴스피드'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('darth/时间'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/bah'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
});
|
||||
|
||||
test('findByIds', function() {
|
||||
QUnit.test('findByIds', assert => {
|
||||
const store = createStore();
|
||||
const categories = {
|
||||
1: store.createRecord('category', {id: 1}),
|
||||
@@ -85,25 +85,25 @@ test('findByIds', function() {
|
||||
};
|
||||
|
||||
sandbox.stub(Discourse.Category, 'idMap').returns(categories);
|
||||
deepEqual(Discourse.Category.findByIds([1,2,3]), _.values(categories));
|
||||
assert.deepEqual(Discourse.Category.findByIds([1,2,3]), _.values(categories));
|
||||
});
|
||||
|
||||
test('search with category name', () => {
|
||||
QUnit.test('search with category name', assert => {
|
||||
const store = createStore(),
|
||||
category1 = store.createRecord('category', { id: 1, name: 'middle term', slug: 'different-slug' }),
|
||||
category2 = store.createRecord('category', { id: 2, name: 'middle term', slug: 'another-different-slug' });
|
||||
|
||||
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
|
||||
|
||||
deepEqual(Category.search('term', { limit: 0 }), [], "returns an empty array when limit is 0");
|
||||
deepEqual(Category.search(''), [category1, category2], "orders by activity if no term is matched");
|
||||
deepEqual(Category.search('term'), [category1, category2], "orders by activity");
|
||||
assert.deepEqual(Category.search('term', { limit: 0 }), [], "returns an empty array when limit is 0");
|
||||
assert.deepEqual(Category.search(''), [category1, category2], "orders by activity if no term is matched");
|
||||
assert.deepEqual(Category.search('term'), [category1, category2], "orders by activity");
|
||||
|
||||
category2.set('name', 'TeRm start');
|
||||
deepEqual(Category.search('tErM'), [category2, category1], "ignores case of category name and search term");
|
||||
assert.deepEqual(Category.search('tErM'), [category2, category1], "ignores case of category name and search term");
|
||||
|
||||
category2.set('name', 'term start');
|
||||
deepEqual(Category.search('term'), [category2, category1], "orders matching begin with and then contains");
|
||||
assert.deepEqual(Category.search('term'), [category2, category1], "orders matching begin with and then contains");
|
||||
|
||||
sandbox.restore();
|
||||
|
||||
@@ -112,35 +112,35 @@ test('search with category name', () => {
|
||||
|
||||
sandbox.stub(Category, "listByActivity").returns([read_restricted_category, category1, child_category1, category2]);
|
||||
|
||||
deepEqual(Category.search(''),
|
||||
assert.deepEqual(Category.search(''),
|
||||
[category1, category2, read_restricted_category],
|
||||
"prioritize non read_restricted and does not include child categories when term is blank");
|
||||
|
||||
deepEqual(Category.search('', { limit: 3 }),
|
||||
assert.deepEqual(Category.search('', { limit: 3 }),
|
||||
[category1, category2, read_restricted_category],
|
||||
"prioritize non read_restricted and does not include child categories categories when term is blank with limit");
|
||||
|
||||
deepEqual(Category.search('term'),
|
||||
assert.deepEqual(Category.search('term'),
|
||||
[child_category1, category2, category1, read_restricted_category],
|
||||
"prioritize non read_restricted");
|
||||
|
||||
deepEqual(Category.search('term', { limit: 3 }),
|
||||
assert.deepEqual(Category.search('term', { limit: 3 }),
|
||||
[child_category1, category2, read_restricted_category],
|
||||
"prioritize non read_restricted with limit");
|
||||
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('search with category slug', () => {
|
||||
QUnit.test('search with category slug', assert => {
|
||||
const store = createStore(),
|
||||
category1 = store.createRecord('category', { id: 1, name: 'middle term', slug: 'different-slug' }),
|
||||
category2 = store.createRecord('category', { id: 2, name: 'middle term', slug: 'another-different-slug' });
|
||||
|
||||
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
|
||||
|
||||
deepEqual(Category.search('different-slug'), [category1, category2], "returns the right categories");
|
||||
deepEqual(Category.search('another-different'), [category2], "returns the right categories");
|
||||
assert.deepEqual(Category.search('different-slug'), [category1, category2], "returns the right categories");
|
||||
assert.deepEqual(Category.search('another-different'), [category2], "returns the right categories");
|
||||
|
||||
category2.set('slug', 'ANOTher-DIFfereNT');
|
||||
deepEqual(Category.search('anOtHer-dIfFeREnt'), [category2], "ignores case of category slug and search term");
|
||||
assert.deepEqual(Category.search('anOtHer-dIfFeREnt'), [category2], "ignores case of category slug and search term");
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import { currentUser } from 'helpers/qunit-helpers';
|
||||
import Composer from 'discourse/models/composer';
|
||||
import createStore from 'helpers/create-store';
|
||||
|
||||
module("model:composer");
|
||||
QUnit.module("model:composer");
|
||||
|
||||
function createComposer(opts) {
|
||||
opts = opts || {};
|
||||
@@ -17,10 +16,10 @@ function openComposer(opts) {
|
||||
return composer;
|
||||
}
|
||||
|
||||
test('replyLength', function() {
|
||||
QUnit.test('replyLength', assert => {
|
||||
const replyLength = function(val, expectedLength) {
|
||||
const composer = createComposer({ reply: val });
|
||||
equal(composer.get('replyLength'), expectedLength);
|
||||
assert.equal(composer.get('replyLength'), expectedLength);
|
||||
};
|
||||
|
||||
replyLength("basic reply", 11, "basic reply length");
|
||||
@@ -30,11 +29,11 @@ test('replyLength', function() {
|
||||
replyLength("1[quote=]not[quote=]counted[/quote]yay[/quote]2", 2, "handles nested quotes correctly");
|
||||
});
|
||||
|
||||
test('missingReplyCharacters', function() {
|
||||
QUnit.test('missingReplyCharacters', assert => {
|
||||
Discourse.SiteSettings.min_first_post_length = 40;
|
||||
const missingReplyCharacters = function(val, isPM, isFirstPost, expected, message) {
|
||||
const composer = createComposer({ reply: val, creatingPrivateMessage: isPM, creatingTopic: isFirstPost });
|
||||
equal(composer.get('missingReplyCharacters'), expected, message);
|
||||
assert.equal(composer.get('missingReplyCharacters'), expected, message);
|
||||
};
|
||||
|
||||
missingReplyCharacters('hi', false, false, Discourse.SiteSettings.min_post_length - 2, 'too short public post');
|
||||
@@ -44,144 +43,144 @@ test('missingReplyCharacters', function() {
|
||||
const link = "http://imgur.com/gallery/grxX8";
|
||||
const composer = createComposer({ canEditTopicFeaturedLink: true, title: link, featuredLink: link, reply: link });
|
||||
|
||||
equal(composer.get('missingReplyCharacters'), 0, "don't require any post content");
|
||||
assert.equal(composer.get('missingReplyCharacters'), 0, "don't require any post content");
|
||||
});
|
||||
|
||||
test('missingTitleCharacters', function() {
|
||||
QUnit.test('missingTitleCharacters', assert => {
|
||||
const missingTitleCharacters = function(val, isPM, expected, message) {
|
||||
const composer = createComposer({ title: val, creatingPrivateMessage: isPM });
|
||||
equal(composer.get('missingTitleCharacters'), expected, message);
|
||||
assert.equal(composer.get('missingTitleCharacters'), expected, message);
|
||||
};
|
||||
|
||||
missingTitleCharacters('hi', false, Discourse.SiteSettings.min_topic_title_length - 2, 'too short post title');
|
||||
missingTitleCharacters('z', true, Discourse.SiteSettings.min_private_message_title_length - 1, 'too short pm title');
|
||||
});
|
||||
|
||||
test('replyDirty', function() {
|
||||
QUnit.test('replyDirty', assert => {
|
||||
const composer = createComposer();
|
||||
ok(!composer.get('replyDirty'), "by default it's false");
|
||||
assert.ok(!composer.get('replyDirty'), "by default it's false");
|
||||
|
||||
composer.setProperties({
|
||||
originalText: "hello",
|
||||
reply: "hello"
|
||||
});
|
||||
|
||||
ok(!composer.get('replyDirty'), "it's false when the originalText is the same as the reply");
|
||||
assert.ok(!composer.get('replyDirty'), "it's false when the originalText is the same as the reply");
|
||||
composer.set('reply', 'hello world');
|
||||
ok(composer.get('replyDirty'), "it's true when the reply changes");
|
||||
assert.ok(composer.get('replyDirty'), "it's true when the reply changes");
|
||||
});
|
||||
|
||||
test("appendText", function() {
|
||||
QUnit.test("appendText", assert => {
|
||||
const composer = createComposer();
|
||||
|
||||
blank(composer.get('reply'), "the reply is blank by default");
|
||||
assert.blank(composer.get('reply'), "the reply is blank by default");
|
||||
|
||||
composer.appendText("hello");
|
||||
equal(composer.get('reply'), "hello", "it appends text to nothing");
|
||||
assert.equal(composer.get('reply'), "hello", "it appends text to nothing");
|
||||
composer.appendText(" world");
|
||||
equal(composer.get('reply'), "hello world", "it appends text to existing text");
|
||||
assert.equal(composer.get('reply'), "hello world", "it appends text to existing text");
|
||||
|
||||
composer.clearState();
|
||||
composer.appendText("a\n\n\n\nb");
|
||||
composer.appendText("c",3,{block: true});
|
||||
|
||||
equal(composer.get("reply"), "a\n\nc\n\nb");
|
||||
assert.equal(composer.get("reply"), "a\n\nc\n\nb");
|
||||
|
||||
composer.clearState();
|
||||
composer.appendText("ab");
|
||||
composer.appendText("c",1,{block: true});
|
||||
|
||||
equal(composer.get("reply"), "a\n\nc\n\nb");
|
||||
assert.equal(composer.get("reply"), "a\n\nc\n\nb");
|
||||
|
||||
composer.clearState();
|
||||
composer.appendText("\nab");
|
||||
composer.appendText("c",0,{block: true});
|
||||
|
||||
equal(composer.get("reply"), "c\n\nab");
|
||||
assert.equal(composer.get("reply"), "c\n\nab");
|
||||
});
|
||||
|
||||
test("prependText", function() {
|
||||
QUnit.test("prependText", assert => {
|
||||
const composer = createComposer();
|
||||
|
||||
blank(composer.get('reply'), "the reply is blank by default");
|
||||
assert.blank(composer.get('reply'), "the reply is blank by default");
|
||||
|
||||
composer.prependText("hello");
|
||||
equal(composer.get('reply'), "hello", "it prepends text to nothing");
|
||||
assert.equal(composer.get('reply'), "hello", "it prepends text to nothing");
|
||||
|
||||
composer.prependText("world ");
|
||||
equal(composer.get('reply'), "world hello", "it prepends text to existing text");
|
||||
assert.equal(composer.get('reply'), "world hello", "it prepends text to existing text");
|
||||
|
||||
composer.prependText("before new line", {new_line: true});
|
||||
equal(composer.get('reply'), "before new line\n\nworld hello", "it prepends text with new line to existing text");
|
||||
assert.equal(composer.get('reply'), "before new line\n\nworld hello", "it prepends text with new line to existing text");
|
||||
});
|
||||
|
||||
test("Title length for regular topics", function() {
|
||||
QUnit.test("Title length for regular topics", assert => {
|
||||
Discourse.SiteSettings.min_topic_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
const composer = createComposer();
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
assert.ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test("Title length for private messages", function() {
|
||||
QUnit.test("Title length for private messages", assert => {
|
||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
assert.ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test("Title length for private messages", function() {
|
||||
QUnit.test("Title length for private messages", assert => {
|
||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
assert.ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
assert.ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test("Post length for private messages with non human users", function() {
|
||||
QUnit.test("Post length for private messages with non human users", assert => {
|
||||
const composer = createComposer({
|
||||
topic: Ember.Object.create({ pm_with_non_human_user: true })
|
||||
});
|
||||
|
||||
equal(composer.get('minimumPostLength'), 1);
|
||||
assert.equal(composer.get('minimumPostLength'), 1);
|
||||
});
|
||||
|
||||
test('editingFirstPost', function() {
|
||||
QUnit.test('editingFirstPost', assert => {
|
||||
const composer = createComposer();
|
||||
ok(!composer.get('editingFirstPost'), "it's false by default");
|
||||
assert.ok(!composer.get('editingFirstPost'), "it's false by default");
|
||||
|
||||
const post = Discourse.Post.create({id: 123, post_number: 2});
|
||||
composer.setProperties({post: post, action: Composer.EDIT });
|
||||
ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
|
||||
assert.ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
|
||||
|
||||
post.set('post_number', 1);
|
||||
ok(composer.get('editingFirstPost'), "it's true when editing the first post");
|
||||
assert.ok(composer.get('editingFirstPost'), "it's true when editing the first post");
|
||||
|
||||
});
|
||||
|
||||
test('clearState', function() {
|
||||
QUnit.test('clearState', assert => {
|
||||
const composer = createComposer({
|
||||
originalText: 'asdf',
|
||||
reply: 'asdf2',
|
||||
@@ -191,36 +190,36 @@ test('clearState', function() {
|
||||
|
||||
composer.clearState();
|
||||
|
||||
blank(composer.get('originalText'));
|
||||
blank(composer.get('reply'));
|
||||
blank(composer.get('post'));
|
||||
blank(composer.get('title'));
|
||||
assert.blank(composer.get('originalText'));
|
||||
assert.blank(composer.get('reply'));
|
||||
assert.blank(composer.get('post'));
|
||||
assert.blank(composer.get('title'));
|
||||
|
||||
});
|
||||
|
||||
test('initial category when uncategorized is allowed', function() {
|
||||
QUnit.test('initial category when uncategorized is allowed', assert => {
|
||||
Discourse.SiteSettings.allow_uncategorized_topics = true;
|
||||
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
||||
ok(!composer.get('categoryId'), "Uncategorized by default");
|
||||
assert.ok(!composer.get('categoryId'), "Uncategorized by default");
|
||||
});
|
||||
|
||||
test('initial category when uncategorized is not allowed', function() {
|
||||
QUnit.test('initial category when uncategorized is not allowed', assert => {
|
||||
Discourse.SiteSettings.allow_uncategorized_topics = false;
|
||||
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
||||
ok(!composer.get('categoryId'), "Uncategorized by default. Must choose a category.");
|
||||
assert.ok(!composer.get('categoryId'), "Uncategorized by default. Must choose a category.");
|
||||
});
|
||||
|
||||
test('open with a quote', function() {
|
||||
QUnit.test('open with a quote', assert => {
|
||||
const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
|
||||
const newComposer = function() {
|
||||
return openComposer({action: Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
|
||||
};
|
||||
|
||||
equal(newComposer().get('originalText'), quote, "originalText is the quote" );
|
||||
equal(newComposer().get('replyDirty'), false, "replyDirty is initally false with a quote" );
|
||||
assert.equal(newComposer().get('originalText'), quote, "originalText is the quote" );
|
||||
assert.equal(newComposer().get('replyDirty'), false, "replyDirty is initally false with a quote" );
|
||||
});
|
||||
|
||||
test("Title length for static page topics as admin", function() {
|
||||
QUnit.test("Title length for static page topics as admin", assert => {
|
||||
Discourse.SiteSettings.min_topic_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
const composer = createComposer();
|
||||
@@ -229,38 +228,38 @@ test("Title length for static page topics as admin", function() {
|
||||
composer.setProperties({post: post, action: Composer.EDIT });
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(composer.get('titleLengthValid'), "admins can use short titles");
|
||||
assert.ok(composer.get('titleLengthValid'), "admins can use short titles");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(composer.get('titleLengthValid'), "admins can use long titles");
|
||||
assert.ok(composer.get('titleLengthValid'), "admins can use long titles");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
assert.ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
|
||||
composer.set('title', '');
|
||||
ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character");
|
||||
assert.ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character");
|
||||
});
|
||||
|
||||
test("title placeholder depends on what you're doing", function() {
|
||||
QUnit.test("title placeholder depends on what you're doing", assert => {
|
||||
let composer = createComposer({action: Composer.CREATE_TOPIC});
|
||||
equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for normal topic");
|
||||
assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for normal topic");
|
||||
|
||||
composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||
equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message");
|
||||
assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message");
|
||||
|
||||
Discourse.SiteSettings.topic_featured_link_enabled = true;
|
||||
|
||||
composer = createComposer({action: Composer.CREATE_TOPIC});
|
||||
equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link");
|
||||
assert.equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link");
|
||||
|
||||
composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||
equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message with topic links enabled");
|
||||
assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message with topic links enabled");
|
||||
});
|
||||
|
||||
test("allows featured link before choosing a category", function() {
|
||||
QUnit.test("allows featured link before choosing a category", assert => {
|
||||
Discourse.SiteSettings.topic_featured_link_enabled = true;
|
||||
Discourse.SiteSettings.allow_uncategorized_topics = false;
|
||||
let composer = createComposer({action: Composer.CREATE_TOPIC});
|
||||
equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link");
|
||||
ok(composer.get('canEditTopicFeaturedLink'), "can paste link");
|
||||
});
|
||||
assert.equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link");
|
||||
assert.ok(composer.get('canEditTopicFeaturedLink'), "can paste link");
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import EmailLog from 'admin/models/email-log';
|
||||
|
||||
module("Discourse.EmailLog");
|
||||
QUnit.module("Discourse.EmailLog");
|
||||
|
||||
test("create", function() {
|
||||
ok(EmailLog.create(), "it can be created without arguments");
|
||||
});
|
||||
QUnit.test("create", assert => {
|
||||
assert.ok(EmailLog.create(), "it can be created without arguments");
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import Group from 'discourse/models/group';
|
||||
|
||||
module("model:group");
|
||||
QUnit.module("model:group");
|
||||
|
||||
test('displayName', function() {
|
||||
QUnit.test('displayName', assert => {
|
||||
const group = Group.create({ name: "test", display_name: 'donkey' });
|
||||
|
||||
ok(group.get('displayName'), "donkey", 'it should return the display name');
|
||||
assert.ok(group.get('displayName'), "donkey", 'it should return the display name');
|
||||
|
||||
group.set('display_name', null);
|
||||
|
||||
ok(group.get('displayName'), "test", "it should return the group's name");
|
||||
});
|
||||
assert.ok(group.get('displayName'), "test", "it should return the group's name");
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import Invite from 'discourse/models/invite';
|
||||
|
||||
module("model:invite");
|
||||
QUnit.module("model:invite");
|
||||
|
||||
test("create", function() {
|
||||
ok(Invite.create(), "it can be created without arguments");
|
||||
});
|
||||
QUnit.test("create", assert => {
|
||||
assert.ok(Invite.create(), "it can be created without arguments");
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import Model from 'discourse/models/model';
|
||||
|
||||
module("model:discourse");
|
||||
QUnit.module("model:discourse");
|
||||
|
||||
test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() {
|
||||
QUnit.test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", assert => {
|
||||
var firstObject = {id: "id_1", foo: "foo_1"};
|
||||
var secondObject = {id: "id_2", foo: "foo_2"};
|
||||
|
||||
@@ -12,10 +12,10 @@ test("extractByKey: converts a list of hashes into a hash of instances of specif
|
||||
id_2: Ember.Object.create(secondObject)
|
||||
};
|
||||
|
||||
ok(_.isEqual(actual, expected));
|
||||
assert.ok(_.isEqual(actual, expected));
|
||||
});
|
||||
|
||||
test("extractByKey: returns an empty hash if there isn't anything to convert", function() {
|
||||
deepEqual(Model.extractByKey(), {}, "when called without parameters");
|
||||
deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
|
||||
});
|
||||
QUnit.test("extractByKey: returns an empty hash if there isn't anything to convert", assert => {
|
||||
assert.deepEqual(Model.extractByKey(), {}, "when called without parameters");
|
||||
assert.deepEqual(Model.extractByKey([]), {}, "when called with an empty array");
|
||||
});
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
module("Discourse.NavItem", {
|
||||
setup: function() {
|
||||
QUnit.module("Discourse.NavItem", {
|
||||
beforeEach() {
|
||||
Ember.run(function() {
|
||||
const asianCategory = Discourse.Category.create({name: '确实是这样', id: 343434});
|
||||
Discourse.Site.currentProp('categories').addObject(asianCategory);
|
||||
@@ -8,11 +7,11 @@ module("Discourse.NavItem", {
|
||||
}
|
||||
});
|
||||
|
||||
test('href', function(){
|
||||
expect(4);
|
||||
QUnit.test('href', assert =>{
|
||||
assert.expect(4);
|
||||
|
||||
function href(text, expected, label) {
|
||||
equal(Discourse.NavItem.fromText(text, {}).get('href'), expected, label);
|
||||
assert.equal(Discourse.NavItem.fromText(text, {}).get('href'), expected, label);
|
||||
}
|
||||
|
||||
href('latest', '/latest', 'latest');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
module("model:post-stream");
|
||||
QUnit.module("model:post-stream");
|
||||
|
||||
import createStore from 'helpers/create-store';
|
||||
|
||||
@@ -15,93 +14,93 @@ const buildStream = function(id, stream) {
|
||||
|
||||
const participant = {username: 'eviltrout'};
|
||||
|
||||
test('create', function() {
|
||||
QUnit.test('create', assert => {
|
||||
const store = createStore();
|
||||
ok(store.createRecord('postStream'), 'it can be created with no parameters');
|
||||
assert.ok(store.createRecord('postStream'), 'it can be created with no parameters');
|
||||
});
|
||||
|
||||
test('defaults', function() {
|
||||
QUnit.test('defaults', assert => {
|
||||
const postStream = buildStream(1234);
|
||||
blank(postStream.get('posts'), "there are no posts in a stream by default");
|
||||
ok(!postStream.get('loaded'), "it has never loaded");
|
||||
present(postStream.get('topic'));
|
||||
assert.blank(postStream.get('posts'), "there are no posts in a stream by default");
|
||||
assert.ok(!postStream.get('loaded'), "it has never loaded");
|
||||
assert.present(postStream.get('topic'));
|
||||
});
|
||||
|
||||
test('appending posts', function() {
|
||||
QUnit.test('appending posts', assert => {
|
||||
const postStream = buildStream(4567, [1, 3, 4]);
|
||||
const store = postStream.store;
|
||||
|
||||
equal(postStream.get('firstPostId'), 1);
|
||||
equal(postStream.get('lastPostId'), 4, "the last post id is 4");
|
||||
assert.equal(postStream.get('firstPostId'), 1);
|
||||
assert.equal(postStream.get('lastPostId'), 4, "the last post id is 4");
|
||||
|
||||
ok(!postStream.get('hasPosts'), "there are no posts by default");
|
||||
ok(!postStream.get('firstPostPresent'), "the first post is not loaded");
|
||||
ok(!postStream.get('loadedAllPosts'), "the last post is not loaded");
|
||||
equal(postStream.get('posts.length'), 0, "it has no posts initially");
|
||||
assert.ok(!postStream.get('hasPosts'), "there are no posts by default");
|
||||
assert.ok(!postStream.get('firstPostPresent'), "the first post is not loaded");
|
||||
assert.ok(!postStream.get('loadedAllPosts'), "the last post is not loaded");
|
||||
assert.equal(postStream.get('posts.length'), 0, "it has no posts initially");
|
||||
|
||||
postStream.appendPost(store.createRecord('post', {id: 2, post_number: 2}));
|
||||
ok(!postStream.get('firstPostPresent'), "the first post is still not loaded");
|
||||
equal(postStream.get('posts.length'), 1, "it has one post in the stream");
|
||||
assert.ok(!postStream.get('firstPostPresent'), "the first post is still not loaded");
|
||||
assert.equal(postStream.get('posts.length'), 1, "it has one post in the stream");
|
||||
|
||||
postStream.appendPost(store.createRecord('post', {id: 4, post_number: 4}));
|
||||
ok(!postStream.get('firstPostPresent'), "the first post is still loaded");
|
||||
ok(postStream.get('loadedAllPosts'), "the last post is now loaded");
|
||||
equal(postStream.get('posts.length'), 2, "it has two posts in the stream");
|
||||
assert.ok(!postStream.get('firstPostPresent'), "the first post is still loaded");
|
||||
assert.ok(postStream.get('loadedAllPosts'), "the last post is now loaded");
|
||||
assert.equal(postStream.get('posts.length'), 2, "it has two posts in the stream");
|
||||
|
||||
postStream.appendPost(store.createRecord('post', {id: 4, post_number: 4}));
|
||||
equal(postStream.get('posts.length'), 2, "it will not add the same post with id twice");
|
||||
assert.equal(postStream.get('posts.length'), 2, "it will not add the same post with id twice");
|
||||
|
||||
const stagedPost = store.createRecord('post', {raw: 'incomplete post'});
|
||||
postStream.appendPost(stagedPost);
|
||||
equal(postStream.get('posts.length'), 3, "it can handle posts without ids");
|
||||
assert.equal(postStream.get('posts.length'), 3, "it can handle posts without ids");
|
||||
postStream.appendPost(stagedPost);
|
||||
equal(postStream.get('posts.length'), 3, "it won't add the same post without an id twice");
|
||||
assert.equal(postStream.get('posts.length'), 3, "it won't add the same post without an id twice");
|
||||
|
||||
// change the stream
|
||||
postStream.set('stream', [1, 2, 4]);
|
||||
ok(!postStream.get('firstPostPresent'), "the first post no longer loaded since the stream changed.");
|
||||
ok(postStream.get('loadedAllPosts'), "the last post is still the last post in the new stream");
|
||||
assert.ok(!postStream.get('firstPostPresent'), "the first post no longer loaded since the stream changed.");
|
||||
assert.ok(postStream.get('loadedAllPosts'), "the last post is still the last post in the new stream");
|
||||
});
|
||||
|
||||
test('closestPostNumberFor', function() {
|
||||
QUnit.test('closestPostNumberFor', assert => {
|
||||
const postStream = buildStream(1231);
|
||||
const store = postStream.store;
|
||||
|
||||
blank(postStream.closestPostNumberFor(1), "there is no closest post when nothing is loaded");
|
||||
assert.blank(postStream.closestPostNumberFor(1), "there is no closest post when nothing is loaded");
|
||||
|
||||
postStream.appendPost(store.createRecord('post', {id: 1, post_number: 2}));
|
||||
postStream.appendPost(store.createRecord('post', {id: 2, post_number: 3}));
|
||||
|
||||
equal(postStream.closestPostNumberFor(2), 2, "If a post is in the stream it returns its post number");
|
||||
equal(postStream.closestPostNumberFor(3), 3, "If a post is in the stream it returns its post number");
|
||||
equal(postStream.closestPostNumberFor(10), 3, "it clips to the upper bound of the stream");
|
||||
equal(postStream.closestPostNumberFor(0), 2, "it clips to the lower bound of the stream");
|
||||
assert.equal(postStream.closestPostNumberFor(2), 2, "If a post is in the stream it returns its post number");
|
||||
assert.equal(postStream.closestPostNumberFor(3), 3, "If a post is in the stream it returns its post number");
|
||||
assert.equal(postStream.closestPostNumberFor(10), 3, "it clips to the upper bound of the stream");
|
||||
assert.equal(postStream.closestPostNumberFor(0), 2, "it clips to the lower bound of the stream");
|
||||
});
|
||||
|
||||
test('closestDaysAgoFor', function() {
|
||||
QUnit.test('closestDaysAgoFor', assert => {
|
||||
const postStream = buildStream(1231);
|
||||
postStream.set('timelineLookup', [[1, 10], [3, 8], [5, 1]]);
|
||||
|
||||
equal(postStream.closestDaysAgoFor(1), 10);
|
||||
equal(postStream.closestDaysAgoFor(2), 10);
|
||||
equal(postStream.closestDaysAgoFor(3), 8);
|
||||
equal(postStream.closestDaysAgoFor(4), 8);
|
||||
equal(postStream.closestDaysAgoFor(5), 1);
|
||||
assert.equal(postStream.closestDaysAgoFor(1), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(2), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(3), 8);
|
||||
assert.equal(postStream.closestDaysAgoFor(4), 8);
|
||||
assert.equal(postStream.closestDaysAgoFor(5), 1);
|
||||
|
||||
// Out of bounds
|
||||
equal(postStream.closestDaysAgoFor(-1), 10);
|
||||
equal(postStream.closestDaysAgoFor(0), 10);
|
||||
equal(postStream.closestDaysAgoFor(10), 1);
|
||||
assert.equal(postStream.closestDaysAgoFor(-1), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(0), 10);
|
||||
assert.equal(postStream.closestDaysAgoFor(10), 1);
|
||||
});
|
||||
|
||||
test('closestDaysAgoFor - empty', function() {
|
||||
QUnit.test('closestDaysAgoFor - empty', assert => {
|
||||
const postStream = buildStream(1231);
|
||||
postStream.set('timelineLookup', []);
|
||||
|
||||
equal(postStream.closestDaysAgoFor(1), null);
|
||||
assert.equal(postStream.closestDaysAgoFor(1), null);
|
||||
});
|
||||
|
||||
test('updateFromJson', function() {
|
||||
QUnit.test('updateFromJson', assert => {
|
||||
const postStream = buildStream(1231);
|
||||
|
||||
postStream.updateFromJson({
|
||||
@@ -110,13 +109,13 @@ test('updateFromJson', function() {
|
||||
extra_property: 12
|
||||
});
|
||||
|
||||
equal(postStream.get('posts.length'), 1, 'it loaded the posts');
|
||||
containsInstance(postStream.get('posts'), Discourse.Post);
|
||||
assert.equal(postStream.get('posts.length'), 1, 'it loaded the posts');
|
||||
assert.containsInstance(postStream.get('posts'), Discourse.Post);
|
||||
|
||||
equal(postStream.get('extra_property'), 12);
|
||||
assert.equal(postStream.get('extra_property'), 12);
|
||||
});
|
||||
|
||||
test("removePosts", function() {
|
||||
QUnit.test("removePosts", assert => {
|
||||
const postStream = buildStream(10000001, [1,2,3]);
|
||||
const store = postStream.store;
|
||||
|
||||
@@ -130,179 +129,179 @@ test("removePosts", function() {
|
||||
|
||||
// Removing nothing does nothing
|
||||
postStream.removePosts();
|
||||
equal(postStream.get('posts.length'), 3);
|
||||
assert.equal(postStream.get('posts.length'), 3);
|
||||
|
||||
postStream.removePosts([p1, p3]);
|
||||
equal(postStream.get('posts.length'), 1);
|
||||
deepEqual(postStream.get('stream'), [2]);
|
||||
assert.equal(postStream.get('posts.length'), 1);
|
||||
assert.deepEqual(postStream.get('stream'), [2]);
|
||||
|
||||
});
|
||||
|
||||
test("cancelFilter", function() {
|
||||
QUnit.test("cancelFilter", assert => {
|
||||
const postStream = buildStream(1235);
|
||||
|
||||
sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve());
|
||||
|
||||
postStream.set('summary', true);
|
||||
postStream.cancelFilter();
|
||||
ok(!postStream.get('summary'), "summary is cancelled");
|
||||
assert.ok(!postStream.get('summary'), "summary is cancelled");
|
||||
|
||||
postStream.toggleParticipant(participant);
|
||||
postStream.cancelFilter();
|
||||
blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters");
|
||||
assert.blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters");
|
||||
});
|
||||
|
||||
test("findPostIdForPostNumber", function() {
|
||||
QUnit.test("findPostIdForPostNumber", assert => {
|
||||
const postStream = buildStream(1234, [10, 20, 30, 40, 50, 60, 70]);
|
||||
postStream.set('gaps', { before: { 60: [55, 58] } });
|
||||
|
||||
equal(postStream.findPostIdForPostNumber(500), null, 'it returns null when the post cannot be found');
|
||||
equal(postStream.findPostIdForPostNumber(1), 10, 'it finds the postId at the beginning');
|
||||
equal(postStream.findPostIdForPostNumber(5), 50, 'it finds the postId in the middle');
|
||||
equal(postStream.findPostIdForPostNumber(8), 60, 'it respects gaps');
|
||||
assert.equal(postStream.findPostIdForPostNumber(500), null, 'it returns null when the post cannot be found');
|
||||
assert.equal(postStream.findPostIdForPostNumber(1), 10, 'it finds the postId at the beginning');
|
||||
assert.equal(postStream.findPostIdForPostNumber(5), 50, 'it finds the postId in the middle');
|
||||
assert.equal(postStream.findPostIdForPostNumber(8), 60, 'it respects gaps');
|
||||
|
||||
});
|
||||
|
||||
test("toggleParticipant", function() {
|
||||
QUnit.test("toggleParticipant", assert => {
|
||||
const postStream = buildStream(1236);
|
||||
sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve());
|
||||
|
||||
equal(postStream.get('userFilters.length'), 0, "by default no participants are toggled");
|
||||
assert.equal(postStream.get('userFilters.length'), 0, "by default no participants are toggled");
|
||||
|
||||
postStream.toggleParticipant(participant.username);
|
||||
ok(postStream.get('userFilters').includes('eviltrout'), 'eviltrout is in the filters');
|
||||
assert.ok(postStream.get('userFilters').includes('eviltrout'), 'eviltrout is in the filters');
|
||||
|
||||
postStream.toggleParticipant(participant.username);
|
||||
blank(postStream.get('userFilters'), "toggling the participant again removes them");
|
||||
assert.blank(postStream.get('userFilters'), "toggling the participant again removes them");
|
||||
});
|
||||
|
||||
test("streamFilters", function() {
|
||||
QUnit.test("streamFilters", assert => {
|
||||
const postStream = buildStream(1237);
|
||||
sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve());
|
||||
|
||||
deepEqual(postStream.get('streamFilters'), {}, "there are no postFilters by default");
|
||||
ok(postStream.get('hasNoFilters'), "there are no filters by default");
|
||||
assert.deepEqual(postStream.get('streamFilters'), {}, "there are no postFilters by default");
|
||||
assert.ok(postStream.get('hasNoFilters'), "there are no filters by default");
|
||||
|
||||
postStream.set('summary', true);
|
||||
deepEqual(postStream.get('streamFilters'), {filter: "summary"}, "postFilters contains the summary flag");
|
||||
ok(!postStream.get('hasNoFilters'), "now there are filters present");
|
||||
assert.deepEqual(postStream.get('streamFilters'), {filter: "summary"}, "postFilters contains the summary flag");
|
||||
assert.ok(!postStream.get('hasNoFilters'), "now there are filters present");
|
||||
|
||||
postStream.toggleParticipant(participant.username);
|
||||
deepEqual(postStream.get('streamFilters'), {
|
||||
assert.deepEqual(postStream.get('streamFilters'), {
|
||||
username_filters: 'eviltrout',
|
||||
}, "streamFilters contains the username we filtered");
|
||||
});
|
||||
|
||||
test("loading", function() {
|
||||
QUnit.test("loading", assert => {
|
||||
let postStream = buildStream(1234);
|
||||
ok(!postStream.get('loading'), "we're not loading by default");
|
||||
assert.ok(!postStream.get('loading'), "we're not loading by default");
|
||||
|
||||
postStream.set('loadingAbove', true);
|
||||
ok(postStream.get('loading'), "we're loading if loading above");
|
||||
assert.ok(postStream.get('loading'), "we're loading if loading above");
|
||||
|
||||
postStream = buildStream(1234);
|
||||
postStream.set('loadingBelow', true);
|
||||
ok(postStream.get('loading'), "we're loading if loading below");
|
||||
assert.ok(postStream.get('loading'), "we're loading if loading below");
|
||||
|
||||
postStream = buildStream(1234);
|
||||
postStream.set('loadingFilter', true);
|
||||
ok(postStream.get('loading'), "we're loading if loading a filter");
|
||||
assert.ok(postStream.get('loading'), "we're loading if loading a filter");
|
||||
});
|
||||
|
||||
test("nextWindow", function() {
|
||||
QUnit.test("nextWindow", assert => {
|
||||
const postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]);
|
||||
|
||||
blank(postStream.get('nextWindow'), 'With no posts loaded, the window is blank');
|
||||
assert.blank(postStream.get('nextWindow'), 'With no posts loaded, the window is blank');
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 1}, {id: 2}] });
|
||||
deepEqual(postStream.get('nextWindow'), [3,5,8,9,10],
|
||||
assert.deepEqual(postStream.get('nextWindow'), [3,5,8,9,10],
|
||||
"If we've loaded the first 2 posts, the window should be the 5 after that");
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 13}] });
|
||||
deepEqual(postStream.get('nextWindow'), [14, 15, 16], "Boundary check: stop at the end.");
|
||||
assert.deepEqual(postStream.get('nextWindow'), [14, 15, 16], "Boundary check: stop at the end.");
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 16}] });
|
||||
blank(postStream.get('nextWindow'), "Once we've seen everything there's nothing to load.");
|
||||
assert.blank(postStream.get('nextWindow'), "Once we've seen everything there's nothing to load.");
|
||||
});
|
||||
|
||||
test("previousWindow", function() {
|
||||
QUnit.test("previousWindow", assert => {
|
||||
const postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]);
|
||||
|
||||
blank(postStream.get('previousWindow'), 'With no posts loaded, the window is blank');
|
||||
assert.blank(postStream.get('previousWindow'), 'With no posts loaded, the window is blank');
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 11}, {id: 13}] });
|
||||
deepEqual(postStream.get('previousWindow'), [3, 5, 8, 9, 10],
|
||||
assert.deepEqual(postStream.get('previousWindow'), [3, 5, 8, 9, 10],
|
||||
"If we've loaded in the middle, it's the previous 5 posts");
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 3}] });
|
||||
deepEqual(postStream.get('previousWindow'), [1, 2], "Boundary check: stop at the beginning.");
|
||||
assert.deepEqual(postStream.get('previousWindow'), [1, 2], "Boundary check: stop at the beginning.");
|
||||
|
||||
postStream.updateFromJson({ posts: [{id: 1}] });
|
||||
blank(postStream.get('previousWindow'), "Once we've seen everything there's nothing to load.");
|
||||
assert.blank(postStream.get('previousWindow'), "Once we've seen everything there's nothing to load.");
|
||||
});
|
||||
|
||||
test("storePost", function() {
|
||||
QUnit.test("storePost", assert => {
|
||||
const postStream = buildStream(1234),
|
||||
store = postStream.store,
|
||||
post = store.createRecord('post', {id: 1, post_number: 100, raw: 'initial value'});
|
||||
|
||||
blank(postStream.get('topic.highest_post_number'), "it has no highest post number yet");
|
||||
assert.blank(postStream.get('topic.highest_post_number'), "it has no highest post number yet");
|
||||
let stored = postStream.storePost(post);
|
||||
equal(post, stored, "it returns the post it stored");
|
||||
equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly");
|
||||
equal(postStream.get('topic.highest_post_number'), 100, "it set the highest post number");
|
||||
assert.equal(post, stored, "it returns the post it stored");
|
||||
assert.equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly");
|
||||
assert.equal(postStream.get('topic.highest_post_number'), 100, "it set the highest post number");
|
||||
|
||||
const dupePost = store.createRecord('post', {id: 1, post_number: 100, raw: 'updated value'});
|
||||
const storedDupe = postStream.storePost(dupePost);
|
||||
equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes");
|
||||
equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post');
|
||||
assert.equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes");
|
||||
assert.equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post');
|
||||
|
||||
const postWithoutId = store.createRecord('post', {raw: 'hello world'});
|
||||
stored = postStream.storePost(postWithoutId);
|
||||
equal(stored, postWithoutId, "it returns the same post back");
|
||||
assert.equal(stored, postWithoutId, "it returns the same post back");
|
||||
|
||||
});
|
||||
|
||||
test("identity map", function() {
|
||||
QUnit.test("identity map", assert => {
|
||||
const postStream = buildStream(1234);
|
||||
const store = postStream.store;
|
||||
|
||||
const p1 = postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1}));
|
||||
const p3 = postStream.appendPost(store.createRecord('post', {id: 3, post_number: 4}));
|
||||
|
||||
equal(postStream.findLoadedPost(1), p1, "it can return cached posts by id");
|
||||
blank(postStream.findLoadedPost(4), "it can't find uncached posts");
|
||||
assert.equal(postStream.findLoadedPost(1), p1, "it can return cached posts by id");
|
||||
assert.blank(postStream.findLoadedPost(4), "it can't find uncached posts");
|
||||
|
||||
// Find posts by ids uses the identity map
|
||||
postStream.findPostsByIds([1, 2, 3]).then(result => {
|
||||
equal(result.length, 3);
|
||||
equal(result.objectAt(0), p1);
|
||||
equal(result.objectAt(1).get('post_number'), 2);
|
||||
equal(result.objectAt(2), p3);
|
||||
return postStream.findPostsByIds([1, 2, 3]).then(result => {
|
||||
assert.equal(result.length, 3);
|
||||
assert.equal(result.objectAt(0), p1);
|
||||
assert.equal(result.objectAt(1).get('post_number'), 2);
|
||||
assert.equal(result.objectAt(2), p3);
|
||||
});
|
||||
});
|
||||
|
||||
test("loadIntoIdentityMap with no data", () => {
|
||||
QUnit.test("loadIntoIdentityMap with no data", assert => {
|
||||
return buildStream(1234).loadIntoIdentityMap([]).then(result => {
|
||||
equal(result.length, 0, 'requesting no posts produces no posts');
|
||||
assert.equal(result.length, 0, 'requesting no posts produces no posts');
|
||||
});
|
||||
});
|
||||
|
||||
test("loadIntoIdentityMap with post ids", function() {
|
||||
QUnit.test("loadIntoIdentityMap with post ids", assert => {
|
||||
const postStream = buildStream(1234);
|
||||
|
||||
return postStream.loadIntoIdentityMap([10]).then(function() {
|
||||
present(postStream.findLoadedPost(10), "it adds the returned post to the store");
|
||||
assert.present(postStream.findLoadedPost(10), "it adds the returned post to the store");
|
||||
});
|
||||
});
|
||||
|
||||
test("staging and undoing a new post", function() {
|
||||
QUnit.test("staging and undoing a new post", assert => {
|
||||
const postStream = buildStream(10101, [1]);
|
||||
const store = postStream.store;
|
||||
|
||||
const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101});
|
||||
postStream.appendPost(original);
|
||||
ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||
assert.ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||
|
||||
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
||||
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
||||
@@ -315,39 +314,39 @@ test("staging and undoing a new post", function() {
|
||||
|
||||
// Stage the new post in the stream
|
||||
const result = postStream.stagePost(stagedPost, user);
|
||||
equal(result, "staged", "it returns staged");
|
||||
equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
||||
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||
ok(postStream.get('lastAppended'), original, "it doesn't consider staged posts as the lastAppended");
|
||||
assert.equal(result, "staged", "it returns staged");
|
||||
assert.equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
||||
assert.ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||
assert.ok(postStream.get('lastAppended'), original, "it doesn't consider staged posts as the lastAppended");
|
||||
|
||||
equal(topic.get('posts_count'), 2, "it increases the post count");
|
||||
present(topic.get('last_posted_at'), "it updates last_posted_at");
|
||||
equal(topic.get('details.last_poster'), user, "it changes the last poster");
|
||||
assert.equal(topic.get('posts_count'), 2, "it increases the post count");
|
||||
assert.present(topic.get('last_posted_at'), "it updates last_posted_at");
|
||||
assert.equal(topic.get('details.last_poster'), user, "it changes the last poster");
|
||||
|
||||
equal(stagedPost.get('topic'), topic, "it assigns the topic reference");
|
||||
equal(stagedPost.get('post_number'), 2, "it is assigned the probable post_number");
|
||||
present(stagedPost.get('created_at'), "it is assigned a created date");
|
||||
ok(postStream.get('posts').includes(stagedPost), "the post is added to the stream");
|
||||
equal(stagedPost.get('id'), -1, "the post has a magical -1 id");
|
||||
assert.equal(stagedPost.get('topic'), topic, "it assigns the topic reference");
|
||||
assert.equal(stagedPost.get('post_number'), 2, "it is assigned the probable post_number");
|
||||
assert.present(stagedPost.get('created_at'), "it is assigned a created date");
|
||||
assert.ok(postStream.get('posts').includes(stagedPost), "the post is added to the stream");
|
||||
assert.equal(stagedPost.get('id'), -1, "the post has a magical -1 id");
|
||||
|
||||
// Undoing a created post (there was an error)
|
||||
postStream.undoPost(stagedPost);
|
||||
|
||||
ok(!postStream.get('loading'), "it is no longer loading");
|
||||
equal(topic.get('highest_post_number'), 1, "it reverts the highest_post_number");
|
||||
equal(topic.get('posts_count'), 1, "it reverts the post count");
|
||||
equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
||||
ok(!postStream.get('posts').includes(stagedPost), "the post is removed from the stream");
|
||||
ok(postStream.get('lastAppended'), original, "it doesn't consider undid post lastAppended");
|
||||
assert.ok(!postStream.get('loading'), "it is no longer loading");
|
||||
assert.equal(topic.get('highest_post_number'), 1, "it reverts the highest_post_number");
|
||||
assert.equal(topic.get('posts_count'), 1, "it reverts the post count");
|
||||
assert.equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
||||
assert.ok(!postStream.get('posts').includes(stagedPost), "the post is removed from the stream");
|
||||
assert.ok(postStream.get('lastAppended'), original, "it doesn't consider undid post lastAppended");
|
||||
});
|
||||
|
||||
test("staging and committing a post", function() {
|
||||
QUnit.test("staging and committing a post", assert => {
|
||||
const postStream = buildStream(10101, [1]);
|
||||
const store = postStream.store;
|
||||
|
||||
const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101});
|
||||
postStream.appendPost(original);
|
||||
ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||
assert.ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||
|
||||
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
||||
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
||||
@@ -357,29 +356,29 @@ test("staging and committing a post", function() {
|
||||
|
||||
// Stage the new post in the stream
|
||||
let result = postStream.stagePost(stagedPost, user);
|
||||
equal(result, "staged", "it returns staged");
|
||||
assert.equal(result, "staged", "it returns staged");
|
||||
|
||||
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||
assert.ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||
stagedPost.setProperties({ id: 1234, raw: "different raw value" });
|
||||
|
||||
result = postStream.stagePost(stagedPost, user);
|
||||
equal(result, "alreadyStaging", "you can't stage a post while it is currently staging");
|
||||
ok(postStream.get('lastAppended'), original, "staging a post doesn't change the lastAppended");
|
||||
assert.equal(result, "alreadyStaging", "you can't stage a post while it is currently staging");
|
||||
assert.ok(postStream.get('lastAppended'), original, "staging a post doesn't change the lastAppended");
|
||||
|
||||
postStream.commitPost(stagedPost);
|
||||
ok(postStream.get('posts').includes(stagedPost), "the post is still in the stream");
|
||||
ok(!postStream.get('loading'), "it is no longer loading");
|
||||
assert.ok(postStream.get('posts').includes(stagedPost), "the post is still in the stream");
|
||||
assert.ok(!postStream.get('loading'), "it is no longer loading");
|
||||
|
||||
equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount");
|
||||
assert.equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount");
|
||||
|
||||
const found = postStream.findLoadedPost(stagedPost.get('id'));
|
||||
present(found, "the post is in the identity map");
|
||||
ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream");
|
||||
equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream');
|
||||
ok(postStream.get('lastAppended'), found, "comitting a post changes lastAppended");
|
||||
assert.present(found, "the post is in the identity map");
|
||||
assert.ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream");
|
||||
assert.equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream');
|
||||
assert.ok(postStream.get('lastAppended'), found, "comitting a post changes lastAppended");
|
||||
});
|
||||
|
||||
test("loadedAllPosts when the id changes", function() {
|
||||
QUnit.test("loadedAllPosts when the id changes", assert => {
|
||||
// This can happen in a race condition between staging a post and it coming through on the
|
||||
// message bus. If the id of a post changes we should reconsider the loadedAllPosts property.
|
||||
const postStream = buildStream(10101, [1, 2]);
|
||||
@@ -388,13 +387,13 @@ test("loadedAllPosts when the id changes", function() {
|
||||
|
||||
postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1}));
|
||||
postStream.appendPost(postWithoutId);
|
||||
ok(!postStream.get('loadedAllPosts'), 'the last post is not loaded');
|
||||
assert.ok(!postStream.get('loadedAllPosts'), 'the last post is not loaded');
|
||||
|
||||
postWithoutId.set('id', 2);
|
||||
ok(postStream.get('loadedAllPosts'), 'the last post is loaded now that the post has an id');
|
||||
assert.ok(postStream.get('loadedAllPosts'), 'the last post is loaded now that the post has an id');
|
||||
});
|
||||
|
||||
test("comitting and triggerNewPostInStream race condition", function() {
|
||||
QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
||||
const postStream = buildStream(4964);
|
||||
const store = postStream.store;
|
||||
|
||||
@@ -403,18 +402,18 @@ test("comitting and triggerNewPostInStream race condition", function() {
|
||||
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post' });
|
||||
|
||||
postStream.stagePost(stagedPost, user);
|
||||
equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet");
|
||||
assert.equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet");
|
||||
stagedPost.set('id', 123);
|
||||
|
||||
sandbox.stub(postStream, 'appendMore');
|
||||
postStream.triggerNewPostInStream(123);
|
||||
equal(postStream.get('filteredPostsCount'), 1, "it added the post");
|
||||
assert.equal(postStream.get('filteredPostsCount'), 1, "it added the post");
|
||||
|
||||
postStream.commitPost(stagedPost);
|
||||
equal(postStream.get('filteredPostsCount'), 1, "it does not add the same post twice");
|
||||
assert.equal(postStream.get('filteredPostsCount'), 1, "it does not add the same post twice");
|
||||
});
|
||||
|
||||
test("postsWithPlaceholders", () => {
|
||||
QUnit.test("postsWithPlaceholders", assert => {
|
||||
const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
||||
const postsWithPlaceholders = postStream.get('postsWithPlaceholders');
|
||||
const store = postStream.store;
|
||||
@@ -431,28 +430,28 @@ test("postsWithPlaceholders", () => {
|
||||
postStream.appendPost(p3);
|
||||
|
||||
// Test enumerable and array access
|
||||
equal(postsWithPlaceholders.get('length'), 3);
|
||||
equal(testProxy.get('length'), 3);
|
||||
equal(postsWithPlaceholders.nextObject(0), p1);
|
||||
equal(postsWithPlaceholders.objectAt(0), p1);
|
||||
equal(postsWithPlaceholders.nextObject(1, p1), p2);
|
||||
equal(postsWithPlaceholders.objectAt(1), p2);
|
||||
equal(postsWithPlaceholders.nextObject(2, p2), p3);
|
||||
equal(postsWithPlaceholders.objectAt(2), p3);
|
||||
assert.equal(postsWithPlaceholders.get('length'), 3);
|
||||
assert.equal(testProxy.get('length'), 3);
|
||||
assert.equal(postsWithPlaceholders.nextObject(0), p1);
|
||||
assert.equal(postsWithPlaceholders.objectAt(0), p1);
|
||||
assert.equal(postsWithPlaceholders.nextObject(1, p1), p2);
|
||||
assert.equal(postsWithPlaceholders.objectAt(1), p2);
|
||||
assert.equal(postsWithPlaceholders.nextObject(2, p2), p3);
|
||||
assert.equal(postsWithPlaceholders.objectAt(2), p3);
|
||||
|
||||
const promise = postStream.appendMore();
|
||||
equal(postsWithPlaceholders.get('length'), 8, 'we immediately have a larger placeholder window');
|
||||
equal(testProxy.get('length'), 8);
|
||||
ok(!!postsWithPlaceholders.nextObject(3, p3));
|
||||
ok(!!postsWithPlaceholders.objectAt(4));
|
||||
ok(postsWithPlaceholders.objectAt(3) !== p4);
|
||||
ok(testProxy.objectAt(3) !== p4);
|
||||
assert.equal(postsWithPlaceholders.get('length'), 8, 'we immediately have a larger placeholder window');
|
||||
assert.equal(testProxy.get('length'), 8);
|
||||
assert.ok(!!postsWithPlaceholders.nextObject(3, p3));
|
||||
assert.ok(!!postsWithPlaceholders.objectAt(4));
|
||||
assert.ok(postsWithPlaceholders.objectAt(3) !== p4);
|
||||
assert.ok(testProxy.objectAt(3) !== p4);
|
||||
|
||||
return promise.then(() => {
|
||||
equal(postsWithPlaceholders.objectAt(3), p4);
|
||||
equal(postsWithPlaceholders.get('length'), 8, 'have a larger placeholder window when loaded');
|
||||
equal(testProxy.get('length'), 8);
|
||||
equal(testProxy.objectAt(3), p4);
|
||||
assert.equal(postsWithPlaceholders.objectAt(3), p4);
|
||||
assert.equal(postsWithPlaceholders.get('length'), 8, 'have a larger placeholder window when loaded');
|
||||
assert.equal(testProxy.get('length'), 8);
|
||||
assert.equal(testProxy.objectAt(3), p4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { present, blank } from 'helpers/qunit-helpers';
|
||||
|
||||
module("Discourse.Post");
|
||||
QUnit.module("Discourse.Post");
|
||||
|
||||
var buildPost = function(args) {
|
||||
return Discourse.Post.create(_.merge({
|
||||
@@ -10,29 +8,29 @@ var buildPost = function(args) {
|
||||
}, args || {}));
|
||||
};
|
||||
|
||||
test('defaults', function() {
|
||||
QUnit.test('defaults', assert => {
|
||||
var post = Discourse.Post.create({id: 1});
|
||||
blank(post.get('deleted_at'), "it has no deleted_at by default");
|
||||
blank(post.get('deleted_by'), "there is no deleted_by by default");
|
||||
assert.blank(post.get('deleted_at'), "it has no deleted_at by default");
|
||||
assert.blank(post.get('deleted_by'), "there is no deleted_by by default");
|
||||
});
|
||||
|
||||
test('new_user', function() {
|
||||
QUnit.test('new_user', assert => {
|
||||
var post = Discourse.Post.create({trust_level: 0});
|
||||
ok(post.get('new_user'), "post is from a new user");
|
||||
assert.ok(post.get('new_user'), "post is from a new user");
|
||||
|
||||
post.set('trust_level', 1);
|
||||
ok(!post.get('new_user'), "post is no longer from a new user");
|
||||
assert.ok(!post.get('new_user'), "post is no longer from a new user");
|
||||
});
|
||||
|
||||
test('firstPost', function() {
|
||||
QUnit.test('firstPost', assert => {
|
||||
var post = Discourse.Post.create({post_number: 1});
|
||||
ok(post.get('firstPost'), "it's the first post");
|
||||
assert.ok(post.get('firstPost'), "it's the first post");
|
||||
|
||||
post.set('post_number', 10);
|
||||
ok(!post.get('firstPost'), "post is no longer the first post");
|
||||
assert.ok(!post.get('firstPost'), "post is no longer the first post");
|
||||
});
|
||||
|
||||
test('updateFromPost', function() {
|
||||
QUnit.test('updateFromPost', assert => {
|
||||
var post = Discourse.Post.create({
|
||||
post_number: 1,
|
||||
raw: 'hello world'
|
||||
@@ -43,33 +41,32 @@ test('updateFromPost', function() {
|
||||
wat: function() { return 123; }
|
||||
}));
|
||||
|
||||
equal(post.get('raw'), "different raw", "raw field updated");
|
||||
assert.equal(post.get('raw'), "different raw", "raw field updated");
|
||||
});
|
||||
|
||||
test('destroy by staff', function() {
|
||||
QUnit.test('destroy by staff', assert => {
|
||||
var user = Discourse.User.create({username: 'staff', staff: true}),
|
||||
post = buildPost({user: user});
|
||||
|
||||
post.destroy(user);
|
||||
|
||||
present(post.get('deleted_at'), "it has a `deleted_at` field.");
|
||||
equal(post.get('deleted_by'), user, "it has the user in the `deleted_by` field");
|
||||
assert.present(post.get('deleted_at'), "it has a `deleted_at` field.");
|
||||
assert.equal(post.get('deleted_by'), user, "it has the user in the `deleted_by` field");
|
||||
|
||||
post.recover();
|
||||
blank(post.get('deleted_at'), "it clears `deleted_at` when recovering");
|
||||
blank(post.get('deleted_by'), "it clears `deleted_by` when recovering");
|
||||
assert.blank(post.get('deleted_at'), "it clears `deleted_at` when recovering");
|
||||
assert.blank(post.get('deleted_by'), "it clears `deleted_by` when recovering");
|
||||
|
||||
});
|
||||
|
||||
test('destroy by non-staff', function() {
|
||||
QUnit.test('destroy by non-staff', assert => {
|
||||
var originalCooked = "this is the original cooked value",
|
||||
user = Discourse.User.create({username: 'evil trout'}),
|
||||
post = buildPost({user: user, cooked: originalCooked});
|
||||
|
||||
post.destroy(user);
|
||||
|
||||
ok(!post.get('can_delete'), "the post can't be deleted again in this session");
|
||||
ok(post.get('cooked') !== originalCooked, "the cooked content changed");
|
||||
equal(post.get('version'), 2, "the version number increased");
|
||||
});
|
||||
|
||||
assert.ok(!post.get('can_delete'), "the post can't be deleted again in this session");
|
||||
assert.ok(post.get('cooked') !== originalCooked, "the cooked content changed");
|
||||
assert.equal(post.get('version'), 2, "the version number increased");
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
import { blank } from 'helpers/qunit-helpers';
|
||||
import Report from 'admin/models/report';
|
||||
|
||||
module("Report");
|
||||
QUnit.module("Report");
|
||||
|
||||
function reportWithData(data) {
|
||||
return Report.create({
|
||||
@@ -12,53 +11,53 @@ function reportWithData(data) {
|
||||
});
|
||||
}
|
||||
|
||||
test("counts", function() {
|
||||
QUnit.test("counts", assert => {
|
||||
var report = reportWithData([5, 4, 3, 2, 1, 100, 99, 98, 1000]);
|
||||
|
||||
equal(report.get('todayCount'), 5);
|
||||
equal(report.get('yesterdayCount'), 4);
|
||||
equal(report.valueFor(2, 4), 6, "adds the values for the given range of days, inclusive");
|
||||
equal(report.get('lastSevenDaysCount'), 307, "sums 7 days excluding today");
|
||||
assert.equal(report.get('todayCount'), 5);
|
||||
assert.equal(report.get('yesterdayCount'), 4);
|
||||
assert.equal(report.valueFor(2, 4), 6, "adds the values for the given range of days, inclusive");
|
||||
assert.equal(report.get('lastSevenDaysCount'), 307, "sums 7 days excluding today");
|
||||
|
||||
report.set("method", "average");
|
||||
equal(report.valueFor(2, 4), 2, "averages the values for the given range of days");
|
||||
assert.equal(report.valueFor(2, 4), 2, "averages the values for the given range of days");
|
||||
});
|
||||
|
||||
test("percentChangeString", function() {
|
||||
QUnit.test("percentChangeString", assert => {
|
||||
var report = reportWithData([]);
|
||||
|
||||
equal(report.percentChangeString(8, 5), "+60%", "value increased");
|
||||
equal(report.percentChangeString(2, 8), "-75%", "value decreased");
|
||||
equal(report.percentChangeString(8, 8), "0%", "value unchanged");
|
||||
blank(report.percentChangeString(8, 0), "returns blank when previous value was 0");
|
||||
equal(report.percentChangeString(0, 8), "-100%", "yesterday was 0");
|
||||
blank(report.percentChangeString(0, 0), "returns blank when both were 0");
|
||||
assert.equal(report.percentChangeString(8, 5), "+60%", "value increased");
|
||||
assert.equal(report.percentChangeString(2, 8), "-75%", "value decreased");
|
||||
assert.equal(report.percentChangeString(8, 8), "0%", "value unchanged");
|
||||
assert.blank(report.percentChangeString(8, 0), "returns blank when previous value was 0");
|
||||
assert.equal(report.percentChangeString(0, 8), "-100%", "yesterday was 0");
|
||||
assert.blank(report.percentChangeString(0, 0), "returns blank when both were 0");
|
||||
});
|
||||
|
||||
test("yesterdayCountTitle with valid values", function() {
|
||||
QUnit.test("yesterdayCountTitle with valid values", assert => {
|
||||
var title = reportWithData([6,8,5,2,1]).get('yesterdayCountTitle');
|
||||
ok(title.indexOf('+60%') !== -1);
|
||||
ok(title.match(/Was 5/));
|
||||
assert.ok(title.indexOf('+60%') !== -1);
|
||||
assert.ok(title.match(/Was 5/));
|
||||
});
|
||||
|
||||
test("yesterdayCountTitle when two days ago was 0", function() {
|
||||
QUnit.test("yesterdayCountTitle when two days ago was 0", assert => {
|
||||
var title = reportWithData([6,8,0,2,1]).get('yesterdayCountTitle');
|
||||
equal(title.indexOf('%'), -1);
|
||||
ok(title.match(/Was 0/));
|
||||
assert.equal(title.indexOf('%'), -1);
|
||||
assert.ok(title.match(/Was 0/));
|
||||
});
|
||||
|
||||
|
||||
test("sevenDayCountTitle", function() {
|
||||
QUnit.test("sevenDayCountTitle", assert => {
|
||||
var title = reportWithData([100,1,1,1,1,1,1,1,2,2,2,2,2,2,2,100,100]).get('sevenDayCountTitle');
|
||||
ok(title.match(/-50%/));
|
||||
ok(title.match(/Was 14/));
|
||||
assert.ok(title.match(/-50%/));
|
||||
assert.ok(title.match(/Was 14/));
|
||||
});
|
||||
|
||||
test("thirtyDayCountTitle", function() {
|
||||
QUnit.test("thirtyDayCountTitle", assert => {
|
||||
var report = reportWithData([5,5,5,5]);
|
||||
report.set('prev30Days', 10);
|
||||
var title = report.get('thirtyDayCountTitle');
|
||||
|
||||
ok(title.indexOf('+50%') !== -1);
|
||||
ok(title.match(/Was 10/));
|
||||
});
|
||||
assert.ok(title.indexOf('+50%') !== -1);
|
||||
assert.ok(title.match(/Was 10/));
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
module('rest-model');
|
||||
QUnit.module('rest-model');
|
||||
|
||||
import createStore from 'helpers/create-store';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
test('munging', function() {
|
||||
QUnit.test('munging', assert => {
|
||||
const store = createStore();
|
||||
const Grape = RestModel.extend();
|
||||
Grape.reopenClass({
|
||||
@@ -14,26 +14,26 @@ test('munging', function() {
|
||||
});
|
||||
|
||||
var g = Grape.create({ store, percent: 0.4 });
|
||||
equal(g.get('inverse'), 0.6, 'it runs `munge` on `create`');
|
||||
assert.equal(g.get('inverse'), 0.6, 'it runs `munge` on `create`');
|
||||
});
|
||||
|
||||
test('update', function() {
|
||||
QUnit.test('update', assert => {
|
||||
const store = createStore();
|
||||
return store.find('widget', 123).then(function(widget) {
|
||||
equal(widget.get('name'), 'Trout Lure');
|
||||
assert.equal(widget.get('name'), 'Trout Lure');
|
||||
|
||||
ok(!widget.get('isSaving'));
|
||||
assert.ok(!widget.get('isSaving'));
|
||||
const promise = widget.update({ name: 'new name' });
|
||||
ok(widget.get('isSaving'));
|
||||
assert.ok(widget.get('isSaving'));
|
||||
promise.then(function() {
|
||||
ok(!widget.get('isSaving'));
|
||||
equal(widget.get('name'), 'new name');
|
||||
assert.ok(!widget.get('isSaving'));
|
||||
assert.equal(widget.get('name'), 'new name');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('updating simultaneously', function() {
|
||||
expect(2);
|
||||
QUnit.test('updating simultaneously', assert => {
|
||||
assert.expect(2);
|
||||
|
||||
const store = createStore();
|
||||
return store.find('widget', 123).then(function(widget) {
|
||||
@@ -41,37 +41,37 @@ test('updating simultaneously', function() {
|
||||
const firstPromise = widget.update({ name: 'new name' });
|
||||
const secondPromise = widget.update({ name: 'new name' });
|
||||
firstPromise.then(function() {
|
||||
ok(true, 'the first promise succeeeds');
|
||||
assert.ok(true, 'the first promise succeeeds');
|
||||
});
|
||||
|
||||
secondPromise.catch(function() {
|
||||
ok(true, 'the second promise fails');
|
||||
assert.ok(true, 'the second promise fails');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('save new', function() {
|
||||
QUnit.test('save new', assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget');
|
||||
|
||||
ok(widget.get('isNew'), 'it is a new record');
|
||||
ok(!widget.get('isCreated'), 'it is not created');
|
||||
ok(!widget.get('isSaving'));
|
||||
assert.ok(widget.get('isNew'), 'it is a new record');
|
||||
assert.ok(!widget.get('isCreated'), 'it is not created');
|
||||
assert.ok(!widget.get('isSaving'));
|
||||
|
||||
const promise = widget.save({ name: 'Evil Widget' });
|
||||
ok(widget.get('isSaving'));
|
||||
assert.ok(widget.get('isSaving'));
|
||||
|
||||
return promise.then(function() {
|
||||
ok(!widget.get('isSaving'));
|
||||
ok(widget.get('id'), 'it has an id');
|
||||
ok(widget.get('name'), 'Evil Widget');
|
||||
ok(widget.get('isCreated'), 'it is created');
|
||||
ok(!widget.get('isNew'), 'it is no longer new');
|
||||
assert.ok(!widget.get('isSaving'));
|
||||
assert.ok(widget.get('id'), 'it has an id');
|
||||
assert.ok(widget.get('name'), 'Evil Widget');
|
||||
assert.ok(widget.get('isCreated'), 'it is created');
|
||||
assert.ok(!widget.get('isNew'), 'it is no longer new');
|
||||
});
|
||||
});
|
||||
|
||||
test('creating simultaneously', function() {
|
||||
expect(2);
|
||||
QUnit.test('creating simultaneously', assert => {
|
||||
assert.expect(2);
|
||||
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget');
|
||||
@@ -79,20 +79,19 @@ test('creating simultaneously', function() {
|
||||
const firstPromise = widget.save({ name: 'Evil Widget' });
|
||||
const secondPromise = widget.save({ name: 'Evil Widget' });
|
||||
firstPromise.then(function() {
|
||||
ok(true, 'the first promise succeeeds');
|
||||
assert.ok(true, 'the first promise succeeeds');
|
||||
});
|
||||
|
||||
secondPromise.catch(function() {
|
||||
ok(true, 'the second promise fails');
|
||||
assert.ok(true, 'the second promise fails');
|
||||
});
|
||||
});
|
||||
|
||||
test('destroyRecord', function() {
|
||||
QUnit.test('destroyRecord', assert => {
|
||||
const store = createStore();
|
||||
return store.find('widget', 123).then(function(widget) {
|
||||
widget.destroyRecord().then(function(result) {
|
||||
ok(result);
|
||||
assert.ok(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
module('result-set');
|
||||
QUnit.module('result-set');
|
||||
|
||||
import ResultSet from 'discourse/models/result-set';
|
||||
import createStore from 'helpers/create-store';
|
||||
|
||||
test('defaults', function() {
|
||||
QUnit.test('defaults', assert => {
|
||||
const rs = ResultSet.create({ content: [] });
|
||||
equal(rs.get('length'), 0);
|
||||
equal(rs.get('totalRows'), 0);
|
||||
ok(!rs.get('loadMoreUrl'));
|
||||
ok(!rs.get('loading'));
|
||||
ok(!rs.get('loadingMore'));
|
||||
ok(!rs.get('refreshing'));
|
||||
assert.equal(rs.get('length'), 0);
|
||||
assert.equal(rs.get('totalRows'), 0);
|
||||
assert.ok(!rs.get('loadMoreUrl'));
|
||||
assert.ok(!rs.get('loading'));
|
||||
assert.ok(!rs.get('loadingMore'));
|
||||
assert.ok(!rs.get('refreshing'));
|
||||
});
|
||||
|
||||
test('pagination support', function() {
|
||||
QUnit.test('pagination support', assert => {
|
||||
const store = createStore();
|
||||
return store.findAll('widget').then(function(rs) {
|
||||
equal(rs.get('length'), 2);
|
||||
equal(rs.get('totalRows'), 4);
|
||||
ok(rs.get('loadMoreUrl'), 'has a url to load more');
|
||||
ok(!rs.get('loadingMore'), 'it is not loading more');
|
||||
ok(rs.get('canLoadMore'));
|
||||
assert.equal(rs.get('length'), 2);
|
||||
assert.equal(rs.get('totalRows'), 4);
|
||||
assert.ok(rs.get('loadMoreUrl'), 'has a url to load more');
|
||||
assert.ok(!rs.get('loadingMore'), 'it is not loading more');
|
||||
assert.ok(rs.get('canLoadMore'));
|
||||
|
||||
const promise = rs.loadMore();
|
||||
|
||||
ok(rs.get('loadingMore'), 'it is loading more');
|
||||
assert.ok(rs.get('loadingMore'), 'it is loading more');
|
||||
promise.then(function() {
|
||||
ok(!rs.get('loadingMore'), 'it finished loading more');
|
||||
equal(rs.get('length'), 4);
|
||||
ok(!rs.get('loadMoreUrl'));
|
||||
ok(!rs.get('canLoadMore'));
|
||||
assert.ok(!rs.get('loadingMore'), 'it finished loading more');
|
||||
assert.equal(rs.get('length'), 4);
|
||||
assert.ok(!rs.get('loadMoreUrl'));
|
||||
assert.ok(!rs.get('canLoadMore'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('refresh support', function() {
|
||||
QUnit.test('refresh support', assert => {
|
||||
const store = createStore();
|
||||
return store.findAll('widget').then(function(rs) {
|
||||
equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url');
|
||||
assert.equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url');
|
||||
|
||||
const promise = rs.refresh();
|
||||
|
||||
ok(rs.get('refreshing'), 'it is refreshing');
|
||||
assert.ok(rs.get('refreshing'), 'it is refreshing');
|
||||
promise.then(function() {
|
||||
ok(!rs.get('refreshing'), 'it is finished refreshing');
|
||||
assert.ok(!rs.get('refreshing'), 'it is finished refreshing');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import Session from "discourse/models/session";
|
||||
|
||||
module("model:session");
|
||||
QUnit.module("model:session");
|
||||
|
||||
test('highestSeenByTopic', function() {
|
||||
QUnit.test('highestSeenByTopic', assert => {
|
||||
const session = Session.current();
|
||||
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
||||
});
|
||||
assert.deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
||||
});
|
||||
@@ -1,23 +1,22 @@
|
||||
import createStore from 'helpers/create-store';
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
|
||||
module("model:site");
|
||||
QUnit.module("model:site");
|
||||
|
||||
test('create', function() {
|
||||
ok(Discourse.Site.create(), 'it can create with no parameters');
|
||||
QUnit.test('create', assert => {
|
||||
assert.ok(Discourse.Site.create(), 'it can create with no parameters');
|
||||
});
|
||||
|
||||
test('instance', function() {
|
||||
QUnit.test('instance', assert => {
|
||||
const site = Discourse.Site.current();
|
||||
|
||||
present(site, "We have a current site singleton");
|
||||
present(site.get('categories'), "The instance has a list of categories");
|
||||
present(site.get('flagTypes'), "The instance has a list of flag types");
|
||||
present(site.get('trustLevels'), "The instance has a list of trust levels");
|
||||
assert.present(site, "We have a current site singleton");
|
||||
assert.present(site.get('categories'), "The instance has a list of categories");
|
||||
assert.present(site.get('flagTypes'), "The instance has a list of flag types");
|
||||
assert.present(site.get('trustLevels'), "The instance has a list of trust levels");
|
||||
|
||||
});
|
||||
|
||||
test('create categories', function() {
|
||||
QUnit.test('create categories', assert => {
|
||||
const store = createStore();
|
||||
const site = store.createRecord('site', {
|
||||
categories: [{ id: 1234, name: 'Test'},
|
||||
@@ -28,22 +27,22 @@ test('create categories', function() {
|
||||
const categories = site.get('categories');
|
||||
site.get('sortedCategories');
|
||||
|
||||
present(categories, "The categories are present");
|
||||
equal(categories.length, 3, "it loaded all three categories");
|
||||
assert.present(categories, "The categories are present");
|
||||
assert.equal(categories.length, 3, "it loaded all three categories");
|
||||
|
||||
const parent = categories.findBy('id', 1234);
|
||||
present(parent, "it loaded the parent category");
|
||||
blank(parent.get('parentCategory'), 'it has no parent category');
|
||||
assert.present(parent, "it loaded the parent category");
|
||||
assert.blank(parent.get('parentCategory'), 'it has no parent category');
|
||||
|
||||
const subcategory = categories.findBy('id', 3456);
|
||||
present(subcategory, "it loaded the subcategory");
|
||||
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
||||
assert.present(subcategory, "it loaded the subcategory");
|
||||
assert.equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
||||
|
||||
// remove invalid category and child
|
||||
categories.removeObject(categories[2]);
|
||||
categories.removeObject(categories[1]);
|
||||
|
||||
equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal");
|
||||
equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal");
|
||||
assert.equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal");
|
||||
assert.equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal");
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import StaffActionLog from 'admin/models/staff-action-log';
|
||||
|
||||
module("StaffActionLog");
|
||||
QUnit.module("StaffActionLog");
|
||||
|
||||
test("create", function() {
|
||||
ok(StaffActionLog.create(), "it can be created without arguments");
|
||||
});
|
||||
QUnit.test("create", assert => {
|
||||
assert.ok(StaffActionLog.create(), "it can be created without arguments");
|
||||
});
|
||||
@@ -1,81 +1,81 @@
|
||||
module('store:main');
|
||||
QUnit.module('store:main');
|
||||
|
||||
import createStore from 'helpers/create-store';
|
||||
|
||||
test('createRecord', function() {
|
||||
QUnit.test('createRecord', assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget', {id: 111, name: 'hello'});
|
||||
|
||||
ok(!widget.get('isNew'), 'it is not a new record');
|
||||
equal(widget.get('name'), 'hello');
|
||||
equal(widget.get('id'), 111);
|
||||
assert.ok(!widget.get('isNew'), 'it is not a new record');
|
||||
assert.equal(widget.get('name'), 'hello');
|
||||
assert.equal(widget.get('id'), 111);
|
||||
});
|
||||
|
||||
test('createRecord without an `id`', function() {
|
||||
QUnit.test('createRecord without an `id`', assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget', {name: 'hello'});
|
||||
|
||||
ok(widget.get('isNew'), 'it is a new record');
|
||||
ok(!widget.get('id'), 'there is no id');
|
||||
assert.ok(widget.get('isNew'), 'it is a new record');
|
||||
assert.ok(!widget.get('id'), 'there is no id');
|
||||
});
|
||||
|
||||
test("createRecord doesn't modify the input `id` field", () => {
|
||||
QUnit.test("createRecord doesn't modify the input `id` field", assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget', {id: 1, name: 'hello'});
|
||||
|
||||
const obj = { id: 1, name: 'something' };
|
||||
|
||||
const other = store.createRecord('widget', obj);
|
||||
equal(widget, other, 'returns the same record');
|
||||
equal(widget.name, 'something', 'it updates the properties');
|
||||
equal(obj.id, 1, 'it does not remove the id from the input');
|
||||
assert.equal(widget, other, 'returns the same record');
|
||||
assert.equal(widget.name, 'something', 'it updates the properties');
|
||||
assert.equal(obj.id, 1, 'it does not remove the id from the input');
|
||||
});
|
||||
|
||||
test('createRecord without attributes', function() {
|
||||
QUnit.test('createRecord without attributes', assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget');
|
||||
|
||||
ok(!widget.get('id'), 'there is no id');
|
||||
ok(widget.get('isNew'), 'it is a new record');
|
||||
assert.ok(!widget.get('id'), 'there is no id');
|
||||
assert.ok(widget.get('isNew'), 'it is a new record');
|
||||
});
|
||||
|
||||
test('createRecord with a record as attributes returns that record from the map', function() {
|
||||
QUnit.test('createRecord with a record as attributes returns that record from the map', assert => {
|
||||
const store = createStore();
|
||||
const widget = store.createRecord('widget', {id: 33});
|
||||
const secondWidget = store.createRecord('widget', {id: 33});
|
||||
|
||||
equal(widget, secondWidget, 'they should be the same');
|
||||
assert.equal(widget, secondWidget, 'they should be the same');
|
||||
});
|
||||
|
||||
test('find', function() {
|
||||
QUnit.test('find', assert => {
|
||||
const store = createStore();
|
||||
return store.find('widget', 123).then(function(w) {
|
||||
equal(w.get('name'), 'Trout Lure');
|
||||
equal(w.get('id'), 123);
|
||||
ok(!w.get('isNew'), 'found records are not new');
|
||||
assert.equal(w.get('name'), 'Trout Lure');
|
||||
assert.equal(w.get('id'), 123);
|
||||
assert.ok(!w.get('isNew'), 'found records are not new');
|
||||
|
||||
// A second find by id returns the same object
|
||||
store.find('widget', 123).then(function(w2) {
|
||||
equal(w, w2);
|
||||
assert.equal(w, w2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('find with object id', function() {
|
||||
QUnit.test('find with object id', assert => {
|
||||
const store = createStore();
|
||||
return store.find('widget', {id: 123}).then(function(w) {
|
||||
equal(w.get('firstObject.name'), 'Trout Lure');
|
||||
assert.equal(w.get('firstObject.name'), 'Trout Lure');
|
||||
});
|
||||
});
|
||||
|
||||
test('find with query param', function() {
|
||||
QUnit.test('find with query param', assert => {
|
||||
const store = createStore();
|
||||
return store.find('widget', {name: 'Trout Lure'}).then(function(w) {
|
||||
equal(w.get('firstObject.id'), 123);
|
||||
assert.equal(w.get('firstObject.id'), 123);
|
||||
});
|
||||
});
|
||||
|
||||
test('findStale with no stale results', (assert) => {
|
||||
QUnit.test('findStale with no stale results', (assert) => {
|
||||
const store = createStore();
|
||||
const stale = store.findStale('widget', {name: 'Trout Lure'});
|
||||
|
||||
@@ -86,14 +86,14 @@ test('findStale with no stale results', (assert) => {
|
||||
});
|
||||
});
|
||||
|
||||
test('update', function() {
|
||||
QUnit.test('update', assert => {
|
||||
const store = createStore();
|
||||
return store.update('widget', 123, {name: 'hello'}).then(function(result) {
|
||||
ok(result);
|
||||
assert.ok(result);
|
||||
});
|
||||
});
|
||||
|
||||
test('update with a multi world name', function(assert) {
|
||||
QUnit.test('update with a multi world name', function(assert) {
|
||||
const store = createStore();
|
||||
return store.update('cool-thing', 123, {name: 'hello'}).then(function(result) {
|
||||
assert.ok(result);
|
||||
@@ -101,17 +101,17 @@ test('update with a multi world name', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('findAll', function() {
|
||||
QUnit.test('findAll', assert => {
|
||||
const store = createStore();
|
||||
return store.findAll('widget').then(function(result) {
|
||||
equal(result.get('length'), 2);
|
||||
assert.equal(result.get('length'), 2);
|
||||
const w = result.findBy('id', 124);
|
||||
ok(!w.get('isNew'), 'found records are not new');
|
||||
equal(w.get('name'), 'Evil Repellant');
|
||||
assert.ok(!w.get('isNew'), 'found records are not new');
|
||||
assert.equal(w.get('name'), 'Evil Repellant');
|
||||
});
|
||||
});
|
||||
|
||||
test('destroyRecord', function(assert) {
|
||||
QUnit.test('destroyRecord', function(assert) {
|
||||
const store = createStore();
|
||||
return store.find('widget', 123).then(function(w) {
|
||||
store.destroyRecord('widget', w).then(function(result) {
|
||||
@@ -120,7 +120,7 @@ test('destroyRecord', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('destroyRecord when new', function(assert) {
|
||||
QUnit.test('destroyRecord when new', function(assert) {
|
||||
const store = createStore();
|
||||
const w = store.createRecord('widget', {name: 'hello'});
|
||||
store.destroyRecord('widget', w).then(function(result) {
|
||||
@@ -128,7 +128,7 @@ test('destroyRecord when new', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('find embedded', function(assert) {
|
||||
QUnit.test('find embedded', function(assert) {
|
||||
const store = createStore();
|
||||
return store.find('fruit', 2).then(function(f) {
|
||||
assert.ok(f.get('farmer'), 'it has the embedded object');
|
||||
@@ -142,7 +142,7 @@ test('find embedded', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('findAll embedded', function(assert) {
|
||||
QUnit.test('findAll embedded', function(assert) {
|
||||
const store = createStore();
|
||||
return store.findAll('fruit').then(function(fruits) {
|
||||
assert.equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald');
|
||||
@@ -156,5 +156,4 @@ test('findAll embedded', function(assert) {
|
||||
|
||||
assert.equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import { present } from 'helpers/qunit-helpers';
|
||||
module("model:topic-details");
|
||||
QUnit.module("model:topic-details");
|
||||
|
||||
import Topic from 'discourse/models/topic';
|
||||
|
||||
@@ -8,13 +7,13 @@ var buildDetails = function(id) {
|
||||
return topic.get('details');
|
||||
};
|
||||
|
||||
test('defaults', function() {
|
||||
QUnit.test('defaults', assert => {
|
||||
var details = buildDetails(1234);
|
||||
present(details, "the details are present by default");
|
||||
ok(!details.get('loaded'), "details are not loaded by default");
|
||||
assert.present(details, "the details are present by default");
|
||||
assert.ok(!details.get('loaded'), "details are not loaded by default");
|
||||
});
|
||||
|
||||
test('updateFromJson', function() {
|
||||
QUnit.test('updateFromJson', assert => {
|
||||
var details = buildDetails(1234);
|
||||
|
||||
details.updateFromJson({
|
||||
@@ -22,10 +21,10 @@ test('updateFromJson', function() {
|
||||
allowed_users: [{username: 'eviltrout'}]
|
||||
});
|
||||
|
||||
equal(details.get('suggested_topics.length'), 2, 'it loaded the suggested_topics');
|
||||
containsInstance(details.get('suggested_topics'), Topic);
|
||||
assert.equal(details.get('suggested_topics.length'), 2, 'it loaded the suggested_topics');
|
||||
assert.containsInstance(details.get('suggested_topics'), Topic);
|
||||
|
||||
equal(details.get('allowed_users.length'), 1, 'it loaded the allowed users');
|
||||
containsInstance(details.get('allowed_users'), Discourse.User);
|
||||
assert.equal(details.get('allowed_users.length'), 1, 'it loaded the allowed users');
|
||||
assert.containsInstance(details.get('allowed_users'), Discourse.User);
|
||||
|
||||
});
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
import { IMAGE_VERSION as v} from 'pretty-text/emoji';
|
||||
|
||||
module("model:topic");
|
||||
QUnit.module("model:topic");
|
||||
|
||||
import Topic from 'discourse/models/topic';
|
||||
|
||||
test("defaults", function() {
|
||||
QUnit.test("defaults", assert => {
|
||||
var topic = Topic.create({id: 1234});
|
||||
blank(topic.get('deleted_at'), 'deleted_at defaults to blank');
|
||||
blank(topic.get('deleted_by'), 'deleted_by defaults to blank');
|
||||
assert.blank(topic.get('deleted_at'), 'deleted_at defaults to blank');
|
||||
assert.blank(topic.get('deleted_by'), 'deleted_by defaults to blank');
|
||||
});
|
||||
|
||||
test('has details', function() {
|
||||
QUnit.test('has details', assert => {
|
||||
var topic = Topic.create({id: 1234});
|
||||
var topicDetails = topic.get('details');
|
||||
present(topicDetails, "a topic has topicDetails after we create it");
|
||||
equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic");
|
||||
assert.present(topicDetails, "a topic has topicDetails after we create it");
|
||||
assert.equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic");
|
||||
});
|
||||
|
||||
test('has a postStream', function() {
|
||||
QUnit.test('has a postStream', assert => {
|
||||
var topic = Topic.create({id: 1234});
|
||||
var postStream = topic.get('postStream');
|
||||
present(postStream, "a topic has a postStream after we create it");
|
||||
equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic");
|
||||
assert.present(postStream, "a topic has a postStream after we create it");
|
||||
assert.equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic");
|
||||
});
|
||||
|
||||
|
||||
test('category relationship', function() {
|
||||
QUnit.test('category relationship', assert => {
|
||||
// It finds the category by id
|
||||
var category = Discourse.Category.list()[0],
|
||||
topic = Topic.create({id: 1111, category_id: category.get('id') });
|
||||
|
||||
equal(topic.get('category'), category);
|
||||
assert.equal(topic.get('category'), category);
|
||||
});
|
||||
|
||||
test("updateFromJson", function() {
|
||||
QUnit.test("updateFromJson", assert => {
|
||||
var topic = Topic.create({id: 1234}),
|
||||
category = Discourse.Category.list()[0];
|
||||
|
||||
@@ -45,34 +44,34 @@ test("updateFromJson", function() {
|
||||
category_id: category.get('id')
|
||||
});
|
||||
|
||||
blank(topic.get('post_stream'), "it does not update post_stream");
|
||||
equal(topic.get('details.hello'), 'world', 'it updates the details');
|
||||
equal(topic.get('cool'), "property", "it updates other properties");
|
||||
equal(topic.get('category'), category);
|
||||
assert.blank(topic.get('post_stream'), "it does not update post_stream");
|
||||
assert.equal(topic.get('details.hello'), 'world', 'it updates the details');
|
||||
assert.equal(topic.get('cool'), "property", "it updates other properties");
|
||||
assert.equal(topic.get('category'), category);
|
||||
});
|
||||
|
||||
test("destroy", function() {
|
||||
QUnit.test("destroy", assert => {
|
||||
var user = Discourse.User.create({username: 'eviltrout'});
|
||||
var topic = Topic.create({id: 1234});
|
||||
|
||||
topic.destroy(user);
|
||||
present(topic.get('deleted_at'), 'deleted at is set');
|
||||
equal(topic.get('deleted_by'), user, 'deleted by is set');
|
||||
assert.present(topic.get('deleted_at'), 'deleted at is set');
|
||||
assert.equal(topic.get('deleted_by'), user, 'deleted by is set');
|
||||
});
|
||||
|
||||
test("recover", function() {
|
||||
QUnit.test("recover", assert => {
|
||||
var user = Discourse.User.create({username: 'eviltrout'});
|
||||
var topic = Topic.create({id: 1234, deleted_at: new Date(), deleted_by: user});
|
||||
|
||||
topic.recover();
|
||||
blank(topic.get('deleted_at'), "it clears deleted_at");
|
||||
blank(topic.get('deleted_by'), "it clears deleted_by");
|
||||
assert.blank(topic.get('deleted_at'), "it clears deleted_at");
|
||||
assert.blank(topic.get('deleted_by'), "it clears deleted_by");
|
||||
});
|
||||
|
||||
test('fancyTitle', function() {
|
||||
QUnit.test('fancyTitle', assert => {
|
||||
var topic = Topic.create({ fancy_title: ":smile: with all :) the emojis :pear::peach:" });
|
||||
|
||||
equal(topic.get('fancyTitle'),
|
||||
assert.equal(topic.get('fancyTitle'),
|
||||
`<img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'> with all <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'> the emojis <img src='/images/emoji/emoji_one/pear.png?v=${v}' title='pear' alt='pear' class='emoji'><img src='/images/emoji/emoji_one/peach.png?v=${v}' title='peach' alt='peach' class='emoji'>`,
|
||||
"supports emojis");
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
import TopicTrackingState from 'discourse/models/topic-tracking-state';
|
||||
import createStore from 'helpers/create-store';
|
||||
|
||||
module("model:topic-tracking-state");
|
||||
QUnit.module("model:topic-tracking-state");
|
||||
|
||||
test("sync", function (assert) {
|
||||
QUnit.test("sync", function (assert) {
|
||||
const state = TopicTrackingState.create();
|
||||
state.states["t111"] = {last_read_post_number: null};
|
||||
|
||||
@@ -19,7 +19,7 @@ test("sync", function (assert) {
|
||||
assert.equal(list.topics.length, 0, "expect new topic to be removed as it was seen");
|
||||
});
|
||||
|
||||
test("subscribe to category", function(assert){
|
||||
QUnit.test("subscribe to category", function(assert){
|
||||
|
||||
const store = createStore();
|
||||
const darth = store.createRecord('category', {id: 1, slug: 'darth'}),
|
||||
@@ -47,4 +47,4 @@ test("subscribe to category", function(assert){
|
||||
state.notify({message_type: 'new_topic', topic_id: 3, payload: {category_id: 1, topic_id: 3}});
|
||||
|
||||
assert.equal(state.get("incomingCount"), 1, "expect to properly track incoming for subcategory");
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
module("Discourse.UserAction");
|
||||
QUnit.module("Discourse.UserAction");
|
||||
|
||||
test("collapsing likes", function () {
|
||||
QUnit.test("collapsing likes", assert => {
|
||||
var actions = Discourse.UserAction.collapseStream([
|
||||
Discourse.UserAction.create({
|
||||
action_type: Discourse.UserAction.TYPES.likes_given,
|
||||
@@ -20,8 +20,8 @@ test("collapsing likes", function () {
|
||||
})
|
||||
]);
|
||||
|
||||
equal(actions.length, 2);
|
||||
assert.equal(actions.length, 2);
|
||||
|
||||
equal(actions[0].get('children.length'), 1);
|
||||
equal(actions[0].get('children')[0].items.length, 2);
|
||||
});
|
||||
assert.equal(actions[0].get('children.length'), 1);
|
||||
assert.equal(actions[0].get('children')[0].items.length, 2);
|
||||
});
|
||||
@@ -1,42 +1,42 @@
|
||||
import UserBadge from 'discourse/models/user-badge';
|
||||
import badgeFixtures from 'fixtures/user-badges';
|
||||
|
||||
module("model:user-badge");
|
||||
QUnit.module("model:user-badge");
|
||||
|
||||
test('createFromJson single', function() {
|
||||
QUnit.test('createFromJson single', assert => {
|
||||
const userBadge = UserBadge.createFromJson(badgeFixtures['/user_badges']);
|
||||
ok(!Array.isArray(userBadge), "does not return an array");
|
||||
equal(userBadge.get('badge.name'), "Badge 2", "badge reference is set");
|
||||
equal(userBadge.get('badge.badge_type.name'), "Silver 2", "badge.badge_type reference is set");
|
||||
equal(userBadge.get('granted_by.username'), "anne3", "granted_by reference is set");
|
||||
assert.ok(!Array.isArray(userBadge), "does not return an array");
|
||||
assert.equal(userBadge.get('badge.name'), "Badge 2", "badge reference is set");
|
||||
assert.equal(userBadge.get('badge.badge_type.name'), "Silver 2", "badge.badge_type reference is set");
|
||||
assert.equal(userBadge.get('granted_by.username'), "anne3", "granted_by reference is set");
|
||||
});
|
||||
|
||||
test('createFromJson array', function() {
|
||||
QUnit.test('createFromJson array', assert => {
|
||||
const userBadges = UserBadge.createFromJson(badgeFixtures['/user-badges/:username']);
|
||||
ok(Array.isArray(userBadges), "returns an array");
|
||||
equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null");
|
||||
assert.ok(Array.isArray(userBadges), "returns an array");
|
||||
assert.equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null");
|
||||
});
|
||||
|
||||
test('findByUsername', function() {
|
||||
QUnit.test('findByUsername', assert => {
|
||||
return UserBadge.findByUsername("anne3").then(function(badges) {
|
||||
ok(Array.isArray(badges), "returns an array");
|
||||
assert.ok(Array.isArray(badges), "returns an array");
|
||||
});
|
||||
});
|
||||
|
||||
test('findByBadgeId', function() {
|
||||
QUnit.test('findByBadgeId', assert => {
|
||||
return UserBadge.findByBadgeId(880).then(function(badges) {
|
||||
ok(Array.isArray(badges), "returns an array");
|
||||
assert.ok(Array.isArray(badges), "returns an array");
|
||||
});
|
||||
});
|
||||
|
||||
test('grant', function() {
|
||||
QUnit.test('grant', assert => {
|
||||
return UserBadge.grant(1, "username").then(function(userBadge) {
|
||||
ok(!Array.isArray(userBadge), "does not return an array");
|
||||
assert.ok(!Array.isArray(userBadge), "does not return an array");
|
||||
});
|
||||
});
|
||||
|
||||
test('revoke', function() {
|
||||
expect(0);
|
||||
QUnit.test('revoke', assert => {
|
||||
assert.expect(0);
|
||||
const userBadge = UserBadge.create({id: 1});
|
||||
return userBadge.revoke();
|
||||
});
|
||||
});
|
||||
@@ -1,32 +1,30 @@
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
QUnit.module("Discourse.UserStream");
|
||||
|
||||
module("Discourse.UserStream");
|
||||
|
||||
test('basics', function(){
|
||||
QUnit.test('basics', assert =>{
|
||||
var user = Discourse.User.create({id: 1, username: 'eviltrout'});
|
||||
var stream = user.get('stream');
|
||||
present(stream, "a user has a stream by default");
|
||||
equal(stream.get('user'), user, "the stream points back to the user");
|
||||
assert.present(stream, "a user has a stream by default");
|
||||
assert.equal(stream.get('user'), user, "the stream points back to the user");
|
||||
|
||||
equal(stream.get('itemsLoaded'), 0, "no items are loaded by default");
|
||||
blank(stream.get('content'), "no content by default");
|
||||
blank(stream.get('filter'), "no filter by default");
|
||||
assert.equal(stream.get('itemsLoaded'), 0, "no items are loaded by default");
|
||||
assert.blank(stream.get('content'), "no content by default");
|
||||
assert.blank(stream.get('filter'), "no filter by default");
|
||||
|
||||
ok(!stream.get('loaded'), "the stream is not loaded by default");
|
||||
assert.ok(!stream.get('loaded'), "the stream is not loaded by default");
|
||||
});
|
||||
|
||||
|
||||
test('filterParam', function() {
|
||||
QUnit.test('filterParam', assert => {
|
||||
var user = Discourse.User.create({id: 1, username: 'eviltrout'});
|
||||
var stream = user.get('stream');
|
||||
|
||||
// defaults to posts/topics
|
||||
equal(stream.get('filterParam'), "4,5");
|
||||
assert.equal(stream.get('filterParam'), "4,5");
|
||||
|
||||
stream.set('filter', Discourse.UserAction.TYPES.likes_given);
|
||||
equal(stream.get('filterParam'), Discourse.UserAction.TYPES.likes_given);
|
||||
assert.equal(stream.get('filterParam'), Discourse.UserAction.TYPES.likes_given);
|
||||
|
||||
stream.set('filter', Discourse.UserAction.TYPES.replies);
|
||||
equal(stream.get('filterParam'), '6,9');
|
||||
assert.equal(stream.get('filterParam'), '6,9');
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,46 +1,46 @@
|
||||
import User from 'discourse/models/user';
|
||||
import Group from 'discourse/models/group';
|
||||
|
||||
module("model:user");
|
||||
QUnit.module("model:user");
|
||||
|
||||
test('staff', function(){
|
||||
QUnit.test('staff', assert =>{
|
||||
var user = User.create({id: 1, username: 'eviltrout'});
|
||||
|
||||
ok(!user.get('staff'), "user is not staff");
|
||||
assert.ok(!user.get('staff'), "user is not staff");
|
||||
|
||||
user.toggleProperty('moderator');
|
||||
ok(user.get('staff'), "moderators are staff");
|
||||
assert.ok(user.get('staff'), "moderators are staff");
|
||||
|
||||
user.setProperties({moderator: false, admin: true});
|
||||
ok(user.get('staff'), "admins are staff");
|
||||
assert.ok(user.get('staff'), "admins are staff");
|
||||
});
|
||||
|
||||
test('searchContext', function() {
|
||||
QUnit.test('searchContext', assert => {
|
||||
var user = User.create({id: 1, username: 'EvilTrout'});
|
||||
|
||||
deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context");
|
||||
assert.deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context");
|
||||
});
|
||||
|
||||
test("isAllowedToUploadAFile", function() {
|
||||
QUnit.test("isAllowedToUploadAFile", assert => {
|
||||
var user = User.create({ trust_level: 0, admin: true });
|
||||
ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file");
|
||||
assert.ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file");
|
||||
|
||||
user.setProperties({ admin: false, moderator: true });
|
||||
ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file");
|
||||
assert.ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file");
|
||||
});
|
||||
|
||||
test('canMangeGroup', function() {
|
||||
QUnit.test('canMangeGroup', assert => {
|
||||
let user = User.create({ admin: true });
|
||||
let group = Group.create({ automatic: true });
|
||||
|
||||
equal(user.canManageGroup(group), false, "automatic groups cannot be managed.");
|
||||
assert.equal(user.canManageGroup(group), false, "automatic groups cannot be managed.");
|
||||
|
||||
group.set("automatic", false);
|
||||
|
||||
equal(user.canManageGroup(group), true, "an admin should be able to manage the group");
|
||||
assert.equal(user.canManageGroup(group), true, "an admin should be able to manage the group");
|
||||
|
||||
user.set('admin', false);
|
||||
group.setProperties({ is_group_owner: true });
|
||||
|
||||
equal(user.canManageGroup(group), true, "a group owner should be able to manage the group");
|
||||
});
|
||||
assert.equal(user.canManageGroup(group), true, "a group owner should be able to manage the group");
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import VersionCheck from 'admin/models/version-check';
|
||||
|
||||
module("VersionCheck");
|
||||
QUnit.module("VersionCheck");
|
||||
|
||||
test('dataIsOld', function() {
|
||||
QUnit.test('dataIsOld', assert => {
|
||||
var dataIsOld = function(args, expected, message) {
|
||||
equal(VersionCheck.create(args).get('dataIsOld'), expected, message);
|
||||
assert.equal(VersionCheck.create(args).get('dataIsOld'), expected, message);
|
||||
};
|
||||
|
||||
dataIsOld({updated_at: moment().subtract(2, 'hours').toJSON()}, false, '2 hours ago');
|
||||
@@ -12,12 +12,12 @@ test('dataIsOld', function() {
|
||||
dataIsOld({updated_at: moment().subtract(2, 'hours').toJSON(), version_check_pending: true}, true, 'version check pending');
|
||||
});
|
||||
|
||||
test('staleData', function() {
|
||||
QUnit.test('staleData', assert => {
|
||||
var updatedAt = function(hoursAgo) {
|
||||
return moment().subtract(hoursAgo, 'hours').toJSON();
|
||||
};
|
||||
var staleData = function(args, expected, message) {
|
||||
equal(VersionCheck.create(args).get('staleData'), expected, message);
|
||||
assert.equal(VersionCheck.create(args).get('staleData'), expected, message);
|
||||
};
|
||||
|
||||
staleData({missing_versions_count: 0, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(2)}, false, 'up to date');
|
||||
@@ -25,4 +25,4 @@ test('staleData', function() {
|
||||
staleData({missing_versions_count: 1, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(2)}, true, 'installed and latest match, but missing_versions_count is not 0');
|
||||
staleData({missing_versions_count: 0, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(50)}, true, 'old version check data');
|
||||
staleData({version_check_pending: true, missing_versions_count: 0, installed_version: '0.9.4', latest_version: '0.9.3', updated_at: updatedAt(2)}, true, 'version was upgraded, but no version check has been done since the upgrade');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user