Upgrade QUnit to latest version
This commit is contained in:
parent
8ae445766f
commit
cc525b1a8d
10
.eslintrc
10
.eslintrc
|
@ -11,23 +11,19 @@
|
|||
{"Ember":true,
|
||||
"jQuery":true,
|
||||
"$":true,
|
||||
"QUnit":true,
|
||||
"RSVP":true,
|
||||
"Discourse":true,
|
||||
"Em":true,
|
||||
"Handlebars":true,
|
||||
"I18n":true,
|
||||
"bootbox":true,
|
||||
"module":true,
|
||||
"moduleFor":true,
|
||||
"moduleForComponent":true,
|
||||
"Pretender":true,
|
||||
"sandbox":true,
|
||||
"controllerFor":true,
|
||||
"test":true,
|
||||
"ok":true,
|
||||
"not":true,
|
||||
"expect":true,
|
||||
"equal":true,
|
||||
"visit":true,
|
||||
"andThen":true,
|
||||
"click":true,
|
||||
|
@ -48,12 +44,8 @@
|
|||
"find":true,
|
||||
"sinon":true,
|
||||
"moment":true,
|
||||
"start":true,
|
||||
"_":true,
|
||||
"alert":true,
|
||||
"containsInstance":true,
|
||||
"deepEqual":true,
|
||||
"notEqual":true,
|
||||
"define":true,
|
||||
"require":true,
|
||||
"requirejs":true,
|
||||
|
|
|
@ -8,6 +8,8 @@ export default Discourse.Route.extend({
|
|||
model(params) {
|
||||
if (PreloadStore.get("invite_info")) {
|
||||
return PreloadStore.getAndRemove("invite_info").then(json => _.merge(params, json));
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,12 +11,12 @@ export default createWidget('link', {
|
|||
const route = attrs.route;
|
||||
if (route) {
|
||||
const router = this.register.lookup('router:main');
|
||||
if (router && router.router) {
|
||||
if (router && router._routerMicrolib) {
|
||||
const params = [route];
|
||||
if (attrs.model) {
|
||||
params.push(attrs.model);
|
||||
}
|
||||
return Discourse.getURL(router.router.generate.apply(router.router, params));
|
||||
return Discourse.getURL(router._routerMicrolib.generate.apply(router._routerMicrolib, params));
|
||||
}
|
||||
} else {
|
||||
return Discourse.getURL(attrs.href);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import getUrl from 'discourse-common/lib/get-url';
|
||||
|
||||
const Router = Ember.Router.extend({
|
||||
rootURL: getUrl('/wizard'),
|
||||
rootURL: getUrl('/wizard/'),
|
||||
location: Ember.testing ? 'none': 'history'
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module("Acceptance: wizard", {
|
|||
wizard = startApp();
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
Ember.run(wizard, 'destroy');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ moduleForComponent('invite-list', { integration: true });
|
|||
componentTest('can add users', {
|
||||
template: `{{invite-list field=field}}`,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('field', {});
|
||||
},
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ export function componentTest(name, opts) {
|
|||
test(name, function(assert) {
|
||||
initializer.initialize(this.registry);
|
||||
|
||||
if (opts.setup) {
|
||||
opts.setup.call(this);
|
||||
if (opts.beforeEach) {
|
||||
opts.beforeEach.call(this);
|
||||
}
|
||||
|
||||
andThen(() => this.render(opts.template));
|
||||
|
|
|
@ -33,6 +33,7 @@ if (window.Logster) {
|
|||
} else {
|
||||
window.Logster = { enabled: false };
|
||||
}
|
||||
Ember.Test.adapter = window.QUnitAdapter.create();
|
||||
|
||||
var createPretendServer = require('wizard/test/wizard-pretender', null, null, false).default;
|
||||
|
||||
|
@ -45,6 +46,7 @@ QUnit.testDone(function() {
|
|||
server.shutdown();
|
||||
});
|
||||
|
||||
|
||||
var _testApp = require('wizard/test/helpers/start-app').default();
|
||||
var _buildResolver = require('discourse-common/resolver').buildResolver;
|
||||
window.setResolver(_buildResolver('wizard').create({ namespace: _testApp }));
|
||||
|
|
|
@ -6,7 +6,7 @@ function findTextarea() {
|
|||
return find(".d-editor-input")[0];
|
||||
}
|
||||
|
||||
test('details button', () => {
|
||||
test('details button', (assert) => {
|
||||
visit("/");
|
||||
|
||||
click('#create-topic');
|
||||
|
@ -14,7 +14,7 @@ test('details button', () => {
|
|||
click('.popup-menu .fa-caret-right');
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
`[details=${I18n.t("composer.details_title")}]${I18n.t("composer.details_text")}[/details]`,
|
||||
'it should contain the right output'
|
||||
|
@ -33,15 +33,15 @@ test('details button', () => {
|
|||
click('.popup-menu .fa-caret-right');
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
`[details=${I18n.t("composer.details_title")}]This is my title[/details]`,
|
||||
'it should contain the right selected output'
|
||||
);
|
||||
|
||||
const textarea = findTextarea();
|
||||
equal(textarea.selectionStart, 17, 'it should start highlighting at the right position');
|
||||
equal(textarea.selectionEnd, 33, 'it should end highlighting at the right position');
|
||||
assert.equal(textarea.selectionStart, 17, 'it should start highlighting at the right position');
|
||||
assert.equal(textarea.selectionEnd, 33, 'it should end highlighting at the right position');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', "Before some text in between After");
|
||||
|
@ -56,15 +56,15 @@ test('details button', () => {
|
|||
click('.popup-menu .fa-caret-right');
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
`Before [details=${I18n.t("composer.details_title")}]some text in between[/details] After`,
|
||||
'it should contain the right output'
|
||||
);
|
||||
|
||||
const textarea = findTextarea();
|
||||
equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
||||
equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
||||
assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
||||
assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', "Before\nsome text in between\nAfter");
|
||||
|
@ -79,14 +79,14 @@ test('details button', () => {
|
|||
click('.popup-menu .fa-caret-right');
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".d-editor-input").val(),
|
||||
`Before\n[details=${I18n.t("composer.details_title")}]some text in between[/details]\nAfter`,
|
||||
'it should contain the right output'
|
||||
);
|
||||
|
||||
const textarea = findTextarea();
|
||||
equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
||||
equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
||||
assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
||||
assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,11 +13,11 @@ const defaultOpts = buildOptions({
|
|||
getURL: url => url
|
||||
});
|
||||
|
||||
function cooked(input, expected, text) {
|
||||
equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
};
|
||||
|
||||
test("details", () => {
|
||||
test("details", assert => {
|
||||
const cooked = (input, expected, text) => {
|
||||
assert.equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
};
|
||||
cooked(`<details><summary>Info</summary>coucou</details>`,
|
||||
`<details><summary>Info</summary>\n\n<p>coucou</p>\n\n</details>`,
|
||||
"manual HTML for details");
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -10,7 +10,7 @@ moduleFor("controller:poll-ui-builder", "controller:poll-ui-builder", {
|
|||
needs: ['controller:modal']
|
||||
});
|
||||
|
||||
test("isMultiple", function() {
|
||||
test("isMultiple", function(assert) {
|
||||
const controller = this.subject();
|
||||
|
||||
controller.setProperties({
|
||||
|
@ -18,31 +18,31 @@ test("isMultiple", function() {
|
|||
pollOptionsCount: 1
|
||||
});
|
||||
|
||||
equal(controller.get("isMultiple"), true, "it should be true");
|
||||
assert.equal(controller.get("isMultiple"), true, "it should be true");
|
||||
|
||||
controller.set("pollOptionsCount", 0);
|
||||
|
||||
equal(controller.get("isMultiple"), false, "it should be false");
|
||||
assert.equal(controller.get("isMultiple"), false, "it should be false");
|
||||
|
||||
controller.setProperties({ pollType: "random", pollOptionsCount: 1 });
|
||||
|
||||
equal(controller.get("isMultiple"), false, "it should be false");
|
||||
assert.equal(controller.get("isMultiple"), false, "it should be false");
|
||||
});
|
||||
|
||||
test("isNumber", function() {
|
||||
test("isNumber", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
controller.set("pollType", "random");
|
||||
|
||||
equal(controller.get("isNumber"), false, "it should be false");
|
||||
assert.equal(controller.get("isNumber"), false, "it should be false");
|
||||
|
||||
controller.set("pollType", controller.get("numberPollType"));
|
||||
|
||||
equal(controller.get("isNumber"), true, "it should be true");
|
||||
assert.equal(controller.get("isNumber"), true, "it should be true");
|
||||
});
|
||||
|
||||
test("showMinMax", function() {
|
||||
test("showMinMax", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
|
@ -51,14 +51,14 @@ test("showMinMax", function() {
|
|||
isMultiple: false
|
||||
});
|
||||
|
||||
equal(controller.get("showMinMax"), true, "it should be true");
|
||||
assert.equal(controller.get("showMinMax"), true, "it should be true");
|
||||
|
||||
controller.setProperties({
|
||||
isNumber: false,
|
||||
isMultiple: true
|
||||
});
|
||||
|
||||
equal(controller.get("showMinMax"), true, "it should be true");
|
||||
assert.equal(controller.get("showMinMax"), true, "it should be true");
|
||||
|
||||
controller.setProperties({
|
||||
isNumber: false,
|
||||
|
@ -66,23 +66,23 @@ test("showMinMax", function() {
|
|||
isRegular: true
|
||||
});
|
||||
|
||||
equal(controller.get("showMinMax"), false, "it should be false");
|
||||
assert.equal(controller.get("showMinMax"), false, "it should be false");
|
||||
});
|
||||
|
||||
test("pollOptionsCount", function() {
|
||||
test("pollOptionsCount", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
controller.set("pollOptions", "1\n2\n");
|
||||
|
||||
equal(controller.get("pollOptionsCount"), 2, "it should equal 2");
|
||||
assert.equal(controller.get("pollOptionsCount"), 2, "it should equal 2");
|
||||
|
||||
controller.set("pollOptions", "");
|
||||
|
||||
equal(controller.get("pollOptionsCount"), 0, "it should equal 0");
|
||||
assert.equal(controller.get("pollOptionsCount"), 0, "it should equal 0");
|
||||
});
|
||||
|
||||
test("pollMinOptions", function() {
|
||||
test("pollMinOptions", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
|
@ -91,40 +91,40 @@ test("pollMinOptions", function() {
|
|||
pollOptionsCount: 1
|
||||
});
|
||||
|
||||
deepEqual(controller.get("pollMinOptions"), [{ name: 1, value: 1 }], "it should return the right options");
|
||||
assert.deepEqual(controller.get("pollMinOptions"), [{ name: 1, value: 1 }], "it should return the right options");
|
||||
|
||||
controller.set("pollOptionsCount", 2);
|
||||
|
||||
deepEqual(controller.get("pollMinOptions"), [
|
||||
assert.deepEqual(controller.get("pollMinOptions"), [
|
||||
{ name: 1, value: 1 }, { name: 2, value: 2 }
|
||||
], "it should return the right options");
|
||||
|
||||
controller.set("isNumber", true);
|
||||
controller.siteSettings.poll_maximum_options = 2;
|
||||
|
||||
deepEqual(controller.get("pollMinOptions"), [
|
||||
assert.deepEqual(controller.get("pollMinOptions"), [
|
||||
{ name: 1, value: 1 }, { name: 2, value: 2 }
|
||||
], "it should return the right options");
|
||||
});
|
||||
|
||||
test("pollMaxOptions", function() {
|
||||
test("pollMaxOptions", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
controller.setProperties({ isMultiple: true, pollOptionsCount: 1, pollMin: 1 });
|
||||
|
||||
deepEqual(controller.get("pollMaxOptions"), [], "it should return the right options");
|
||||
assert.deepEqual(controller.get("pollMaxOptions"), [], "it should return the right options");
|
||||
|
||||
controller.set("pollOptionsCount", 2);
|
||||
|
||||
deepEqual(controller.get("pollMaxOptions"), [
|
||||
assert.deepEqual(controller.get("pollMaxOptions"), [
|
||||
{ name: 2, value: 2 }
|
||||
], "it should return the right options");
|
||||
|
||||
controller.siteSettings.poll_maximum_options = 3;
|
||||
controller.setProperties({ isMultiple: false, isNumber: true, pollStep: 2, pollMin: 1 });
|
||||
|
||||
deepEqual(controller.get("pollMaxOptions"), [
|
||||
assert.deepEqual(controller.get("pollMaxOptions"), [
|
||||
{ name: 2, value: 2 },
|
||||
{ name: 3, value: 3 },
|
||||
{ name: 4, value: 4 },
|
||||
|
@ -133,50 +133,50 @@ test("pollMaxOptions", function() {
|
|||
], "it should return the right options");
|
||||
});
|
||||
|
||||
test("pollStepOptions", function() {
|
||||
test("pollStepOptions", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
controller.siteSettings.poll_maximum_options = 3;
|
||||
|
||||
controller.set("isNumber", false);
|
||||
|
||||
equal(controller.get("pollStepOptions"), null, "is should return null");
|
||||
assert.equal(controller.get("pollStepOptions"), null, "is should return null");
|
||||
|
||||
controller.setProperties({ isNumber: true });
|
||||
|
||||
deepEqual(controller.get("pollStepOptions"), [
|
||||
assert.deepEqual(controller.get("pollStepOptions"), [
|
||||
{ name: 1, value: 1 },
|
||||
{ name: 2, value: 2 },
|
||||
{ name: 3, value: 3 }
|
||||
], "it should return the right options");
|
||||
});
|
||||
|
||||
test("disableInsert", function() {
|
||||
test("disableInsert", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
|
||||
controller.setProperties({ isRegular: true });
|
||||
|
||||
equal(controller.get("disableInsert"), true, "it should be true");
|
||||
assert.equal(controller.get("disableInsert"), true, "it should be true");
|
||||
|
||||
controller.setProperties({ isRegular: true, pollOptionsCount: 2 });
|
||||
|
||||
equal(controller.get("disableInsert"), false, "it should be false");
|
||||
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
||||
|
||||
controller.setProperties({ isNumber: true });
|
||||
|
||||
equal(controller.get("disableInsert"), false, "it should be false");
|
||||
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
||||
|
||||
controller.setProperties({ isNumber: false, pollOptionsCount: 3 });
|
||||
|
||||
equal(controller.get("disableInsert"), false, "it should be false");
|
||||
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
||||
|
||||
controller.setProperties({ isNumber: false, pollOptionsCount: 1 });
|
||||
|
||||
equal(controller.get("disableInsert"), true, "it should be true");
|
||||
assert.equal(controller.get("disableInsert"), true, "it should be true");
|
||||
});
|
||||
|
||||
test("number pollOutput", function() {
|
||||
test("number pollOutput", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
controller.siteSettings.poll_maximum_options = 20;
|
||||
|
@ -187,18 +187,18 @@ test("number pollOutput", function() {
|
|||
pollMin: 1
|
||||
});
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1]\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1]\n[/poll]", "it should return the right output");
|
||||
|
||||
controller.set("pollStep", 2);
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2]\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2]\n[/poll]", "it should return the right output");
|
||||
|
||||
controller.set("publicPoll", true);
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output");
|
||||
});
|
||||
|
||||
test("regular pollOutput", function() {
|
||||
test("regular pollOutput", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
controller.siteSettings.poll_maximum_options = 20;
|
||||
|
@ -209,15 +209,15 @@ test("regular pollOutput", function() {
|
|||
pollType: controller.get("regularPollType")
|
||||
});
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=regular]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=regular]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
|
||||
controller.set("publicPoll", "true");
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=regular public=true]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=regular public=true]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
});
|
||||
|
||||
|
||||
test("multiple pollOutput", function() {
|
||||
test("multiple pollOutput", function(assert) {
|
||||
const controller = this.subject();
|
||||
controller.siteSettings = Discourse.SiteSettings;
|
||||
controller.siteSettings.poll_maximum_options = 20;
|
||||
|
@ -229,9 +229,9 @@ test("multiple pollOutput", function() {
|
|||
pollOptions: "\n\n1\n\n2"
|
||||
});
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
|
||||
controller.set("publicPoll", "true");
|
||||
|
||||
equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2 public=true]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2 public=true]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ const template = `{{mount-widget
|
|||
widgetTest('single, not selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('option', { id: 'opt-id' });
|
||||
this.set('vote', []);
|
||||
},
|
||||
|
@ -21,7 +21,7 @@ widgetTest('single, not selected', {
|
|||
widgetTest('single, selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('option', { id: 'opt-id' });
|
||||
this.set('vote', ['opt-id']);
|
||||
},
|
||||
|
@ -34,7 +34,7 @@ widgetTest('single, selected', {
|
|||
widgetTest('multi, not selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: 'opt-id' },
|
||||
isMultiple: true,
|
||||
|
@ -50,7 +50,7 @@ widgetTest('multi, not selected', {
|
|||
widgetTest('multi, selected', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.setProperties({
|
||||
option: { id: 'opt-id' },
|
||||
isMultiple: true,
|
||||
|
|
|
@ -8,7 +8,7 @@ const template = `{{mount-widget
|
|||
widgetTest('options in descending order', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('poll', Ember.Object.create({
|
||||
options: [{ votes: 5 }, { votes: 4 }],
|
||||
voters: 9
|
||||
|
@ -24,7 +24,7 @@ widgetTest('options in descending order', {
|
|||
widgetTest('options in ascending order', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('poll', Ember.Object.create({
|
||||
options: [{ votes: 4 }, { votes: 5 }],
|
||||
voters: 9
|
||||
|
@ -40,7 +40,7 @@ widgetTest('options in ascending order', {
|
|||
widgetTest('multiple options in descending order', {
|
||||
template,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('isMultiple', true);
|
||||
this.set('poll', Ember.Object.create({
|
||||
type: 'multiple',
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("About");
|
||||
|
||||
test("viewing", () => {
|
||||
QUnit.test("viewing", assert => {
|
||||
visit("/about");
|
||||
andThen(() => {
|
||||
ok($('body.about-page').length, "has body class");
|
||||
ok(exists('.about.admins .user-info'), 'has admins');
|
||||
ok(exists('.about.moderators .user-info'), 'has moderators');
|
||||
ok(exists('.about.stats tr td'), 'has stats');
|
||||
assert.ok($('body.about-page').length, "has body class");
|
||||
assert.ok(exists('.about.admins .user-info'), 'has admins');
|
||||
assert.ok(exists('.about.moderators .user-info'), 'has moderators');
|
||||
assert.ok(exists('.about.stats tr td'), 'has stats');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -3,7 +3,7 @@ import PreloadStore from 'preload-store';
|
|||
|
||||
acceptance("Account Created");
|
||||
|
||||
test("account created - message", assert => {
|
||||
QUnit.test("account created - message", assert => {
|
||||
PreloadStore.store('accountCreated', {
|
||||
message: "Hello World",
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ test("account created - message", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("account created - resend email", assert => {
|
||||
QUnit.test("account created - resend email", assert => {
|
||||
PreloadStore.store('accountCreated', {
|
||||
message: "Hello World",
|
||||
username: 'eviltrout',
|
||||
|
@ -47,7 +47,7 @@ test("account created - resend email", assert => {
|
|||
|
||||
});
|
||||
|
||||
test("account created - update email - cancel", assert => {
|
||||
QUnit.test("account created - update email - cancel", assert => {
|
||||
PreloadStore.store('accountCreated', {
|
||||
message: "Hello World",
|
||||
username: 'eviltrout',
|
||||
|
@ -68,7 +68,7 @@ test("account created - update email - cancel", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("account created - update email - submit", assert => {
|
||||
QUnit.test("account created - update email - submit", assert => {
|
||||
PreloadStore.store('accountCreated', {
|
||||
message: "Hello World",
|
||||
username: 'eviltrout',
|
||||
|
@ -94,4 +94,4 @@ test("account created - update email - submit", assert => {
|
|||
assert.equal(email, 'newemail@example.com');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -2,33 +2,33 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Admin - Site Texts", { loggedIn: true });
|
||||
|
||||
test("search for a key", () => {
|
||||
QUnit.test("search for a key", assert => {
|
||||
visit("/admin/customize/site_texts");
|
||||
|
||||
fillIn('.site-text-search', 'Test');
|
||||
andThen(() => {
|
||||
ok(exists('.site-text'));
|
||||
ok(exists(".site-text:not(.overridden)"));
|
||||
ok(exists('.site-text.overridden'));
|
||||
assert.ok(exists('.site-text'));
|
||||
assert.ok(exists(".site-text:not(.overridden)"));
|
||||
assert.ok(exists('.site-text.overridden'));
|
||||
});
|
||||
|
||||
|
||||
// Only show overridden
|
||||
click('.extra-options input');
|
||||
andThen(() => {
|
||||
ok(!exists(".site-text:not(.overridden)"));
|
||||
ok(exists('.site-text.overridden'));
|
||||
assert.ok(!exists(".site-text:not(.overridden)"));
|
||||
assert.ok(exists('.site-text.overridden'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test("edit and revert a site text by key", () => {
|
||||
QUnit.test("edit and revert a site text by key", assert => {
|
||||
visit("/admin/customize/site_texts/site.test");
|
||||
andThen(() => {
|
||||
equal(find('.title h3').text(), 'site.test');
|
||||
ok(!exists('.save-messages .saved'));
|
||||
ok(!exists('.save-messages .saved'));
|
||||
ok(!exists('.revert-site-text'));
|
||||
assert.equal(find('.title h3').text(), 'site.test');
|
||||
assert.ok(!exists('.save-messages .saved'));
|
||||
assert.ok(!exists('.save-messages .saved'));
|
||||
assert.ok(!exists('.revert-site-text'));
|
||||
});
|
||||
|
||||
// Change the value
|
||||
|
@ -36,19 +36,19 @@ test("edit and revert a site text by key", () => {
|
|||
click(".save-changes");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.save-messages .saved'));
|
||||
ok(exists('.revert-site-text'));
|
||||
assert.ok(exists('.save-messages .saved'));
|
||||
assert.ok(exists('.revert-site-text'));
|
||||
});
|
||||
|
||||
// Revert the changes
|
||||
click('.revert-site-text');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'));
|
||||
assert.ok(exists('.bootbox.modal'));
|
||||
});
|
||||
click('.bootbox.modal .btn-primary');
|
||||
|
||||
andThen(() => {
|
||||
ok(!exists('.save-messages .saved'));
|
||||
ok(!exists('.revert-site-text'));
|
||||
assert.ok(!exists('.save-messages .saved'));
|
||||
assert.ok(!exists('.revert-site-text'));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,10 +2,10 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Admin - Users List", { loggedIn: true });
|
||||
|
||||
test("lists users", () => {
|
||||
QUnit.test("lists users", assert => {
|
||||
visit("/admin/users/list/active");
|
||||
andThen(() => {
|
||||
ok(exists('.users-list .user'));
|
||||
ok(!exists('.user:eq(0) .email small'), 'escapes email');
|
||||
assert.ok(exists('.users-list .user'));
|
||||
assert.ok(!exists('.user:eq(0) .email small'), 'escapes email');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,17 +2,17 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Badges");
|
||||
|
||||
test("Visit Badge Pages", () => {
|
||||
QUnit.test("Visit Badge Pages", assert => {
|
||||
visit("/badges");
|
||||
andThen(() => {
|
||||
ok($('body.badges-page').length, "has body class");
|
||||
ok(exists('.badge-groups .badge-card'), "has a list of badges");
|
||||
assert.ok($('body.badges-page').length, "has body class");
|
||||
assert.ok(exists('.badge-groups .badge-card'), "has a list of badges");
|
||||
});
|
||||
|
||||
visit("/badges/9/autobiographer");
|
||||
andThen(() => {
|
||||
ok(exists('.badge-card'), "has the badge in the listing");
|
||||
ok(exists('.user-info'), "has the list of users with that badge");
|
||||
ok(!exists('.badge-card:eq(0) script'));
|
||||
assert.ok(exists('.badge-card'), "has the badge in the listing");
|
||||
assert.ok(exists('.user-info'), "has the list of users with that badge");
|
||||
assert.ok(!exists('.badge-card:eq(0) script'));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -6,7 +6,7 @@ acceptance("Category Edit", {
|
|||
settings: { email_in: true }
|
||||
});
|
||||
|
||||
test("Can open the category modal", assert => {
|
||||
QUnit.test("Can open the category modal", assert => {
|
||||
visit("/c/bug");
|
||||
|
||||
click('.edit-category');
|
||||
|
@ -20,7 +20,7 @@ test("Can open the category modal", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Change the category color", assert => {
|
||||
QUnit.test("Change the category color", assert => {
|
||||
visit("/c/bug");
|
||||
|
||||
click('.edit-category');
|
||||
|
@ -32,7 +32,7 @@ test("Change the category color", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Change the topic template", assert => {
|
||||
QUnit.test("Change the topic template", assert => {
|
||||
visit("/c/bug");
|
||||
|
||||
click('.edit-category');
|
||||
|
@ -45,7 +45,7 @@ test("Change the topic template", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Error Saving", assert => {
|
||||
QUnit.test("Error Saving", assert => {
|
||||
visit("/c/bug");
|
||||
|
||||
click('.edit-category');
|
||||
|
@ -58,19 +58,19 @@ test("Error Saving", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Subcategory list settings", () => {
|
||||
QUnit.test("Subcategory list settings", assert => {
|
||||
visit("/c/bug");
|
||||
|
||||
click('.edit-category');
|
||||
click('.edit-category-settings');
|
||||
|
||||
andThen(() => {
|
||||
ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible by default");
|
||||
assert.ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible by default");
|
||||
});
|
||||
|
||||
click(".show-subcategory-list-field input[type=checkbox]");
|
||||
andThen(() => {
|
||||
ok(visible(".subcategory-list-style-field"), "subcategory list style is shown if show subcategory list is checked");
|
||||
assert.ok(visible(".subcategory-list-style-field"), "subcategory list style is shown if show subcategory list is checked");
|
||||
});
|
||||
|
||||
click('.edit-category-general');
|
||||
|
@ -78,7 +78,7 @@ test("Subcategory list settings", () => {
|
|||
|
||||
click('.edit-category-settings');
|
||||
andThen(() => {
|
||||
ok(!visible(".show-subcategory-list-field"), "show subcategory list isn't visible for child categories");
|
||||
ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible for child categories");
|
||||
assert.ok(!visible(".show-subcategory-list-field"), "show subcategory list isn't visible for child categories");
|
||||
assert.ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible for child categories");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,18 +2,18 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Category hashtag", { loggedIn: true });
|
||||
|
||||
test("category hashtag is cooked properly", () => {
|
||||
QUnit.test("category hashtag is cooked properly", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
|
||||
fillIn('.d-editor-input', "this is a category hashtag #bug");
|
||||
andThen(() => {
|
||||
// TODO: Test that the autocomplete shows
|
||||
equal(find('.d-editor-preview:visible').html().trim(), "<p>this is a category hashtag <a href=\"/c/bugs\" class=\"hashtag\">#<span>bug</span></a></p>");
|
||||
assert.equal(find('.d-editor-preview:visible').html().trim(), "<p>this is a category hashtag <a href=\"/c/bugs\" class=\"hashtag\">#<span>bug</span></a></p>");
|
||||
});
|
||||
|
||||
click('#reply-control .btn.create');
|
||||
andThen(() => {
|
||||
equal(find('.topic-post:last .cooked p').html().trim(), "this is a category hashtag <a href=\"/c/bugs\" class=\"hashtag\">#<span>bug</span></a>");
|
||||
assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is a category hashtag <a href=\"/c/bugs\" class=\"hashtag\">#<span>bug</span></a>");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -7,44 +7,44 @@ acceptance("Composer", {
|
|||
}
|
||||
});
|
||||
|
||||
test("Tests the Composer controls", () => {
|
||||
QUnit.test("Tests the Composer controls", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
ok(exists('#create-topic'), 'the create button is visible');
|
||||
assert.ok(exists('#create-topic'), 'the create button is visible');
|
||||
});
|
||||
|
||||
click('#create-topic');
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
ok(exists('.title-input .popup-tip.bad.hide'), 'title errors are hidden by default');
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.bad.hide'), 'body errors are hidden by default');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(exists('.title-input .popup-tip.bad.hide'), 'title errors are hidden by default');
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.bad.hide'), 'body errors are hidden by default');
|
||||
});
|
||||
|
||||
click('a.toggle-preview');
|
||||
andThen(() => {
|
||||
ok(!exists('.d-editor-preview:visible'), "clicking the toggle hides the preview");
|
||||
assert.ok(!exists('.d-editor-preview:visible'), "clicking the toggle hides the preview");
|
||||
});
|
||||
|
||||
click('a.toggle-preview');
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-preview:visible'), "clicking the toggle shows the preview again");
|
||||
assert.ok(exists('.d-editor-preview:visible'), "clicking the toggle shows the preview again");
|
||||
});
|
||||
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
ok(!exists('.title-input .popup-tip.bad.hide'), 'it shows the empty title error');
|
||||
ok(!exists('.d-editor-wrapper .popup-tip.bad.hide'), 'it shows the empty body error');
|
||||
assert.ok(!exists('.title-input .popup-tip.bad.hide'), 'it shows the empty title error');
|
||||
assert.ok(!exists('.d-editor-wrapper .popup-tip.bad.hide'), 'it shows the empty body error');
|
||||
});
|
||||
|
||||
fillIn('#reply-title', "this is my new topic title");
|
||||
andThen(() => {
|
||||
ok(exists('.title-input .popup-tip.good'), 'the title is now good');
|
||||
assert.ok(exists('.title-input .popup-tip.good'), 'the title is now good');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', "this is the *content* of a post");
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-preview').html().trim(), "<p>this is the <em>content</em> of a post</p>", "it previews content");
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
assert.equal(find('.d-editor-preview').html().trim(), "<p>this is the <em>content</em> of a post</p>", "it previews content");
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
|
@ -64,89 +64,89 @@ test("Tests the Composer controls", () => {
|
|||
|
||||
andThen(() => {
|
||||
const example = I18n.t(`composer.bold_text`);
|
||||
equal(find('#reply-control .d-editor-input').val().trim(),
|
||||
assert.equal(find('#reply-control .d-editor-input').val().trim(),
|
||||
`this is the *content* of a post**${example}**`,
|
||||
"it supports keyboard shortcuts");
|
||||
});
|
||||
|
||||
click('#reply-control a.cancel');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
});
|
||||
|
||||
click('.modal-footer a:eq(1)');
|
||||
andThen(() => {
|
||||
ok(!exists('.bootbox.modal'), 'the confirmation can be cancelled');
|
||||
assert.ok(!exists('.bootbox.modal'), 'the confirmation can be cancelled');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test("Create a topic with server side errors", () => {
|
||||
QUnit.test("Create a topic with server side errors", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "this title triggers an error");
|
||||
fillIn('.d-editor-input', "this is the *content* of a post");
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'), 'it pops up an error message');
|
||||
assert.ok(exists('.bootbox.modal'), 'it pops up an error message');
|
||||
});
|
||||
click('.bootbox.modal a.btn-primary');
|
||||
andThen(() => {
|
||||
ok(!exists('.bootbox.modal'), 'it dismisses the error');
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(!exists('.bootbox.modal'), 'it dismisses the error');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
});
|
||||
});
|
||||
|
||||
test("Create a Topic", () => {
|
||||
QUnit.test("Create a Topic", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "Internationalization Localization");
|
||||
fillIn('.d-editor-input', "this is the *content* of a new topic post");
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
equal(currentURL(), "/t/internationalization-localization/280", "it transitions to the newly created topic URL");
|
||||
assert.equal(currentURL(), "/t/internationalization-localization/280", "it transitions to the newly created topic URL");
|
||||
});
|
||||
});
|
||||
|
||||
test("Create an enqueued Topic", () => {
|
||||
QUnit.test("Create an enqueued Topic", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "Internationalization Localization");
|
||||
fillIn('.d-editor-input', "enqueue this content please");
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
ok(visible('#discourse-modal'), 'it pops up a modal');
|
||||
equal(currentURL(), "/", "it doesn't change routes");
|
||||
assert.ok(visible('#discourse-modal'), 'it pops up a modal');
|
||||
assert.equal(currentURL(), "/", "it doesn't change routes");
|
||||
});
|
||||
|
||||
click('.modal-footer button');
|
||||
andThen(() => {
|
||||
ok(invisible('#discourse-modal'), 'the modal can be dismissed');
|
||||
assert.ok(invisible('#discourse-modal'), 'the modal can be dismissed');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test("Create a Reply", () => {
|
||||
QUnit.test("Create a Reply", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
|
||||
andThen(() => {
|
||||
ok(!exists('article[data-post-id=12345]'), 'the post is not in the DOM');
|
||||
assert.ok(!exists('article[data-post-id=12345]'), 'the post is not in the DOM');
|
||||
});
|
||||
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
ok(!exists('#reply-title'), 'there is no title since this is a reply');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(!exists('#reply-title'), 'there is no title since this is a reply');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', 'this is the content of my reply');
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
equal(find('.cooked:last p').text(), 'this is the content of my reply');
|
||||
assert.equal(find('.cooked:last p').text(), 'this is the content of my reply');
|
||||
});
|
||||
});
|
||||
|
||||
test("Posting on a different topic", (assert) => {
|
||||
QUnit.test("Posting on a different topic", (assert) => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
fillIn('.d-editor-input', 'this is the content for a different topic');
|
||||
|
@ -167,106 +167,106 @@ test("Posting on a different topic", (assert) => {
|
|||
});
|
||||
|
||||
|
||||
test("Create an enqueued Reply", () => {
|
||||
QUnit.test("Create an enqueued Reply", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
ok(!exists('#reply-title'), 'there is no title since this is a reply');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(!exists('#reply-title'), 'there is no title since this is a reply');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', 'enqueue this content please');
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
ok(find('.cooked:last p').text() !== 'enqueue this content please', "it doesn't insert the post");
|
||||
assert.ok(find('.cooked:last p').text() !== 'enqueue this content please', "it doesn't insert the post");
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
ok(visible('#discourse-modal'), 'it pops up a modal');
|
||||
assert.ok(visible('#discourse-modal'), 'it pops up a modal');
|
||||
});
|
||||
|
||||
click('.modal-footer button');
|
||||
andThen(() => {
|
||||
ok(invisible('#discourse-modal'), 'the modal can be dismissed');
|
||||
assert.ok(invisible('#discourse-modal'), 'the modal can be dismissed');
|
||||
});
|
||||
});
|
||||
|
||||
test("Edit the first post", () => {
|
||||
QUnit.test("Edit the first post", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
|
||||
ok(!exists('.topic-post:eq(0) .post-info.edits'), 'it has no edits icon at first');
|
||||
assert.ok(!exists('.topic-post:eq(0) .post-info.edits'), 'it has no edits icon at first');
|
||||
|
||||
click('.topic-post:eq(0) button.show-more-actions');
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('Any plans to support'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('Any plans to support'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
|
||||
fillIn('.d-editor-input', "This is the new text for the post");
|
||||
fillIn('#reply-title', "This is the new text for the title");
|
||||
click('#reply-control button.create');
|
||||
andThen(() => {
|
||||
ok(!exists('.d-editor-input'), 'it closes the composer');
|
||||
ok(exists('.topic-post:eq(0) .post-info.edits'), 'it has the edits icon');
|
||||
ok(find('#topic-title h1').text().indexOf('This is the new text for the title') !== -1, 'it shows the new title');
|
||||
ok(find('.topic-post:eq(0) .cooked').text().indexOf('This is the new text for the post') !== -1, 'it updates the post');
|
||||
assert.ok(!exists('.d-editor-input'), 'it closes the composer');
|
||||
assert.ok(exists('.topic-post:eq(0) .post-info.edits'), 'it has the edits icon');
|
||||
assert.ok(find('#topic-title h1').text().indexOf('This is the new text for the title') !== -1, 'it shows the new title');
|
||||
assert.ok(find('.topic-post:eq(0) .cooked').text().indexOf('This is the new text for the post') !== -1, 'it updates the post');
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer can switch between edits", () => {
|
||||
QUnit.test("Composer can switch between edits", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
click('.topic-post:eq(1) button.edit');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer with dirty edit can toggle to another edit", () => {
|
||||
QUnit.test("Composer with dirty edit can toggle to another edit", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
fillIn('.d-editor-input', 'This is a dirty reply');
|
||||
click('.topic-post:eq(1) button.edit');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
});
|
||||
click('.modal-footer a:eq(0)');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer can toggle between edit and reply", () => {
|
||||
QUnit.test("Composer can toggle between edit and reply", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
click('.topic-post:eq(0) button.reply');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val(), "", 'it clears the input');
|
||||
assert.equal(find('.d-editor-input').val(), "", 'it clears the input');
|
||||
});
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer can toggle between reply and createTopic", () => {
|
||||
QUnit.test("Composer can toggle between reply and createTopic", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.reply');
|
||||
click('button.options');
|
||||
click('.popup-menu .fa-eye-slash');
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) > 0,
|
||||
'it sets the post type to whisper'
|
||||
);
|
||||
|
@ -274,12 +274,12 @@ test("Composer can toggle between reply and createTopic", () => {
|
|||
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
ok(exists('#create-topic'), 'the create topic button is visible');
|
||||
assert.ok(exists('#create-topic'), 'the create topic button is visible');
|
||||
});
|
||||
|
||||
click('#create-topic');
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) === -1,
|
||||
"it should reset the state of the composer's model"
|
||||
);
|
||||
|
@ -288,7 +288,7 @@ test("Composer can toggle between reply and createTopic", () => {
|
|||
click('button.options');
|
||||
click('.popup-menu .fa-eye-slash');
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) > 0,
|
||||
'it sets the topic to unlisted'
|
||||
);
|
||||
|
@ -298,29 +298,29 @@ test("Composer can toggle between reply and createTopic", () => {
|
|||
|
||||
click('.topic-post:eq(0) button.reply');
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) === -1,
|
||||
"it should reset the state of the composer's model"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer with dirty reply can toggle to edit", () => {
|
||||
QUnit.test("Composer with dirty reply can toggle to edit", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.reply');
|
||||
fillIn('.d-editor-input', 'This is a dirty reply');
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
});
|
||||
click('.modal-footer a:eq(0)');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
});
|
||||
|
||||
test("Composer draft with dirty reply can toggle to edit", () => {
|
||||
QUnit.test("Composer draft with dirty reply can toggle to edit", assert => {
|
||||
visit("/t/this-is-a-test-topic/9");
|
||||
|
||||
click('.topic-post:eq(0) button.reply');
|
||||
|
@ -328,10 +328,10 @@ test("Composer draft with dirty reply can toggle to edit", () => {
|
|||
click('.toggler');
|
||||
click('.topic-post:eq(0) button.edit');
|
||||
andThen(() => {
|
||||
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
|
||||
});
|
||||
click('.modal-footer a:eq(0)');
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -9,58 +9,58 @@ acceptance("Composer topic featured links", {
|
|||
});
|
||||
|
||||
|
||||
test("onebox with title", () => {
|
||||
QUnit.test("onebox with title", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "http://www.example.com/has-title.html");
|
||||
andThen(() => {
|
||||
ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article");
|
||||
assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
assert.equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article");
|
||||
});
|
||||
});
|
||||
|
||||
test("onebox result doesn't include a title", () => {
|
||||
QUnit.test("onebox result doesn't include a title", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', 'http://www.example.com/no-title.html');
|
||||
andThen(() => {
|
||||
ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
equal(find('.title-input input').val(), "http://www.example.com/no-title.html", "title is unchanged");
|
||||
assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
assert.equal(find('.title-input input').val(), "http://www.example.com/no-title.html", "title is unchanged");
|
||||
});
|
||||
});
|
||||
|
||||
test("no onebox result", () => {
|
||||
QUnit.test("no onebox result", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "http://www.example.com/nope-onebox.html");
|
||||
andThen(() => {
|
||||
ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'link is pasted into body');
|
||||
equal(find('.title-input input').val(), "http://www.example.com/nope-onebox.html", "title is unchanged");
|
||||
assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'link is pasted into body');
|
||||
assert.equal(find('.title-input input').val(), "http://www.example.com/nope-onebox.html", "title is unchanged");
|
||||
});
|
||||
});
|
||||
|
||||
test("ignore internal links", () => {
|
||||
QUnit.test("ignore internal links", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
const title = "http://" + window.location.hostname + "/internal-page.html";
|
||||
fillIn('#reply-title', title);
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-preview').html().trim().indexOf('onebox'), -1, "onebox preview doesn't show");
|
||||
equal(find('.d-editor-input').val().length, 0, "link isn't put into the post");
|
||||
equal(find('.title-input input').val(), title, "title is unchanged");
|
||||
assert.equal(find('.d-editor-preview').html().trim().indexOf('onebox'), -1, "onebox preview doesn't show");
|
||||
assert.equal(find('.d-editor-input').val().length, 0, "link isn't put into the post");
|
||||
assert.equal(find('.title-input input').val(), title, "title is unchanged");
|
||||
});
|
||||
});
|
||||
|
||||
test("link is longer than max title length", () => {
|
||||
QUnit.test("link is longer than max title length", assert => {
|
||||
visit("/");
|
||||
click('#create-topic');
|
||||
fillIn('#reply-title', "http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html");
|
||||
andThen(() => {
|
||||
ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article");
|
||||
assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it");
|
||||
assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
|
||||
assert.equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -8,14 +8,14 @@ acceptance("Create Account - User Fields", {
|
|||
}
|
||||
});
|
||||
|
||||
test("create account with user fields", () => {
|
||||
QUnit.test("create account with user fields", assert => {
|
||||
visit("/");
|
||||
click("header .sign-up-button");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.create-account'), "it shows the create account modal");
|
||||
ok(exists('.user-field'), "it has at least one user field");
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first');
|
||||
assert.ok(exists('.create-account'), "it shows the create account modal");
|
||||
assert.ok(exists('.user-field'), "it has at least one user field");
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first');
|
||||
});
|
||||
|
||||
fillIn('#new-account-name', 'Dr. Good Tuna');
|
||||
|
@ -24,24 +24,24 @@ test("create account with user fields", () => {
|
|||
fillIn('#new-account-username', 'goodtuna');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('#username-validation.good'), 'the username validation is good');
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled due to lack of user fields');
|
||||
assert.ok(exists('#username-validation.good'), 'the username validation is good');
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled due to lack of user fields');
|
||||
});
|
||||
|
||||
fillIn(".user-field input[type=text]:first", "Barky");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled because field is not checked');
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled because field is not checked');
|
||||
});
|
||||
|
||||
click(".user-field input[type=checkbox]");
|
||||
andThen(() => {
|
||||
not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled because field is not checked');
|
||||
assert.not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled because field is not checked');
|
||||
});
|
||||
|
||||
click(".user-field input[type=checkbox]");
|
||||
andThen(() => {
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'unclicking the checkbox disables the submit');
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'unclicking the checkbox disables the submit');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -4,14 +4,14 @@ import PreloadStore from 'preload-store';
|
|||
|
||||
acceptance("CustomHTML set");
|
||||
|
||||
test("has no custom HTML in the top", assert => {
|
||||
QUnit.test("has no custom HTML in the top", assert => {
|
||||
visit("/static/faq");
|
||||
andThen(() => {
|
||||
assert.ok(!exists('span.custom-html-test'), 'it has no markup');
|
||||
});
|
||||
});
|
||||
|
||||
test("renders set HTML", assert => {
|
||||
QUnit.test("renders set HTML", assert => {
|
||||
setCustomHTML('top', '<span class="custom-html-test">HTML</span>');
|
||||
|
||||
visit("/static/faq");
|
||||
|
@ -20,11 +20,11 @@ test("renders set HTML", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("renders preloaded HTML", assert => {
|
||||
QUnit.test("renders preloaded HTML", assert => {
|
||||
PreloadStore.store('customHTML', {top: "<span class='cookie'>monster</span>"});
|
||||
|
||||
visit("/static/faq");
|
||||
andThen(() => {
|
||||
assert.equal(find('span.cookie').text(), 'monster', 'it inserted the markup');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,16 +1,16 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("CustomHTML template", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
Ember.TEMPLATES['top'] = Ember.HTMLBars.compile(`<span class='top-span'>TOP</span>`);
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
delete Ember.TEMPLATES['top'];
|
||||
}
|
||||
});
|
||||
|
||||
test("renders custom template", assert => {
|
||||
QUnit.test("renders custom template", assert => {
|
||||
visit("/static/faq");
|
||||
andThen(() => {
|
||||
assert.equal(find('span.top-span').text(), 'TOP', 'it inserted the template');
|
||||
|
|
|
@ -2,32 +2,32 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Emoji", { loggedIn: true });
|
||||
|
||||
test("emoji is cooked properly", () => {
|
||||
QUnit.test("emoji is cooked properly", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
|
||||
fillIn('.d-editor-input', "this is an emoji :blonde_woman:");
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-preview:visible').html().trim(), "<p>this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman.png?v=5\" title=\":blonde_woman:\" class=\"emoji\" alt=\":blonde_woman:\"></p>");
|
||||
assert.equal(find('.d-editor-preview:visible').html().trim(), "<p>this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman.png?v=5\" title=\":blonde_woman:\" class=\"emoji\" alt=\":blonde_woman:\"></p>");
|
||||
});
|
||||
|
||||
click('#reply-control .btn.create');
|
||||
andThen(() => {
|
||||
equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman.png?v=5\" title=\":blonde_woman:\" class=\"emoji\" alt=\":blonde_woman:\">");
|
||||
assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman.png?v=5\" title=\":blonde_woman:\" class=\"emoji\" alt=\":blonde_woman:\">");
|
||||
});
|
||||
});
|
||||
|
||||
test("skin toned emoji is cooked properly", () => {
|
||||
QUnit.test("skin toned emoji is cooked properly", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
|
||||
fillIn('.d-editor-input', "this is an emoji :blonde_woman:t5:");
|
||||
andThen(() => {
|
||||
equal(find('.d-editor-preview:visible').html().trim(), "<p>this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman/5.png?v=5\" title=\":blonde_woman:t5:\" class=\"emoji\" alt=\":blonde_woman:t5:\"></p>");
|
||||
assert.equal(find('.d-editor-preview:visible').html().trim(), "<p>this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman/5.png?v=5\" title=\":blonde_woman:t5:\" class=\"emoji\" alt=\":blonde_woman:t5:\"></p>");
|
||||
});
|
||||
|
||||
click('#reply-control .btn.create');
|
||||
andThen(() => {
|
||||
equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman/5.png?v=5\" title=\":blonde_woman:t5:\" class=\"emoji\" alt=\":blonde_woman:t5:\">");
|
||||
assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji <img src=\"/images/emoji/emoji_one/blonde_woman/5.png?v=5\" title=\":blonde_woman:t5:\" class=\"emoji\" alt=\":blonde_woman:t5:\">");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,39 +2,39 @@ import { acceptance, logIn } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Editing Group");
|
||||
|
||||
test("Editing group", () => {
|
||||
QUnit.test("Editing group", assert => {
|
||||
logIn();
|
||||
Discourse.reset();
|
||||
|
||||
visit("/groups/discourse/edit");
|
||||
|
||||
andThen(() => {
|
||||
ok(find('.group-flair-inputs').length === 1, 'it should display avatar flair inputs');
|
||||
ok(find('.group-edit-bio').length === 1, 'it should display group bio input');
|
||||
ok(find('.group-edit-full-name').length === 1, 'it should display group full name input');
|
||||
ok(find('.group-edit-public').length === 1, 'it should display group public input');
|
||||
ok(find('.group-edit-allow-membership-requests').length === 1, 'it should display group allow_membership_requets input');
|
||||
ok(find('.group-members-input .item').length === 7, 'it should display group members');
|
||||
ok(find('.group-members-input-selector').length === 1, 'it should display input to add group members');
|
||||
ok(find('.group-members-input-selector .add[disabled]').length === 1, 'add members button should be disabled');
|
||||
assert.ok(find('.group-flair-inputs').length === 1, 'it should display avatar flair inputs');
|
||||
assert.ok(find('.group-edit-bio').length === 1, 'it should display group bio input');
|
||||
assert.ok(find('.group-edit-full-name').length === 1, 'it should display group full name input');
|
||||
assert.ok(find('.group-edit-public').length === 1, 'it should display group public input');
|
||||
assert.ok(find('.group-edit-allow-membership-requests').length === 1, 'it should display group allow_membership_requets input');
|
||||
assert.ok(find('.group-members-input .item').length === 7, 'it should display group members');
|
||||
assert.ok(find('.group-members-input-selector').length === 1, 'it should display input to add group members');
|
||||
assert.ok(find('.group-members-input-selector .add[disabled]').length === 1, 'add members button should be disabled');
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
ok(find('.group-edit-allow-membership-requests[disabled]').length === 1, 'it should disable group allow_membership_request input');
|
||||
assert.ok(find('.group-edit-allow-membership-requests[disabled]').length === 1, 'it should disable group allow_membership_request input');
|
||||
});
|
||||
|
||||
click('.group-edit-public');
|
||||
click('.group-edit-allow-membership-requests');
|
||||
|
||||
andThen(() => {
|
||||
ok(find('.group-edit-public[disabled]').length === 1, 'it should disable group public input');
|
||||
assert.ok(find('.group-edit-public[disabled]').length === 1, 'it should disable group public input');
|
||||
});
|
||||
});
|
||||
|
||||
test("Editing group as an anonymous user", () => {
|
||||
QUnit.test("Editing group as an anonymous user", assert => {
|
||||
visit("/groups/discourse/edit");
|
||||
|
||||
andThen(() => {
|
||||
ok(count('.group-members tr') > 0, "it should redirect to members page for an anonymous user");
|
||||
assert.ok(count('.group-members tr') > 0, "it should redirect to members page for an anonymous user");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,7 +2,7 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Group Logs", {
|
||||
loggedIn: true,
|
||||
setup() {
|
||||
beforeEach() {
|
||||
const response = object => {
|
||||
return [
|
||||
200,
|
||||
|
@ -26,15 +26,15 @@ acceptance("Group Logs", {
|
|||
}
|
||||
});
|
||||
|
||||
test("Browsing group logs", () => {
|
||||
QUnit.test("Browsing group logs", assert => {
|
||||
visit("/groups/snorlax/logs");
|
||||
|
||||
andThen(() => {
|
||||
ok(find('tr.group-logs-row').length === 2, 'it should display the right number of logs');
|
||||
assert.ok(find('tr.group-logs-row').length === 2, 'it should display the right number of logs');
|
||||
click(find(".group-logs-row button")[0]);
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
ok(find('tr.group-logs-row').length === 1, 'it should display the right number of logs');
|
||||
assert.ok(find('tr.group-logs-row').length === 1, 'it should display the right number of logs');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,104 +2,104 @@ import { acceptance, logIn } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Groups");
|
||||
|
||||
test("Browsing Groups", () => {
|
||||
QUnit.test("Browsing Groups", assert => {
|
||||
visit("/groups");
|
||||
|
||||
andThen(() => {
|
||||
equal(count('.groups-table-row'), 2, 'it displays visible groups');
|
||||
equal(find('.group-index-join').length, 1, 'it shows button to join group');
|
||||
equal(find('.group-index-request').length, 1, 'it shows button to request for group membership');
|
||||
assert.equal(count('.groups-table-row'), 2, 'it displays visible groups');
|
||||
assert.equal(find('.group-index-join').length, 1, 'it shows button to join group');
|
||||
assert.equal(find('.group-index-request').length, 1, 'it shows button to request for group membership');
|
||||
});
|
||||
|
||||
click('.group-index-join');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
});
|
||||
|
||||
click('.login-modal .close');
|
||||
|
||||
andThen(() => {
|
||||
ok(invisible('.modal.login-modal'), 'it closes the login modal');
|
||||
assert.ok(invisible('.modal.login-modal'), 'it closes the login modal');
|
||||
});
|
||||
|
||||
click('.group-index-request');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
});
|
||||
|
||||
click("a[href='/groups/discourse/members']");
|
||||
|
||||
andThen(() => {
|
||||
equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page");
|
||||
assert.equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page");
|
||||
});
|
||||
|
||||
click('.group-index-join');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
assert.ok(exists('.modal.login-modal'), 'it shows the login modal');
|
||||
});
|
||||
});
|
||||
|
||||
test("Viewing Group", () => {
|
||||
QUnit.test("Viewing Group", assert => {
|
||||
visit("/groups/discourse");
|
||||
|
||||
andThen(() => {
|
||||
ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair");
|
||||
ok(count('.group-members tr') > 0, "it lists group members");
|
||||
assert.ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair");
|
||||
assert.ok(count('.group-members tr') > 0, "it lists group members");
|
||||
});
|
||||
|
||||
click(".nav-pills li a[title='Activity']");
|
||||
|
||||
andThen(() => {
|
||||
ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
assert.ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
});
|
||||
|
||||
click(".group-activity-nav li a[href='/groups/discourse/activity/topics']");
|
||||
|
||||
andThen(() => {
|
||||
ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
assert.ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
});
|
||||
|
||||
click(".group-activity-nav li a[href='/groups/discourse/activity/mentions']");
|
||||
|
||||
andThen(() => {
|
||||
ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
assert.ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
});
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".group-activity li a[href='/groups/discourse/activity/messages']").length,
|
||||
0,
|
||||
'it should not show messages tab if user is not a group user or admin'
|
||||
);
|
||||
ok(find(".nav-pills li a[title='Edit Group']").length === 0, 'it should not show messages tab if user is not admin');
|
||||
ok(find(".nav-pills li a[title='Logs']").length === 0, 'it should not show Logs tab if user is not admin');
|
||||
ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
assert.ok(find(".nav-pills li a[title='Edit Group']").length === 0, 'it should not show messages tab if user is not admin');
|
||||
assert.ok(find(".nav-pills li a[title='Logs']").length === 0, 'it should not show Logs tab if user is not admin');
|
||||
assert.ok(count('.user-stream .item') > 0, "it lists stream items");
|
||||
});
|
||||
});
|
||||
|
||||
test("Admin Viewing Group", () => {
|
||||
QUnit.test("Admin Viewing Group", assert => {
|
||||
logIn();
|
||||
Discourse.reset();
|
||||
|
||||
visit("/groups/discourse");
|
||||
|
||||
andThen(() => {
|
||||
ok(find(".nav-pills li a[title='Edit Group']").length === 1, 'it should show edit group tab if user is admin');
|
||||
ok(find(".nav-pills li a[title='Logs']").length === 1, 'it should show Logs tab if user is admin');
|
||||
assert.ok(find(".nav-pills li a[title='Edit Group']").length === 1, 'it should show edit group tab if user is admin');
|
||||
assert.ok(find(".nav-pills li a[title='Logs']").length === 1, 'it should show Logs tab if user is admin');
|
||||
|
||||
equal(find('.group-info-name').text(), 'Awesome Team', 'it should display the group name');
|
||||
assert.equal(find('.group-info-name').text(), 'Awesome Team', 'it should display the group name');
|
||||
});
|
||||
|
||||
click(".nav-pills li a[title='Activity']");
|
||||
|
||||
andThen(() => {
|
||||
equal(
|
||||
assert.equal(
|
||||
find(".group-activity li a[href='/groups/discourse/activity/messages']").length,
|
||||
1,
|
||||
'it should show messages tab if user is admin'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -7,7 +7,7 @@ acceptance("Invite Accept", {
|
|||
}
|
||||
});
|
||||
|
||||
test("Invite Acceptance Page", () => {
|
||||
QUnit.test("Invite Acceptance Page", assert => {
|
||||
PreloadStore.store('invite_info', {
|
||||
invited_by: {"id":123,"username":"neil","avatar_template":"/user_avatar/localhost/neil/{size}/25_1.png","name":"Neil Lalonde","title":"team"},
|
||||
email: "invited@asdf.com",
|
||||
|
@ -16,35 +16,35 @@ test("Invite Acceptance Page", () => {
|
|||
|
||||
visit("/invites/myvalidinvitetoken");
|
||||
andThen(() => {
|
||||
ok(exists("#new-account-username"), "shows the username input");
|
||||
equal(find("#new-account-username").val(), "invited", "username is prefilled");
|
||||
ok(exists("#new-account-name"), "shows the name input");
|
||||
ok(exists("#new-account-password"), "shows the password input");
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because name is not filled');
|
||||
assert.ok(exists("#new-account-username"), "shows the username input");
|
||||
assert.equal(find("#new-account-username").val(), "invited", "username is prefilled");
|
||||
assert.ok(exists("#new-account-name"), "shows the name input");
|
||||
assert.ok(exists("#new-account-password"), "shows the password input");
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because name is not filled');
|
||||
});
|
||||
|
||||
fillIn("#new-account-name", 'John Doe');
|
||||
andThen(() => {
|
||||
not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled');
|
||||
assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled');
|
||||
});
|
||||
|
||||
fillIn("#new-account-username", 'a');
|
||||
andThen(() => {
|
||||
ok(exists(".username-input .bad"), "username is not valid");
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
assert.ok(exists(".username-input .bad"), "username is not valid");
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
});
|
||||
|
||||
fillIn("#new-account-password", 'aaa');
|
||||
andThen(() => {
|
||||
ok(exists(".password-input .bad"), "password is not valid");
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
assert.ok(exists(".password-input .bad"), "password is not valid");
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
});
|
||||
|
||||
fillIn("#new-account-username", 'validname');
|
||||
fillIn("#new-account-password", 'secur3ty4Y0uAndMe');
|
||||
andThen(() => {
|
||||
ok(exists(".username-input .good"), "username is valid");
|
||||
ok(exists(".password-input .good"), "password is valid");
|
||||
not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled');
|
||||
assert.ok(exists(".username-input .good"), "username is valid");
|
||||
assert.ok(exists(".password-input .good"), "password is valid");
|
||||
assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,12 +8,12 @@ acceptance("Accept Invite - User Fields", {
|
|||
}
|
||||
});
|
||||
|
||||
test("accept invite with user fields", () => {
|
||||
QUnit.test("accept invite with user fields", assert => {
|
||||
visit("/invites/myvalidinvitetoken");
|
||||
andThen(() => {
|
||||
ok(exists(".invites-show"), "shows the accept invite page");
|
||||
ok(exists('.user-field'), "it has at least one user field");
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
assert.ok(exists(".invites-show"), "shows the accept invite page");
|
||||
assert.ok(exists('.user-field'), "it has at least one user field");
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled');
|
||||
});
|
||||
|
||||
fillIn("#new-account-name", 'John Doe');
|
||||
|
@ -21,24 +21,24 @@ test("accept invite with user fields", () => {
|
|||
fillIn("#new-account-password", 'secur3ty4Y0uAndMe');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists(".username-input .good"), "username is valid");
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is still disabled due to lack of user fields');
|
||||
assert.ok(exists(".username-input .good"), "username is valid");
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is still disabled due to lack of user fields');
|
||||
});
|
||||
|
||||
fillIn(".user-field input[type=text]:first", "Barky");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because field is not checked');
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because field is not checked');
|
||||
});
|
||||
|
||||
click(".user-field input[type=checkbox]");
|
||||
andThen(() => {
|
||||
not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled because field is checked');
|
||||
assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled because field is checked');
|
||||
});
|
||||
|
||||
click(".user-field input[type=checkbox]");
|
||||
andThen(() => {
|
||||
ok(exists('.invites-show .btn-primary:disabled'), 'unclicking the checkbox disables the submit');
|
||||
assert.ok(exists('.invites-show .btn-primary:disabled'), 'unclicking the checkbox disables the submit');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,24 +6,24 @@ acceptance("Login Required", {
|
|||
}
|
||||
});
|
||||
|
||||
test("redirect", () => {
|
||||
QUnit.test("redirect", assert => {
|
||||
visit('/latest');
|
||||
andThen(() => {
|
||||
equal(currentPath(), "login", "it redirects them to login");
|
||||
assert.equal(currentPath(), "login", "it redirects them to login");
|
||||
});
|
||||
|
||||
click('#site-logo');
|
||||
andThen(() => {
|
||||
equal(currentPath(), "login", "clicking the logo keeps them on login");
|
||||
assert.equal(currentPath(), "login", "clicking the logo keeps them on login");
|
||||
});
|
||||
|
||||
click('header .login-button');
|
||||
andThen(() => {
|
||||
ok(exists('.login-modal'), "they can still access the login modal");
|
||||
assert.ok(exists('.login-modal'), "they can still access the login modal");
|
||||
});
|
||||
|
||||
click('.modal-header .close');
|
||||
andThen(() => {
|
||||
ok(invisible('.login-modal'), "it closes the login modal");
|
||||
assert.ok(invisible('.login-modal'), "it closes the login modal");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,15 +1,15 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Topic Discovery - Mobile", { mobileView: true });
|
||||
|
||||
test("Visit Discovery Pages", () => {
|
||||
QUnit.test("Visit Discovery Pages", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
assert.ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
assert.ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
});
|
||||
|
||||
visit("/categories");
|
||||
andThen(() => {
|
||||
ok(exists('.category'), "has a list of categories");
|
||||
assert.ok(exists('.category'), "has a list of categories");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,10 +2,10 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("Signing In - Mobile", { mobileView: true });
|
||||
|
||||
test("sign in", () => {
|
||||
QUnit.test("sign in", assert => {
|
||||
visit("/");
|
||||
click("header .login-button");
|
||||
andThen(() => {
|
||||
ok(exists('#login-form'), "it shows the login modal");
|
||||
assert.ok(exists('#login-form'), "it shows the login modal");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,9 +2,9 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("User Directory - Mobile", { mobileView: true });
|
||||
|
||||
test("Visit Page", () => {
|
||||
QUnit.test("Visit Page", assert => {
|
||||
visit("/users");
|
||||
andThen(() => {
|
||||
ok(exists('.directory .user'), "has a list of users");
|
||||
assert.ok(exists('.directory .user'), "has a list of users");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,30 +1,30 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Modal");
|
||||
|
||||
test("modal", () => {
|
||||
QUnit.test("modal", assert => {
|
||||
visit('/');
|
||||
|
||||
andThen(() => {
|
||||
ok(find('#discourse-modal:visible').length === 0, 'there is no modal at first');
|
||||
assert.ok(find('#discourse-modal:visible').length === 0, 'there is no modal at first');
|
||||
});
|
||||
|
||||
click('.login-button');
|
||||
andThen(() => {
|
||||
ok(find('#discourse-modal:visible').length === 1, 'modal should appear');
|
||||
assert.ok(find('#discourse-modal:visible').length === 1, 'modal should appear');
|
||||
});
|
||||
|
||||
click('.modal-outer-container');
|
||||
andThen(() => {
|
||||
ok(find('#discourse-modal:visible').length === 0, 'modal should disappear when you click outside');
|
||||
assert.ok(find('#discourse-modal:visible').length === 0, 'modal should disappear when you click outside');
|
||||
});
|
||||
|
||||
click('.login-button');
|
||||
andThen(() => {
|
||||
ok(find('#discourse-modal:visible').length === 1, 'modal should reappear');
|
||||
assert.ok(find('#discourse-modal:visible').length === 1, 'modal should reappear');
|
||||
});
|
||||
|
||||
keyEvent('#main-outlet', 'keydown', 27);
|
||||
andThen(() => {
|
||||
ok(find('#discourse-modal:visible').length === 0, 'ESC should close the modal');
|
||||
assert.ok(find('#discourse-modal:visible').length === 0, 'ESC should close the modal');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -3,7 +3,7 @@ import PreloadStore from 'preload-store';
|
|||
import { parsePostData } from "helpers/create-pretender";
|
||||
|
||||
acceptance("Password Reset", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
const response = (object) => {
|
||||
return [
|
||||
200,
|
||||
|
@ -27,36 +27,35 @@ acceptance("Password Reset", {
|
|||
}
|
||||
});
|
||||
|
||||
test("Password Reset Page", () => {
|
||||
QUnit.test("Password Reset Page", assert => {
|
||||
PreloadStore.store('password_reset', {is_developer: false});
|
||||
|
||||
visit("/u/password-reset/myvalidtoken");
|
||||
andThen(() => {
|
||||
ok(exists(".password-reset input"), "shows the input");
|
||||
assert.ok(exists(".password-reset input"), "shows the input");
|
||||
});
|
||||
|
||||
fillIn('.password-reset input', 'perf3ctly5ecur3');
|
||||
andThen(() => {
|
||||
ok(exists(".password-reset .tip.good"), "input looks good");
|
||||
assert.ok(exists(".password-reset .tip.good"), "input looks good");
|
||||
});
|
||||
|
||||
fillIn('.password-reset input', '123');
|
||||
andThen(() => {
|
||||
ok(exists(".password-reset .tip.bad"), "input is not valid");
|
||||
ok(find(".password-reset .tip.bad").html().indexOf(I18n.t('user.password.too_short')) > -1, "password too short");
|
||||
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
|
||||
assert.ok(find(".password-reset .tip.bad").html().indexOf(I18n.t('user.password.too_short')) > -1, "password too short");
|
||||
});
|
||||
|
||||
fillIn('.password-reset input', 'jonesyAlienSlayer');
|
||||
click('.password-reset form button');
|
||||
andThen(() => {
|
||||
ok(exists(".password-reset .tip.bad"), "input is not valid");
|
||||
ok(find(".password-reset .tip.bad").html().indexOf("is the name of your cat") > -1, "server validation error message shows");
|
||||
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
|
||||
assert.ok(find(".password-reset .tip.bad").html().indexOf("is the name of your cat") > -1, "server validation error message shows");
|
||||
});
|
||||
|
||||
fillIn('.password-reset input', 'perf3ctly5ecur3');
|
||||
click('.password-reset form button');
|
||||
andThen(() => {
|
||||
ok(!exists(".password-reset form"), "form is gone");
|
||||
assert.ok(!exists(".password-reset form"), "form is gone");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -3,7 +3,7 @@ import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
|
|||
|
||||
const PREFIX = "javascripts/single-test/connectors";
|
||||
acceptance("Plugin Outlet - Connector Class", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
extraConnectorClass('user-profile-primary/hello', {
|
||||
actions: {
|
||||
sayHello() {
|
||||
|
@ -28,13 +28,13 @@ acceptance("Plugin Outlet - Connector Class", {
|
|||
);
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
|
||||
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
|
||||
}
|
||||
});
|
||||
|
||||
test("Renders a template into the outlet", assert => {
|
||||
QUnit.test("Renders a template into the outlet", assert => {
|
||||
visit("/u/eviltrout");
|
||||
andThen(() => {
|
||||
assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names');
|
||||
|
@ -44,4 +44,4 @@ test("Renders a template into the outlet", assert => {
|
|||
andThen(() => {
|
||||
assert.equal(find('.hello-result').text(), 'hello!', 'actions delegate properly');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,20 +5,20 @@ const HELLO = 'javascripts/multi-test/connectors/user-profile-primary/hello';
|
|||
const GOODBYE = 'javascripts/multi-test/connectors/user-profile-primary/goodbye';
|
||||
|
||||
acceptance("Plugin Outlet - Multi Template", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
clearCache();
|
||||
Ember.TEMPLATES[HELLO] = Ember.HTMLBars.compile(`<span class='hello-span'>Hello</span>`);
|
||||
Ember.TEMPLATES[GOODBYE] = Ember.HTMLBars.compile(`<span class='bye-span'>Goodbye</span>`);
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
delete Ember.TEMPLATES[HELLO];
|
||||
delete Ember.TEMPLATES[GOODBYE];
|
||||
clearCache();
|
||||
}
|
||||
});
|
||||
|
||||
test("Renders a template into the outlet", assert => {
|
||||
QUnit.test("Renders a template into the outlet", assert => {
|
||||
visit("/u/eviltrout");
|
||||
andThen(() => {
|
||||
assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names');
|
||||
|
@ -26,4 +26,4 @@ test("Renders a template into the outlet", assert => {
|
|||
assert.equal(find('.hello-span').text(), 'Hello', 'it renders into the outlet');
|
||||
assert.equal(find('.bye-span').text(), 'Goodbye', 'it renders into the outlet');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,21 +2,21 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
const CONNECTOR = 'javascripts/single-test/connectors/user-profile-primary/hello';
|
||||
acceptance("Plugin Outlet - Single Template", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile(
|
||||
`<span class='hello-username'>{{model.username}}</span>`
|
||||
);
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
delete Ember.TEMPLATES[CONNECTOR];
|
||||
}
|
||||
});
|
||||
|
||||
test("Renders a template into the outlet", assert => {
|
||||
QUnit.test("Renders a template into the outlet", assert => {
|
||||
visit("/u/eviltrout");
|
||||
andThen(() => {
|
||||
assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names');
|
||||
assert.equal(find('.hello-username').text(), 'eviltrout', 'it renders into the outlet');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,20 +1,20 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("User Preferences", { loggedIn: true });
|
||||
|
||||
test("update some fields", () => {
|
||||
QUnit.test("update some fields", assert => {
|
||||
visit("/u/eviltrout/preferences");
|
||||
|
||||
andThen(() => {
|
||||
ok($('body.user-preferences-page').length, "has the body class");
|
||||
equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab");
|
||||
ok(exists('.user-preferences'), 'it shows the preferences');
|
||||
assert.ok($('body.user-preferences-page').length, "has the body class");
|
||||
assert.equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab");
|
||||
assert.ok(exists('.user-preferences'), 'it shows the preferences');
|
||||
});
|
||||
|
||||
const savePreferences = () => {
|
||||
click('.save-user');
|
||||
ok(!exists('.saved-user'), "it hasn't been saved yet");
|
||||
assert.ok(!exists('.saved-user'), "it hasn't been saved yet");
|
||||
andThen(() => {
|
||||
ok(exists('.saved-user'), 'it displays the saved message');
|
||||
assert.ok(exists('.saved-user'), 'it displays the saved message');
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -37,39 +37,39 @@ test("update some fields", () => {
|
|||
fillIn('.category-controls .category-selector', 'faq');
|
||||
savePreferences();
|
||||
|
||||
ok(!exists('.preferences-nav .nav-tags a'), "tags tab isn't there when tags are disabled");
|
||||
assert.ok(!exists('.preferences-nav .nav-tags a'), "tags tab isn't there when tags are disabled");
|
||||
|
||||
// Error: Unhandled request in test environment: /themes/assets/10d71596-7e4e-4dc0-b368-faa3b6f1ce6d?_=1493833562388 (GET)
|
||||
// click(".preferences-nav .nav-interface a");
|
||||
// click('.control-group.other input[type=checkbox]:first');
|
||||
// savePreferences();
|
||||
|
||||
ok(!exists('.preferences-nav .nav-apps a'), "apps tab isn't there when you have no authorized apps");
|
||||
assert.ok(!exists('.preferences-nav .nav-apps a'), "apps tab isn't there when you have no authorized apps");
|
||||
});
|
||||
|
||||
test("username", () => {
|
||||
QUnit.test("username", assert => {
|
||||
visit("/u/eviltrout/preferences/username");
|
||||
andThen(() => {
|
||||
ok(exists("#change_username"), "it has the input element");
|
||||
assert.ok(exists("#change_username"), "it has the input element");
|
||||
});
|
||||
});
|
||||
|
||||
test("about me", () => {
|
||||
QUnit.test("about me", assert => {
|
||||
visit("/u/eviltrout/preferences/about-me");
|
||||
andThen(() => {
|
||||
ok(exists(".raw-bio"), "it has the input element");
|
||||
assert.ok(exists(".raw-bio"), "it has the input element");
|
||||
});
|
||||
});
|
||||
|
||||
test("email", () => {
|
||||
QUnit.test("email", assert => {
|
||||
visit("/u/eviltrout/preferences/email");
|
||||
andThen(() => {
|
||||
ok(exists("#change-email"), "it has the input element");
|
||||
assert.ok(exists("#change-email"), "it has the input element");
|
||||
});
|
||||
|
||||
fillIn("#change-email", 'invalidemail');
|
||||
|
||||
andThen(() => {
|
||||
equal(find('.tip.bad').text().trim(), I18n.t('user.email.invalid'), 'it should display invalid email tip');
|
||||
assert.equal(find('.tip.bad').text().trim(), I18n.t('user.email.invalid'), 'it should display invalid email tip');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,21 +2,21 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
const CONNECTOR = 'javascripts/raw-test/connectors/topic-list-before-status/lala';
|
||||
acceptance("Raw Plugin Outlet", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
Discourse.RAW_TEMPLATES[CONNECTOR] = Handlebars.compile(
|
||||
`<span class='topic-lala'>{{context.topic.id}}</span>`
|
||||
);
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
delete Discourse.RAW_TEMPLATES[CONNECTOR];
|
||||
}
|
||||
});
|
||||
|
||||
test("Renders the raw plugin outlet", assert => {
|
||||
QUnit.test("Renders the raw plugin outlet", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
assert.ok(find('.topic-lala').length > 0, 'it renders the outlet');
|
||||
assert.equal(find('.topic-lala:eq(0)').text(), '11557', 'it has the topic id');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import { acceptance, waitFor } from "helpers/qunit-helpers";
|
||||
acceptance("Search - Full Page", {
|
||||
settings: {tagging_enabled: true},
|
||||
setup() {
|
||||
beforeEach() {
|
||||
const response = (object) => {
|
||||
return [
|
||||
200,
|
||||
|
@ -39,12 +39,12 @@ acceptance("Search - Full Page", {
|
|||
}
|
||||
});
|
||||
|
||||
test("perform various searches", assert => {
|
||||
QUnit.test("perform various searches", assert => {
|
||||
visit("/search");
|
||||
|
||||
andThen(() => {
|
||||
ok($('body.search-page').length, "has body class");
|
||||
ok(exists('.search-container'), "has container class");
|
||||
assert.ok($('body.search-page').length, "has body class");
|
||||
assert.ok(exists('.search-container'), "has container class");
|
||||
assert.ok(find('input.search').length > 0);
|
||||
assert.ok(find('.fps-topic').length === 0);
|
||||
});
|
||||
|
@ -60,7 +60,7 @@ test("perform various searches", assert => {
|
|||
andThen(() => assert.ok(find('.fps-topic').length === 1, 'has one post'));
|
||||
});
|
||||
|
||||
test("open advanced search", assert => {
|
||||
QUnit.test("open advanced search", assert => {
|
||||
visit("/search");
|
||||
|
||||
andThen(() => assert.ok(exists('.search .search-advanced'), 'shows advanced search panel'));
|
||||
|
@ -95,7 +95,7 @@ test("open advanced search", assert => {
|
|||
// });
|
||||
// });
|
||||
|
||||
test("escape search term", (assert) => {
|
||||
QUnit.test("escape search term", (assert) => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', '@<script>prompt(1337)</script>gmail.com');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -105,7 +105,7 @@ test("escape search term", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update username through advanced search ui", assert => {
|
||||
QUnit.test("update username through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -114,7 +114,7 @@ test("update username through advanced search ui", assert => {
|
|||
keyEvent('.search-advanced-options .user-selector', 'keydown', 8);
|
||||
|
||||
andThen(() => {
|
||||
waitFor(() => {
|
||||
waitFor(assert, () => {
|
||||
assert.ok(visible('.search-advanced-options .autocomplete'), '"autocomplete" popup is visible');
|
||||
assert.ok(exists('.search-advanced-options .autocomplete ul li a span.username:contains("admin")'), '"autocomplete" popup has an entry for "admin"');
|
||||
|
||||
|
@ -128,7 +128,7 @@ test("update username through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update category through advanced search ui", assert => {
|
||||
QUnit.test("update category through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -209,7 +209,7 @@ test("update category through advanced search ui", assert => {
|
|||
// });
|
||||
// });
|
||||
|
||||
test("update in:likes filter through advanced search ui", assert => {
|
||||
QUnit.test("update in:likes filter through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -221,7 +221,7 @@ test("update in:likes filter through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update in:private filter through advanced search ui", assert => {
|
||||
QUnit.test("update in:private filter through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -233,7 +233,7 @@ test("update in:private filter through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update in:seen filter through advanced search ui", assert => {
|
||||
QUnit.test("update in:seen filter through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -248,7 +248,7 @@ test("update in:seen filter through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update in filter through advanced search ui", assert => {
|
||||
QUnit.test("update in filter through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -261,7 +261,7 @@ test("update in filter through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update status through advanced search ui", assert => {
|
||||
QUnit.test("update status through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -274,7 +274,7 @@ test("update status through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update post time through advanced search ui", assert => {
|
||||
QUnit.test("update post time through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -289,7 +289,7 @@ test("update post time through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("update min post count through advanced search ui", assert => {
|
||||
QUnit.test("update min post count through advanced search ui", assert => {
|
||||
visit("/search");
|
||||
fillIn('.search input.full-page-search', 'none');
|
||||
click('.search-advanced-btn');
|
||||
|
@ -301,7 +301,7 @@ test("update min post count through advanced search ui", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("validate advanced search when initially empty", assert => {
|
||||
QUnit.test("validate advanced search when initially empty", assert => {
|
||||
visit("/search?expanded=true");
|
||||
click('.search-advanced-options .in-likes');
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Search");
|
||||
|
||||
test("search", (assert) => {
|
||||
QUnit.test("search", (assert) => {
|
||||
visit("/");
|
||||
|
||||
click('#search-button');
|
||||
|
@ -25,29 +25,29 @@ test("search", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("search scope checkbox", () => {
|
||||
QUnit.test("search scope checkbox", assert => {
|
||||
visit("/c/bug");
|
||||
click('#search-button');
|
||||
andThen(() => {
|
||||
ok(exists('.search-context input:checked'), 'scope to category checkbox is checked');
|
||||
assert.ok(exists('.search-context input:checked'), 'scope to category checkbox is checked');
|
||||
});
|
||||
click('#search-button');
|
||||
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#search-button');
|
||||
andThen(() => {
|
||||
not(exists('.search-context input:checked'), 'scope to topic checkbox is not checked');
|
||||
assert.not(exists('.search-context input:checked'), 'scope to topic checkbox is not checked');
|
||||
});
|
||||
click('#search-button');
|
||||
|
||||
visit("/u/eviltrout");
|
||||
click('#search-button');
|
||||
andThen(() => {
|
||||
ok(exists('.search-context input:checked'), 'scope to user checkbox is checked');
|
||||
assert.ok(exists('.search-context input:checked'), 'scope to user checkbox is checked');
|
||||
});
|
||||
});
|
||||
|
||||
test("Search with context", assert => {
|
||||
QUnit.test("Search with context", assert => {
|
||||
visit("/t/internationalization-localization/280/1");
|
||||
|
||||
click('#search-button');
|
||||
|
@ -72,4 +72,4 @@ test("Search with context", assert => {
|
|||
andThen(() => {
|
||||
assert.ok(!$('.search-context input[type=checkbox]').is(":checked"));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,11 +1,11 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Signing In");
|
||||
|
||||
test("sign in", () => {
|
||||
QUnit.test("sign in", assert => {
|
||||
visit("/");
|
||||
click("header .login-button");
|
||||
andThen(() => {
|
||||
ok(exists('.login-modal'), "it shows the login modal");
|
||||
assert.ok(exists('.login-modal'), "it shows the login modal");
|
||||
});
|
||||
|
||||
// Test invalid password first
|
||||
|
@ -13,48 +13,48 @@ test("sign in", () => {
|
|||
fillIn('#login-account-password', 'incorrect');
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(() => {
|
||||
ok(exists('#modal-alert:visible'), 'it displays the login error');
|
||||
not(exists('.modal-footer .btn-primary:disabled'), "enables the login button");
|
||||
assert.ok(exists('#modal-alert:visible'), 'it displays the login error');
|
||||
assert.not(exists('.modal-footer .btn-primary:disabled'), "enables the login button");
|
||||
});
|
||||
|
||||
// Use the correct password
|
||||
fillIn('#login-account-password', 'correct');
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(() => {
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), "disables the login button");
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), "disables the login button");
|
||||
});
|
||||
});
|
||||
|
||||
test("sign in - not activated", () => {
|
||||
QUnit.test("sign in - not activated", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
click("header .login-button");
|
||||
andThen(() => {
|
||||
ok(exists('.login-modal'), "it shows the login modal");
|
||||
assert.ok(exists('.login-modal'), "it shows the login modal");
|
||||
});
|
||||
|
||||
fillIn('#login-account-name', 'eviltrout');
|
||||
fillIn('#login-account-password', 'not-activated');
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(() => {
|
||||
equal(find('.modal-body b').text(), '<small>eviltrout@example.com</small>');
|
||||
ok(!exists('.modal-body small'), 'it escapes the email address');
|
||||
assert.equal(find('.modal-body b').text(), '<small>eviltrout@example.com</small>');
|
||||
assert.ok(!exists('.modal-body small'), 'it escapes the email address');
|
||||
});
|
||||
|
||||
click('.modal-footer button.resend');
|
||||
andThen(() => {
|
||||
equal(find('.modal-body b').text(), '<small>current@example.com</small>');
|
||||
ok(!exists('.modal-body small'), 'it escapes the email address');
|
||||
assert.equal(find('.modal-body b').text(), '<small>current@example.com</small>');
|
||||
assert.ok(!exists('.modal-body small'), 'it escapes the email address');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("sign in - not activated - edit email", () => {
|
||||
QUnit.test("sign in - not activated - edit email", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
click("header .login-button");
|
||||
andThen(() => {
|
||||
ok(exists('.login-modal'), "it shows the login modal");
|
||||
assert.ok(exists('.login-modal'), "it shows the login modal");
|
||||
});
|
||||
|
||||
fillIn('#login-account-name', 'eviltrout');
|
||||
|
@ -62,27 +62,27 @@ test("sign in - not activated - edit email", () => {
|
|||
click('.modal-footer .btn-primary');
|
||||
click('.modal-footer button.edit-email');
|
||||
andThen(() => {
|
||||
equal(find('.activate-new-email').val(), 'current@example.com');
|
||||
equal(find('.modal-footer .btn-primary:disabled').length, 1, "must change email");
|
||||
assert.equal(find('.activate-new-email').val(), 'current@example.com');
|
||||
assert.equal(find('.modal-footer .btn-primary:disabled').length, 1, "must change email");
|
||||
});
|
||||
fillIn('.activate-new-email', 'different@example.com');
|
||||
andThen(() => {
|
||||
equal(find('.modal-footer .btn-primary:disabled').length, 0);
|
||||
assert.equal(find('.modal-footer .btn-primary:disabled').length, 0);
|
||||
});
|
||||
click(".modal-footer .btn-primary");
|
||||
andThen(() => {
|
||||
equal(find('.modal-body b').text(), 'different@example.com');
|
||||
assert.equal(find('.modal-body b').text(), 'different@example.com');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("create account", () => {
|
||||
QUnit.test("create account", assert => {
|
||||
visit("/");
|
||||
click("header .sign-up-button");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.create-account'), "it shows the create account modal");
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first');
|
||||
assert.ok(exists('.create-account'), "it shows the create account modal");
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first');
|
||||
});
|
||||
|
||||
fillIn('#new-account-name', 'Dr. Good Tuna');
|
||||
|
@ -92,18 +92,18 @@ test("create account", () => {
|
|||
fillIn('#new-account-email', 'good.tuna@test.com');
|
||||
fillIn('#new-account-username', 'taken');
|
||||
andThen(() => {
|
||||
ok(exists('#username-validation.bad'), 'the username validation is bad');
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled');
|
||||
assert.ok(exists('#username-validation.bad'), 'the username validation is bad');
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled');
|
||||
});
|
||||
|
||||
fillIn('#new-account-username', 'goodtuna');
|
||||
andThen(() => {
|
||||
ok(exists('#username-validation.good'), 'the username validation is good');
|
||||
not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled');
|
||||
assert.ok(exists('#username-validation.good'), 'the username validation is good');
|
||||
assert.not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled');
|
||||
});
|
||||
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(() => {
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), "create account is disabled");
|
||||
assert.ok(exists('.modal-footer .btn-primary:disabled'), "create account is disabled");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,33 +1,33 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Static");
|
||||
|
||||
test("Static Pages", () => {
|
||||
QUnit.test("Static Pages", assert => {
|
||||
visit("/faq");
|
||||
andThen(() => {
|
||||
ok($('body.static-faq').length, "has the body class");
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
assert.ok($('body.static-faq').length, "has the body class");
|
||||
assert.ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
|
||||
visit("/guidelines");
|
||||
andThen(() => {
|
||||
ok($('body.static-guidelines').length, "has the body class");
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
assert.ok($('body.static-guidelines').length, "has the body class");
|
||||
assert.ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
|
||||
visit("/tos");
|
||||
andThen(() => {
|
||||
ok($('body.static-tos').length, "has the body class");
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
assert.ok($('body.static-tos').length, "has the body class");
|
||||
assert.ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
|
||||
visit("/privacy");
|
||||
andThen(() => {
|
||||
ok($('body.static-privacy').length, "has the body class");
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
assert.ok($('body.static-privacy').length, "has the body class");
|
||||
assert.ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
|
||||
visit("/login");
|
||||
andThen(() => {
|
||||
equal(currentPath(), "discovery.latest", "it redirects them to latest unless `login_required`");
|
||||
assert.equal(currentPath(), "discovery.latest", "it redirects them to latest unless `login_required`");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -3,7 +3,7 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
acceptance("Tag Hashtag", {
|
||||
loggedIn: true,
|
||||
settings: { tagging_enabled: true },
|
||||
setup() {
|
||||
beforeEach() {
|
||||
const response = (object) => {
|
||||
return [
|
||||
200,
|
||||
|
@ -26,18 +26,18 @@ acceptance("Tag Hashtag", {
|
|||
}
|
||||
});
|
||||
|
||||
test("tag is cooked properly", () => {
|
||||
QUnit.test("tag is cooked properly", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-footer-buttons .btn.create');
|
||||
|
||||
fillIn('.d-editor-input', "this is a tag hashtag #monkey::tag");
|
||||
andThen(() => {
|
||||
// TODO: Test that the autocomplete shows
|
||||
equal(find('.d-editor-preview:visible').html().trim(), "<p>this is a tag hashtag <a href=\"/tags/monkey\" class=\"hashtag\">#<span>monkey</span></a></p>");
|
||||
assert.equal(find('.d-editor-preview:visible').html().trim(), "<p>this is a tag hashtag <a href=\"/tags/monkey\" class=\"hashtag\">#<span>monkey</span></a></p>");
|
||||
});
|
||||
|
||||
click('#reply-control .btn.create');
|
||||
andThen(() => {
|
||||
equal(find('.topic-post:last .cooked').html().trim(), "<p>this is a tag hashtag <a href=\"/tags/monkey\" class=\"hashtag\">#<span>monkey</span></a></p>");
|
||||
assert.equal(find('.topic-post:last .cooked').html().trim(), "<p>this is a tag hashtag <a href=\"/tags/monkey\" class=\"hashtag\">#<span>monkey</span></a></p>");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,11 +1,11 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Tags", { loggedIn: true });
|
||||
|
||||
test("list the tags", () => {
|
||||
QUnit.test("list the tags", assert => {
|
||||
visit("/tags");
|
||||
|
||||
andThen(() => {
|
||||
ok($('body.tags-page').length, "has the body class");
|
||||
ok(exists('.tag-eviltrout'), "shows the evil trout tag");
|
||||
assert.ok($('body.tags-page').length, "has the body class");
|
||||
assert.ok(exists('.tag-eviltrout'), "shows the evil trout tag");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,22 +1,22 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Topic - Anonymous");
|
||||
|
||||
test("Enter a Topic", () => {
|
||||
QUnit.test("Enter a Topic", assert => {
|
||||
visit("/t/internationalization-localization/280/1");
|
||||
andThen(() => {
|
||||
ok(exists("#topic"), "The topic was rendered");
|
||||
ok(exists("#topic .cooked"), "The topic has cooked posts");
|
||||
assert.ok(exists("#topic"), "The topic was rendered");
|
||||
assert.ok(exists("#topic .cooked"), "The topic has cooked posts");
|
||||
});
|
||||
});
|
||||
|
||||
test("Enter without an id", () => {
|
||||
QUnit.test("Enter without an id", assert => {
|
||||
visit("/t/internationalization-localization");
|
||||
andThen(() => {
|
||||
ok(exists("#topic"), "The topic was rendered");
|
||||
assert.ok(exists("#topic"), "The topic was rendered");
|
||||
});
|
||||
});
|
||||
|
||||
test("Enter a 404 topic", assert => {
|
||||
QUnit.test("Enter a 404 topic", assert => {
|
||||
visit("/t/not-found/404");
|
||||
andThen(() => {
|
||||
assert.ok(!exists("#topic"), "The topic was not rendered");
|
||||
|
@ -24,7 +24,7 @@ test("Enter a 404 topic", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Enter without access", assert => {
|
||||
QUnit.test("Enter without access", assert => {
|
||||
visit("/t/i-dont-have-access/403");
|
||||
andThen(() => {
|
||||
assert.ok(!exists("#topic"), "The topic was not rendered");
|
||||
|
@ -32,10 +32,10 @@ test("Enter without access", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
test("Enter with 500 errors", assert => {
|
||||
QUnit.test("Enter with 500 errors", assert => {
|
||||
visit("/t/throws-error/500");
|
||||
andThen(() => {
|
||||
assert.ok(!exists("#topic"), "The topic was not rendered");
|
||||
assert.ok(exists(".topic-error"), "An error message is displayed");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,46 +1,46 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Topic Discovery");
|
||||
|
||||
test("Visit Discovery Pages", () => {
|
||||
QUnit.test("Visit Discovery Pages", assert => {
|
||||
visit("/");
|
||||
andThen(() => {
|
||||
ok($('body.navigation-topics').length, "has the default navigation");
|
||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
assert.ok($('body.navigation-topics').length, "has the default navigation");
|
||||
assert.ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
assert.ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
});
|
||||
|
||||
visit("/c/bug");
|
||||
andThen(() => {
|
||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
ok(!exists('.category-list'), "doesn't render subcategories");
|
||||
ok($('body.category-bug').length, "has a custom css class for the category id on the body");
|
||||
assert.ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
assert.ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
assert.ok(!exists('.category-list'), "doesn't render subcategories");
|
||||
assert.ok($('body.category-bug').length, "has a custom css class for the category id on the body");
|
||||
});
|
||||
|
||||
visit("/categories");
|
||||
andThen(() => {
|
||||
ok($('body.navigation-categories').length, "has the body class");
|
||||
ok($('body.category-bug').length === 0, "removes the custom category class");
|
||||
ok(exists('.category'), "has a list of categories");
|
||||
ok($('body.categories-list').length, "has a custom class to indicate categories");
|
||||
assert.ok($('body.navigation-categories').length, "has the body class");
|
||||
assert.ok($('body.category-bug').length === 0, "removes the custom category class");
|
||||
assert.ok(exists('.category'), "has a list of categories");
|
||||
assert.ok($('body.categories-list').length, "has a custom class to indicate categories");
|
||||
});
|
||||
|
||||
visit("/top");
|
||||
andThen(() => {
|
||||
ok($('body.categories-list').length === 0, "removes the `categories-list` class");
|
||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
assert.ok($('body.categories-list').length === 0, "removes the `categories-list` class");
|
||||
assert.ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||
});
|
||||
|
||||
visit("/c/feature");
|
||||
andThen(() => {
|
||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
ok(exists(".category-boxes"), "The list of subcategories were rendered with box style");
|
||||
assert.ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
assert.ok(exists(".category-boxes"), "The list of subcategories were rendered with box style");
|
||||
});
|
||||
|
||||
visit("/c/dev");
|
||||
andThen(() => {
|
||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
ok(exists(".category-boxes-with-topics"), "The list of subcategories were rendered with box-with-featured-topics style");
|
||||
ok(exists(".category-boxes-with-topics .featured-topics"), "The featured topics are there too");
|
||||
assert.ok(exists(".topic-list"), "The list of topics was rendered");
|
||||
assert.ok(exists(".category-boxes-with-topics"), "The list of subcategories were rendered with box-with-featured-topics style");
|
||||
assert.ok(exists(".category-boxes-with-topics .featured-topics"), "The featured topics are there too");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Topic Notifications button", {
|
||||
loggedIn: true,
|
||||
setup() {
|
||||
beforeEach() {
|
||||
const response = object => {
|
||||
return [
|
||||
200,
|
||||
|
@ -16,13 +16,13 @@ acceptance("Topic Notifications button", {
|
|||
}
|
||||
});
|
||||
|
||||
test("Updating topic notification level", () => {
|
||||
QUnit.test("Updating topic notification level", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
|
||||
const notificationOptions = "#topic-footer-buttons .notification-options";
|
||||
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
exists(`${notificationOptions} .tracking`),
|
||||
"it should display the notification options button in the topic's footer"
|
||||
);
|
||||
|
@ -32,7 +32,7 @@ test("Updating topic notification level", () => {
|
|||
click(`${notificationOptions} .dropdown-menu .watching`);
|
||||
|
||||
andThen(() => {
|
||||
ok(
|
||||
assert.ok(
|
||||
exists(`${notificationOptions} .watching`),
|
||||
"it should display the right notification level"
|
||||
);
|
||||
|
@ -44,4 +44,4 @@ test("Updating topic notification level", () => {
|
|||
// 'it should display the right notification level in topic timeline'
|
||||
// );
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,20 +1,20 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Topic", { loggedIn: true });
|
||||
|
||||
test("Share Popup", () => {
|
||||
QUnit.test("Share Popup", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
andThen(() => {
|
||||
ok(!exists('#share-link.visible'), 'it is not visible');
|
||||
assert.ok(!exists('#share-link.visible'), 'it is not visible');
|
||||
});
|
||||
|
||||
click("button[data-share-url]");
|
||||
andThen(() => {
|
||||
ok(exists('#share-link.visible'), 'it shows the popup');
|
||||
assert.ok(exists('#share-link.visible'), 'it shows the popup');
|
||||
});
|
||||
|
||||
click('#share-link .close-share');
|
||||
andThen(() => {
|
||||
ok(!exists('#share-link.visible'), 'it closes the popup');
|
||||
assert.ok(!exists('#share-link.visible'), 'it closes the popup');
|
||||
});
|
||||
|
||||
// TODO tgxworld This fails on Travis but we need to push the security fix out
|
||||
|
@ -30,23 +30,23 @@ test("Share Popup", () => {
|
|||
// });
|
||||
});
|
||||
|
||||
test("Showing and hiding the edit controls", () => {
|
||||
QUnit.test("Showing and hiding the edit controls", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
|
||||
click('#topic-title .fa-pencil');
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('#edit-title'), 'it shows the editing controls');
|
||||
assert.ok(exists('#edit-title'), 'it shows the editing controls');
|
||||
});
|
||||
|
||||
fillIn('#edit-title', 'this is the new title');
|
||||
click('#topic-title .cancel-edit');
|
||||
andThen(() => {
|
||||
ok(!exists('#edit-title'), 'it hides the editing controls');
|
||||
assert.ok(!exists('#edit-title'), 'it hides the editing controls');
|
||||
});
|
||||
});
|
||||
|
||||
test("Updating the topic title and category", () => {
|
||||
QUnit.test("Updating the topic title and category", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-title .fa-pencil');
|
||||
|
||||
|
@ -56,12 +56,12 @@ test("Updating the topic title and category", () => {
|
|||
click('#topic-title .submit-edit');
|
||||
|
||||
andThen(() => {
|
||||
equal(find('#topic-title .badge-category').text(), 'faq', 'it displays the new category');
|
||||
equal(find('.fancy-title').text().trim(), 'this is the new title', 'it displays the new title');
|
||||
assert.equal(find('#topic-title .badge-category').text(), 'faq', 'it displays the new category');
|
||||
assert.equal(find('.fancy-title').text().trim(), 'this is the new title', 'it displays the new title');
|
||||
});
|
||||
});
|
||||
|
||||
test("Marking a topic as wiki", () => {
|
||||
QUnit.test("Marking a topic as wiki", assert => {
|
||||
server.put('/posts/398/wiki', () => { // eslint-disable-line no-undef
|
||||
return [
|
||||
200,
|
||||
|
@ -73,7 +73,7 @@ test("Marking a topic as wiki", () => {
|
|||
visit("/t/internationalization-localization/280");
|
||||
|
||||
andThen(() => {
|
||||
ok(find('a.wiki').length === 0, 'it does not show the wiki icon');
|
||||
assert.ok(find('a.wiki').length === 0, 'it does not show the wiki icon');
|
||||
});
|
||||
|
||||
click('.topic-post:eq(0) button.show-more-actions');
|
||||
|
@ -81,39 +81,39 @@ test("Marking a topic as wiki", () => {
|
|||
click('.btn.wiki');
|
||||
|
||||
andThen(() => {
|
||||
ok(find('a.wiki').length === 1, 'it shows the wiki icon');
|
||||
assert.ok(find('a.wiki').length === 1, 'it shows the wiki icon');
|
||||
});
|
||||
});
|
||||
|
||||
test("Reply as new topic", () => {
|
||||
QUnit.test("Reply as new topic", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click("button.share:eq(0)");
|
||||
click(".reply-as-new-topic a");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
find('.d-editor-input').val().trim(),
|
||||
`Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):`,
|
||||
"it fills composer with the ring string"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
find('.category-combobox').select2('data').text, "feature",
|
||||
"it fills category selector with the right category"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("Reply as new message", () => {
|
||||
QUnit.test("Reply as new message", assert => {
|
||||
visit("/t/pm-for-testing/12");
|
||||
click("button.share:eq(0)");
|
||||
click(".reply-as-new-topic a");
|
||||
|
||||
andThen(() => {
|
||||
ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
assert.ok(exists('.d-editor-input'), 'the composer input is visible');
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
find('.d-editor-input').val().trim(),
|
||||
`Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):`,
|
||||
"it fills composer with the ring string"
|
||||
|
@ -121,24 +121,24 @@ test("Reply as new message", () => {
|
|||
|
||||
const targets = find('.item span', '.composer-fields');
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
$(targets[0]).text(), "someguy",
|
||||
"it fills up the composer with the right user to start the PM to"
|
||||
);
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
$(targets[1]).text(), "test",
|
||||
"it fills up the composer with the right user to start the PM to"
|
||||
);
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
$(targets[2]).text(), "Group",
|
||||
"it fills up the composer with the right group to start the PM to"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("Updating the topic title with emojis", () => {
|
||||
QUnit.test("Updating the topic title with emojis", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-title .fa-pencil');
|
||||
|
||||
|
@ -147,6 +147,6 @@ test("Updating the topic title with emojis", () => {
|
|||
click('#topic-title .submit-edit');
|
||||
|
||||
andThen(() => {
|
||||
equal(find('.fancy-title').html().trim(), 'emojis title <img src=\"/images/emoji/emoji_one/bike.png?v=5\" title=\"bike\" alt=\"bike\" class=\"emoji\"> <img src=\"/images/emoji/emoji_one/blonde_woman/6.png?v=5\" title=\"blonde_woman:t6\" alt=\"blonde_woman:t6\" class=\"emoji\">', 'it displays the new title with emojis');
|
||||
assert.equal(find('.fancy-title').html().trim(), 'emojis title <img src=\"/images/emoji/emoji_one/bike.png?v=5\" title=\"bike\" alt=\"bike\" class=\"emoji\"> <img src=\"/images/emoji/emoji_one/blonde_woman/6.png?v=5\" title=\"blonde_woman:t6\" alt=\"blonde_woman:t6\" class=\"emoji\">', 'it displays the new title with emojis');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,10 +1,10 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("Unknown");
|
||||
|
||||
test("Unknown URL", () => {
|
||||
expect(1);
|
||||
QUnit.test("Unknown URL", assert => {
|
||||
assert.expect(1);
|
||||
visit("/url-that-doesn't-exist");
|
||||
andThen(() => {
|
||||
ok(exists(".page-not-found"), "The not found content is present");
|
||||
assert.ok(exists(".page-not-found"), "The not found content is present");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("User Anonymous");
|
||||
|
||||
export function hasStream() {
|
||||
function hasStream(assert) {
|
||||
andThen(() => {
|
||||
ok(exists('.user-main .about'), 'it has the about section');
|
||||
ok(count('.user-stream .item') > 0, 'it has stream items');
|
||||
assert.ok(exists('.user-main .about'), 'it has the about section');
|
||||
assert.ok(count('.user-stream .item') > 0, 'it has stream items');
|
||||
});
|
||||
}
|
||||
|
||||
function hasTopicList() {
|
||||
function hasTopicList(assert) {
|
||||
andThen(() => {
|
||||
equal(count('.user-stream .item'), 0, "has no stream displayed");
|
||||
ok(count('.topic-list tr') > 0, 'it has a topic list');
|
||||
assert.equal(count('.user-stream .item'), 0, "has no stream displayed");
|
||||
assert.ok(count('.topic-list tr') > 0, 'it has a topic list');
|
||||
});
|
||||
}
|
||||
|
||||
test("Root URL", () => {
|
||||
QUnit.test("Root URL", assert => {
|
||||
visit("/u/eviltrout");
|
||||
andThen(() => {
|
||||
ok($('body.user-summary-page').length, "has the body class");
|
||||
equal(currentPath(), 'user.summary', "it defaults to summary");
|
||||
assert.ok($('body.user-summary-page').length, "has the body class");
|
||||
assert.equal(currentPath(), 'user.summary', "it defaults to summary");
|
||||
});
|
||||
});
|
||||
|
||||
test("Filters", () => {
|
||||
QUnit.test("Filters", assert => {
|
||||
visit("/u/eviltrout/activity");
|
||||
andThen(() => {
|
||||
ok($('body.user-activity-page').length, "has the body class");
|
||||
assert.ok($('body.user-activity-page').length, "has the body class");
|
||||
});
|
||||
hasStream();
|
||||
hasStream(assert);
|
||||
|
||||
visit("/u/eviltrout/activity/topics");
|
||||
hasTopicList();
|
||||
hasTopicList(assert);
|
||||
|
||||
visit("/u/eviltrout/activity/replies");
|
||||
hasStream();
|
||||
hasStream(assert);
|
||||
});
|
||||
|
||||
test("Badges", () => {
|
||||
QUnit.test("Badges", assert => {
|
||||
visit("/u/eviltrout/badges");
|
||||
andThen(() => {
|
||||
ok($('body.user-badges-page').length, "has the body class");
|
||||
ok(exists(".user-badges-list .badge-card"), "shows a badge");
|
||||
assert.ok($('body.user-badges-page').length, "has the body class");
|
||||
assert.ok(exists(".user-badges-list .badge-card"), "shows a badge");
|
||||
});
|
||||
});
|
||||
|
||||
test("Restricted Routes", () => {
|
||||
QUnit.test("Restricted Routes", assert => {
|
||||
visit("/u/eviltrout/preferences");
|
||||
|
||||
andThen(() => {
|
||||
equal(currentURL(), '/u/eviltrout/activity', "it redirects from preferences");
|
||||
assert.equal(currentURL(), '/u/eviltrout/activity', "it redirects from preferences");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("User Card");
|
||||
|
||||
test("card", () => {
|
||||
QUnit.test("card", assert => {
|
||||
visit('/');
|
||||
|
||||
ok(invisible('#user-card'), 'user card is invisible by default');
|
||||
assert.ok(invisible('#user-card'), 'user card is invisible by default');
|
||||
click('a[data-user-card=eviltrout]:first');
|
||||
|
||||
andThen(() => {
|
||||
ok(visible('#user-card'), 'card should appear');
|
||||
assert.ok(visible('#user-card'), 'card should appear');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -2,32 +2,32 @@ import { acceptance } from "helpers/qunit-helpers";
|
|||
|
||||
acceptance("User", {loggedIn: true});
|
||||
|
||||
test("Invites", () => {
|
||||
QUnit.test("Invites", assert => {
|
||||
visit("/u/eviltrout/invited/pending");
|
||||
andThen(() => {
|
||||
ok($('body.user-invites-page').length, "has the body class");
|
||||
assert.ok($('body.user-invites-page').length, "has the body class");
|
||||
});
|
||||
});
|
||||
|
||||
test("Messages", () => {
|
||||
QUnit.test("Messages", assert => {
|
||||
visit("/u/eviltrout/messages");
|
||||
andThen(() => {
|
||||
ok($('body.user-messages-page').length, "has the body class");
|
||||
assert.ok($('body.user-messages-page').length, "has the body class");
|
||||
});
|
||||
});
|
||||
|
||||
test("Notifications", () => {
|
||||
QUnit.test("Notifications", assert => {
|
||||
visit("/u/eviltrout/notifications");
|
||||
andThen(() => {
|
||||
ok($('body.user-notifications-page').length, "has the body class");
|
||||
assert.ok($('body.user-notifications-page').length, "has the body class");
|
||||
});
|
||||
});
|
||||
|
||||
test("Root URL - Viewing Self", () => {
|
||||
QUnit.test("Root URL - Viewing Self", assert => {
|
||||
visit("/u/eviltrout");
|
||||
andThen(() => {
|
||||
ok($('body.user-activity-page').length, "has the body class");
|
||||
equal(currentPath(), 'user.userActivity.index', "it defaults to activity");
|
||||
ok(exists('.container.viewing-self'), "has the viewing-self class");
|
||||
assert.ok($('body.user-activity-page').length, "has the body class");
|
||||
assert.equal(currentPath(), 'user.userActivity.index', "it defaults to activity");
|
||||
assert.ok(exists('.container.viewing-self'), "has the viewing-self class");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,17 +1,17 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
acceptance("User Directory");
|
||||
|
||||
test("Visit Page", function() {
|
||||
QUnit.test("Visit Page", assert => {
|
||||
visit("/users");
|
||||
andThen(() => {
|
||||
ok($('body.users-page').length, "has the body class");
|
||||
ok(exists('.directory table tr'), "has a list of users");
|
||||
assert.ok($('body.users-page').length, "has the body class");
|
||||
assert.ok(exists('.directory table tr'), "has a list of users");
|
||||
});
|
||||
});
|
||||
|
||||
test("Visit All Time", function() {
|
||||
QUnit.test("Visit All Time", assert => {
|
||||
visit("/users?period=all");
|
||||
andThen(() => {
|
||||
ok(exists('.time-read'), "has time read column");
|
||||
assert.ok(exists('.time-read'), "has time read column");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,13 +2,13 @@ import { mapRoutes } from 'discourse/mapping-router';
|
|||
import Theme from 'admin/models/theme';
|
||||
|
||||
moduleFor('controller:admin-customize-themes', {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
needs: ['controller:adminUser']
|
||||
});
|
||||
|
||||
test("can list sorted themes", function() {
|
||||
QUnit.test("can list sorted themes", function(assert) {
|
||||
|
||||
const defaultTheme = Theme.create({id: 2, 'default': true, name: 'default'});
|
||||
const userTheme = Theme.create({id: 3, 'user_selectable': true, name: 'name'});
|
||||
|
@ -23,7 +23,7 @@ test("can list sorted themes", function() {
|
|||
});
|
||||
|
||||
|
||||
deepEqual(controller.get('sortedThemes').map(t=>t.get('name')), [
|
||||
assert.deepEqual(controller.get('sortedThemes').map(t=>t.get('name')), [
|
||||
defaultTheme,
|
||||
userTheme,
|
||||
strayTheme1,
|
||||
|
|
|
@ -2,13 +2,13 @@ import Badge from 'discourse/models/badge';
|
|||
import { mapRoutes } from 'discourse/mapping-router';
|
||||
|
||||
moduleFor('controller:admin-user-badges', {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
needs: ['controller:adminUser']
|
||||
});
|
||||
|
||||
test("grantableBadges", function() {
|
||||
QUnit.test("grantableBadges", function(assert) {
|
||||
const badgeFirst = Badge.create({id: 3, name: "A Badge", enabled: true});
|
||||
const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true});
|
||||
const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true});
|
||||
|
@ -20,6 +20,6 @@ test("grantableBadges", function() {
|
|||
});
|
||||
|
||||
|
||||
not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
|
||||
deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
||||
assert.not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
|
||||
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
||||
});
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
import ApiKey from 'admin/models/api-key';
|
||||
|
||||
module("model:admin-user");
|
||||
QUnit.module("model:admin-user");
|
||||
|
||||
test('generate key', function(assert) {
|
||||
QUnit.test('generate key', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var adminUser = AdminUser.create({id: 333});
|
||||
assert.ok(!adminUser.get('api_key'), 'it has no api key by default');
|
||||
return adminUser.generateApiKey().then(function() {
|
||||
present(adminUser.get('api_key'), 'it has an api_key now');
|
||||
assert.present(adminUser.get('api_key'), 'it has an api_key now');
|
||||
});
|
||||
});
|
||||
|
||||
test('revoke key', function(assert) {
|
||||
QUnit.test('revoke key', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
|
||||
|
@ -22,6 +21,6 @@ test('revoke key', function(assert) {
|
|||
|
||||
assert.equal(adminUser.get('api_key'), apiKey, 'it has the api key in the beginning');
|
||||
return adminUser.revokeApiKey().then(function() {
|
||||
blank(adminUser.get('api_key'), 'it cleared the api_key');
|
||||
assert.blank(adminUser.get('api_key'), 'it cleared the api_key');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,8 +1,8 @@
|
|||
import Theme from 'admin/models/theme';
|
||||
|
||||
module("model:theme");
|
||||
QUnit.module("model:theme");
|
||||
|
||||
test('can add an upload correctly', function(assert) {
|
||||
QUnit.test('can add an upload correctly', function(assert) {
|
||||
let theme = Theme.create();
|
||||
|
||||
assert.equal(theme.get("uploads.length"), 0, "uploads should be an empty array");
|
||||
|
@ -14,4 +14,4 @@ test('can add an upload correctly', function(assert) {
|
|||
assert.equal(fields[0].type_id, 2, 'expecting type id to be set');
|
||||
|
||||
assert.equal(theme.get("uploads.length"), 1, "expecting an upload");
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@ moduleForComponent('ace-editor', {integration: true});
|
|||
componentTest('css editor', {
|
||||
template: '{{ace-editor mode="css"}}',
|
||||
test(assert) {
|
||||
expect(1);
|
||||
assert.expect(1);
|
||||
assert.ok(this.$('.ace_editor').length, 'it renders the ace editor');
|
||||
}
|
||||
});
|
||||
|
@ -13,7 +13,7 @@ componentTest('css editor', {
|
|||
componentTest('html editor', {
|
||||
template: '{{ace-editor mode="html" content="<b>wat</b>"}}',
|
||||
test(assert) {
|
||||
expect(1);
|
||||
assert.expect(1);
|
||||
assert.ok(this.$('.ace_editor').length, 'it renders the ace editor');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ moduleForComponent('combo-box', {integration: true});
|
|||
|
||||
componentTest('with objects', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('items', [{id: 1, name: 'hello'}, {id: 2, name: 'world'}]);
|
||||
},
|
||||
|
||||
|
@ -17,7 +17,7 @@ componentTest('with objects', {
|
|||
|
||||
componentTest('with objects and valueAttribute', {
|
||||
template: '{{combo-box content=items valueAttribute="value"}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('items', [{value: 0, name: 'hello'}, {value: 1, name: 'world'}]);
|
||||
},
|
||||
|
||||
|
@ -30,7 +30,7 @@ componentTest('with objects and valueAttribute', {
|
|||
|
||||
componentTest('with an array', {
|
||||
template: '{{combo-box content=items value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
},
|
||||
|
||||
|
@ -44,7 +44,7 @@ componentTest('with an array', {
|
|||
|
||||
componentTest('with none', {
|
||||
template: '{{combo-box content=items none="test.none" value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = {none: 'none'};
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
},
|
||||
|
@ -59,7 +59,7 @@ componentTest('with none', {
|
|||
|
||||
componentTest('with Object none', {
|
||||
template: '{{combo-box content=items none=none value=value selected="something"}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('none', { id: 'something', name: 'none' });
|
||||
this.set('items', ['evil', 'trout', 'hat']);
|
||||
},
|
||||
|
|
|
@ -31,7 +31,7 @@ componentTest('preview sanitizes HTML', {
|
|||
componentTest('updating the value refreshes the preview', {
|
||||
template: '{{d-editor value=value}}',
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('value', 'evil trout');
|
||||
},
|
||||
|
||||
|
@ -52,7 +52,7 @@ function jumpEnd(textarea) {
|
|||
function testCase(title, testFunc) {
|
||||
componentTest(title, {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('value', 'hello world.');
|
||||
},
|
||||
test(assert) {
|
||||
|
@ -65,7 +65,7 @@ function testCase(title, testFunc) {
|
|||
function composerTestCase(title, testFunc) {
|
||||
componentTest(title, {
|
||||
template: '{{d-editor value=value composerEvents=true}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('value', 'hello world.');
|
||||
},
|
||||
test(assert) {
|
||||
|
@ -269,7 +269,7 @@ testCase('link modal (link with description)', function(assert) {
|
|||
|
||||
componentTest('advanced code', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.siteSettings.code_formatting_style = '4-spaces-indent';
|
||||
this.set('value',
|
||||
`
|
||||
|
@ -304,7 +304,7 @@ function xyz(x, y, z) {
|
|||
|
||||
componentTest('code button', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.siteSettings.code_formatting_style = '4-spaces-indent';
|
||||
},
|
||||
|
||||
|
@ -406,7 +406,7 @@ third line`
|
|||
|
||||
componentTest('code fences', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('value', '');
|
||||
},
|
||||
|
||||
|
@ -740,7 +740,7 @@ testCase(`doesn't jump to bottom with long text`, function(assert, textarea) {
|
|||
|
||||
componentTest('emoji', {
|
||||
template: '{{d-editor value=value}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
// Test adding a custom button
|
||||
withPluginApi('0.1', api => {
|
||||
api.onToolbarCreate(toolbar => {
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
moduleFor('component:group-membership-button');
|
||||
|
||||
test('canJoinGroup', function() {
|
||||
QUnit.test('canJoinGroup', function(assert) {
|
||||
this.subject().setProperties({
|
||||
model: { public: false }
|
||||
});
|
||||
|
||||
equal(this.subject().get("canJoinGroup"), false, "non public group cannot be joined");
|
||||
assert.equal(this.subject().get("canJoinGroup"), false, "non public group cannot be joined");
|
||||
|
||||
this.subject().set("model.public", true);
|
||||
|
||||
equal(this.subject().get("canJoinGroup"), true, "public group can be joined");
|
||||
assert.equal(this.subject().get("canJoinGroup"), true, "public group can be joined");
|
||||
|
||||
this.subject().setProperties({ currentUser: null, model: { public: true } });
|
||||
|
||||
equal(this.subject().get("canJoinGroup"), true, "can't join group when not logged in");
|
||||
assert.equal(this.subject().get("canJoinGroup"), true, "can't join group when not logged in");
|
||||
});
|
||||
|
||||
test('userIsGroupUser', function() {
|
||||
QUnit.test('userIsGroupUser', function(assert) {
|
||||
this.subject().setProperties({
|
||||
model: { is_group_user: true }
|
||||
});
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), true);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), true);
|
||||
|
||||
this.subject().set('model.is_group_user', false);
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), false);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), false);
|
||||
|
||||
this.subject().setProperties({ model: { id: 1 }, groupUserIds: [1] });
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), true);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), true);
|
||||
|
||||
this.subject().set('groupUserIds', [3]);
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), false);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), false);
|
||||
|
||||
this.subject().set('groupUserIds', undefined);
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), false);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), false);
|
||||
|
||||
this.subject().setProperties({
|
||||
groupUserIds: [1, 3],
|
||||
model: { id: 1, is_group_user: false }
|
||||
});
|
||||
|
||||
equal(this.subject().get('userIsGroupUser'), false);
|
||||
assert.equal(this.subject().get('userIsGroupUser'), false);
|
||||
});
|
||||
|
|
|
@ -3,8 +3,8 @@ import DiscourseURL from 'discourse/lib/url';
|
|||
var testMouseTrap;
|
||||
import KeyboardShortcuts from 'discourse/lib/keyboard-shortcuts';
|
||||
|
||||
module("lib:keyboard-shortcuts", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:keyboard-shortcuts", {
|
||||
beforeEach() {
|
||||
var _bindings = {};
|
||||
|
||||
testMouseTrap = {
|
||||
|
@ -62,7 +62,7 @@ module("lib:keyboard-shortcuts", {
|
|||
].join("\n"));
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
$("#qunit-scratch").html("");
|
||||
}
|
||||
});
|
||||
|
@ -72,11 +72,11 @@ var pathBindings = KeyboardShortcuts.PATH_BINDINGS;
|
|||
_.each(pathBindings, function(path, binding) {
|
||||
var testName = binding + " goes to " + path;
|
||||
|
||||
test(testName, function() {
|
||||
test(testName, function(assert) {
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
testMouseTrap.trigger(binding);
|
||||
|
||||
ok(DiscourseURL.routeTo.calledWith(path));
|
||||
assert.ok(DiscourseURL.routeTo.calledWith(path));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -87,10 +87,10 @@ _.each(clickBindings, function(selector, binding) {
|
|||
|
||||
var testName = binding + " clicks on " + selector;
|
||||
|
||||
test(testName, function() {
|
||||
test(testName, function(assert) {
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
$(selector).on("click", function() {
|
||||
ok(true, selector + " was clicked");
|
||||
assert.ok(true, selector + " was clicked");
|
||||
});
|
||||
|
||||
_.each(bindings, function(b) {
|
||||
|
@ -104,9 +104,9 @@ var functionBindings = KeyboardShortcuts.FUNCTION_BINDINGS;
|
|||
_.each(functionBindings, function(func, binding) {
|
||||
var testName = binding + " calls " + func;
|
||||
|
||||
test(testName, function() {
|
||||
test(testName, function(assert) {
|
||||
sandbox.stub(KeyboardShortcuts, func, function() {
|
||||
ok(true, func + " is called when " + binding + " is triggered");
|
||||
assert.ok(true, func + " is called when " + binding + " is triggered");
|
||||
});
|
||||
KeyboardShortcuts.bindEvents(testMouseTrap);
|
||||
|
||||
|
@ -114,40 +114,40 @@ _.each(functionBindings, function(func, binding) {
|
|||
});
|
||||
});
|
||||
|
||||
test("selectDown calls _moveSelection with 1", function() {
|
||||
QUnit.test("selectDown calls _moveSelection with 1", assert => {
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection');
|
||||
|
||||
KeyboardShortcuts.selectDown();
|
||||
ok(spy.calledWith(1), "_moveSelection is called with 1");
|
||||
assert.ok(spy.calledWith(1), "_moveSelection is called with 1");
|
||||
});
|
||||
|
||||
test("selectUp calls _moveSelection with -1", function() {
|
||||
QUnit.test("selectUp calls _moveSelection with -1", assert => {
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection');
|
||||
|
||||
KeyboardShortcuts.selectUp();
|
||||
ok(spy.calledWith(-1), "_moveSelection is called with -1");
|
||||
assert.ok(spy.calledWith(-1), "_moveSelection is called with -1");
|
||||
});
|
||||
|
||||
test("goBack calls history.back", function() {
|
||||
QUnit.test("goBack calls history.back", assert => {
|
||||
var called = false;
|
||||
sandbox.stub(history, 'back', function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
KeyboardShortcuts.goBack();
|
||||
ok(called, "history.back is called");
|
||||
assert.ok(called, "history.back is called");
|
||||
});
|
||||
|
||||
test("nextSection calls _changeSection with 1", function() {
|
||||
QUnit.test("nextSection calls _changeSection with 1", assert => {
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_changeSection');
|
||||
|
||||
KeyboardShortcuts.nextSection();
|
||||
ok(spy.calledWith(1), "_changeSection is called with 1");
|
||||
assert.ok(spy.calledWith(1), "_changeSection is called with 1");
|
||||
});
|
||||
|
||||
test("prevSection calls _changeSection with -1", function() {
|
||||
QUnit.test("prevSection calls _changeSection with -1", assert => {
|
||||
var spy = sandbox.spy(KeyboardShortcuts, '_changeSection');
|
||||
|
||||
KeyboardShortcuts.prevSection();
|
||||
ok(spy.calledWith(-1), "_changeSection is called with -1");
|
||||
assert.ok(spy.calledWith(-1), "_changeSection is called with -1");
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ componentTest("renders correctly with no properties set", {
|
|||
componentTest("support a placeholder", {
|
||||
template: `{{text-field placeholderKey="placeholder.i18n.key"}}`,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
sandbox.stub(I18n, "t").returnsArg(0);
|
||||
},
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ componentTest('functionality', {
|
|||
|
||||
componentTest('with string delimited values', {
|
||||
template: '{{value-list values=valueString}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('valueString', "hello\nworld");
|
||||
},
|
||||
|
||||
|
@ -49,7 +49,7 @@ componentTest('with string delimited values', {
|
|||
|
||||
componentTest('with array values', {
|
||||
template: '{{value-list values=valueArray inputType="array"}}',
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.set('valueArray', ['abc', 'def']);
|
||||
},
|
||||
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
moduleFor("controller:admin-group");
|
||||
moduleFor("controller:admin-group", {
|
||||
needs: ['controller:adminGroupsType']
|
||||
});
|
||||
|
||||
test("disablePublicSetting", function() {
|
||||
QUnit.test("disablePublicSetting", function(assert) {
|
||||
this.subject().setProperties({
|
||||
model: { visible: false, allow_membership_requests: false }
|
||||
});
|
||||
|
||||
equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
|
||||
assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
|
||||
|
||||
this.subject().set("model.visible", true);
|
||||
|
||||
equal(this.subject().get("disablePublicSetting"), false, "it should enable setting");
|
||||
assert.equal(this.subject().get("disablePublicSetting"), false, "it should enable setting");
|
||||
|
||||
this.subject().set("model.allow_membership_requests", true);
|
||||
|
||||
equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
|
||||
assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting");
|
||||
});
|
||||
|
||||
test("disableMembershipRequestSetting", function() {
|
||||
QUnit.test("disableMembershipRequestSetting", function(assert) {
|
||||
this.subject().setProperties({
|
||||
model: { visible: false, public: false, canEveryoneMention: true }
|
||||
});
|
||||
|
||||
equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting");
|
||||
assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting");
|
||||
|
||||
this.subject().set("model.visible", true);
|
||||
|
||||
equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting");
|
||||
assert.equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting");
|
||||
|
||||
this.subject().set("model.public", true);
|
||||
|
||||
equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting");
|
||||
assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting");
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { mapRoutes } from 'discourse/mapping-router';
|
||||
|
||||
moduleFor("controller:avatar-selector", "controller:avatar-selector", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
needs: ['controller:modal']
|
||||
});
|
||||
|
||||
test("avatarTemplate", function() {
|
||||
QUnit.test("avatarTemplate", function(assert) {
|
||||
const avatarSelectorController = this.subject();
|
||||
|
||||
avatarSelectorController.setProperties({
|
||||
|
@ -17,11 +17,11 @@ test("avatarTemplate", function() {
|
|||
custom_avatar_upload_id: 3
|
||||
});
|
||||
|
||||
equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default");
|
||||
assert.equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default");
|
||||
|
||||
avatarSelectorController.set('selected', 'gravatar');
|
||||
equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set");
|
||||
assert.equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set");
|
||||
|
||||
avatarSelectorController.set("selected", "custom");
|
||||
equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set");
|
||||
assert.equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set");
|
||||
});
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import { mapRoutes } from 'discourse/mapping-router';
|
||||
|
||||
moduleFor("controller:create-account", "controller:create-account", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
needs: ['controller:modal', 'controller:login']
|
||||
});
|
||||
|
||||
test('basicUsernameValidation', function() {
|
||||
QUnit.test('basicUsernameValidation', function(assert) {
|
||||
var subject = this.subject;
|
||||
|
||||
var testInvalidUsername = function(username, expectedReason) {
|
||||
var controller = subject({ siteSettings: Discourse.SiteSettings });
|
||||
controller.set('accountUsername', username);
|
||||
equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username);
|
||||
equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason);
|
||||
assert.equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username);
|
||||
assert.equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason);
|
||||
};
|
||||
|
||||
testInvalidUsername('', undefined);
|
||||
|
@ -24,11 +24,11 @@ test('basicUsernameValidation', function() {
|
|||
var controller = subject({ siteSettings: Discourse.SiteSettings });
|
||||
controller.set('accountUsername', 'porkchops');
|
||||
controller.set('prefilledUsername', 'porkchops');
|
||||
equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid');
|
||||
equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid');
|
||||
assert.equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid');
|
||||
assert.equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid');
|
||||
});
|
||||
|
||||
test('passwordValidation', function() {
|
||||
QUnit.test('passwordValidation', function(assert) {
|
||||
var subject = this.subject;
|
||||
|
||||
var controller = subject({ siteSettings: Discourse.SiteSettings });
|
||||
|
@ -38,14 +38,14 @@ test('passwordValidation', function() {
|
|||
controller.set('prefilledUsername', 'porkchops');
|
||||
|
||||
controller.set('accountPassword', 'b4fcdae11f9167');
|
||||
equal(controller.get('passwordValidation.ok'), true, 'Password is ok');
|
||||
equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid');
|
||||
assert.equal(controller.get('passwordValidation.ok'), true, 'Password is ok');
|
||||
assert.equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid');
|
||||
|
||||
var testInvalidPassword = function(password, expectedReason) {
|
||||
var c = subject({ siteSettings: Discourse.SiteSettings });
|
||||
c.set('accountPassword', password);
|
||||
equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password);
|
||||
equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason);
|
||||
assert.equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password);
|
||||
assert.equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason);
|
||||
};
|
||||
|
||||
testInvalidPassword('', undefined);
|
||||
|
|
|
@ -18,13 +18,13 @@ var buildAdminUser = function(args) {
|
|||
};
|
||||
|
||||
moduleFor("controller:flag", "controller:flag", {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
needs: ['controller:modal']
|
||||
});
|
||||
|
||||
test("canDeleteSpammer not staff", function(){
|
||||
QUnit.test("canDeleteSpammer not staff", function(assert) {
|
||||
const store = createStore();
|
||||
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
|
@ -32,44 +32,44 @@ test("canDeleteSpammer not staff", function(){
|
|||
|
||||
const spamFlag = store.createRecord('post-action-type', {name_key: 'spam'});
|
||||
flagController.set('selected', spamFlag);
|
||||
equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
|
||||
assert.equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
|
||||
});
|
||||
|
||||
var canDeleteSpammer = function(flagController, postActionType, expected, testName) {
|
||||
var canDeleteSpammer = function(assert, flagController, postActionType, expected, testName) {
|
||||
const store = createStore();
|
||||
const flag = store.createRecord('post-action-type', {name_key: postActionType});
|
||||
flagController.set('selected', flag);
|
||||
|
||||
equal(flagController.get('canDeleteSpammer'), expected, testName);
|
||||
assert.equal(flagController.get('canDeleteSpammer'), expected, testName);
|
||||
};
|
||||
|
||||
test("canDeleteSpammer spam not selected", function(){
|
||||
QUnit.test("canDeleteSpammer spam not selected", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
|
||||
canDeleteSpammer(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
||||
canDeleteSpammer(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
||||
canDeleteSpammer(flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user');
|
||||
canDeleteSpammer(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
||||
canDeleteSpammer(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
||||
canDeleteSpammer(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
||||
canDeleteSpammer(assert, flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user');
|
||||
canDeleteSpammer(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
||||
});
|
||||
|
||||
test("canDeleteSpammer spam selected", function(){
|
||||
QUnit.test("canDeleteSpammer spam selected", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
|
||||
canDeleteSpammer(flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');
|
||||
canDeleteSpammer(assert, flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');
|
||||
|
||||
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: true}));
|
||||
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted');
|
||||
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted');
|
||||
|
||||
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: false}));
|
||||
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
||||
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
||||
|
||||
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: false}));
|
||||
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
||||
canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
||||
});
|
||||
|
||||
test("canSendWarning not staff", function(){
|
||||
QUnit.test("canSendWarning not staff", function(assert) {
|
||||
const store = createStore();
|
||||
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
|
@ -77,28 +77,28 @@ test("canSendWarning not staff", function(){
|
|||
|
||||
const notifyUserFlag = store.createRecord('post-action-type', {name_key: 'notify_user'});
|
||||
flagController.set('selected', notifyUserFlag);
|
||||
equal(flagController.get('canSendWarning'), false, 'false if current user is not staff');
|
||||
assert.equal(flagController.get('canSendWarning'), false, 'false if current user is not staff');
|
||||
});
|
||||
|
||||
var canSendWarning = function(flagController, postActionType, expected, testName) {
|
||||
var canSendWarning = function(assert, flagController, postActionType, expected, testName) {
|
||||
const store = createStore();
|
||||
const flag = store.createRecord('post-action-type', {name_key: postActionType});
|
||||
flagController.set('selected', flag);
|
||||
|
||||
equal(flagController.get('canSendWarning'), expected, testName);
|
||||
assert.equal(flagController.get('canSendWarning'), expected, testName);
|
||||
};
|
||||
|
||||
test("canSendWarning notify_user not selected", function(){
|
||||
QUnit.test("canSendWarning notify_user not selected", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
canSendWarning(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
||||
canSendWarning(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
||||
canSendWarning(flagController, 'spam', false, 'false if current user is staff, but selected is spam');
|
||||
canSendWarning(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
||||
canSendWarning(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
||||
canSendWarning(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
||||
canSendWarning(assert, flagController, 'spam', false, 'false if current user is staff, but selected is spam');
|
||||
canSendWarning(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
||||
});
|
||||
|
||||
test("canSendWarning notify_user selected", function(){
|
||||
QUnit.test("canSendWarning notify_user selected", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
||||
var flagController = this.subject({ model: buildPost() });
|
||||
canSendWarning(flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user');
|
||||
canSendWarning(assert, flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user');
|
||||
});
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
moduleFor("controller:group");
|
||||
moduleFor("controller:group", {
|
||||
needs: ['controller:application']
|
||||
});
|
||||
|
||||
test("canEditGroup", function() {
|
||||
QUnit.test("canEditGroup", function(assert) {
|
||||
const GroupController = this.subject();
|
||||
|
||||
GroupController.setProperties({
|
||||
model: { is_group_owner: true, automatic: true }
|
||||
});
|
||||
|
||||
equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited");
|
||||
assert.equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited");
|
||||
|
||||
GroupController.set("model.automatic", false);
|
||||
|
||||
equal(GroupController.get("canEditGroup"), true, "owners can edit groups");
|
||||
assert.equal(GroupController.get("canEditGroup"), true, "owners can edit groups");
|
||||
|
||||
GroupController.set("model.is_group_owner", false);
|
||||
|
||||
equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups");
|
||||
assert.equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups");
|
||||
});
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
moduleFor("controller:history");
|
||||
|
||||
test("displayEdit", function() {
|
||||
QUnit.test("displayEdit", function(assert) {
|
||||
const HistoryController = this.subject();
|
||||
|
||||
HistoryController.setProperties({
|
||||
model: { last_revision: 3, current_revision: 3, can_edit: false }
|
||||
});
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
HistoryController.get("displayEdit"), false,
|
||||
"it should not display edit button when user cannot edit the post"
|
||||
);
|
||||
|
||||
HistoryController.set("model.can_edit", true);
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
HistoryController.get("displayEdit"), true,
|
||||
"it should display edit button when user can edit the post"
|
||||
);
|
||||
|
||||
HistoryController.set("model.current_revision", 2);
|
||||
|
||||
equal(
|
||||
assert.equal(
|
||||
HistoryController.get("displayEdit"), false,
|
||||
"it should only display the edit button on the latest revision"
|
||||
);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
import { mapRoutes } from 'discourse/mapping-router';
|
||||
|
||||
moduleFor('controller:topic', 'controller:topic', {
|
||||
needs: ['controller:modal', 'controller:composer', 'controller:application'],
|
||||
setup() {
|
||||
beforeEach() {
|
||||
this.registry.register('router:main', mapRoutes());
|
||||
},
|
||||
});
|
||||
|
@ -23,27 +22,27 @@ var buildTopic = function() {
|
|||
};
|
||||
|
||||
|
||||
test("editingMode", function() {
|
||||
QUnit.test("editingMode", function(assert) {
|
||||
var topic = buildTopic(),
|
||||
topicController = this.subject({model: topic});
|
||||
|
||||
ok(!topicController.get('editingTopic'), "we are not editing by default");
|
||||
assert.ok(!topicController.get('editingTopic'), "we are not editing by default");
|
||||
|
||||
topicController.set('model.details.can_edit', false);
|
||||
topicController.send('editTopic');
|
||||
ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit");
|
||||
assert.ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit");
|
||||
|
||||
topicController.set('model.details.can_edit', true);
|
||||
topicController.send('editTopic');
|
||||
ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit");
|
||||
equal(topicController.get('buffered.title'), topic.get('title'));
|
||||
equal(topicController.get('buffered.category_id'), topic.get('category_id'));
|
||||
assert.ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit");
|
||||
assert.equal(topicController.get('buffered.title'), topic.get('title'));
|
||||
assert.equal(topicController.get('buffered.category_id'), topic.get('category_id'));
|
||||
|
||||
topicController.send('cancelEditingTopic');
|
||||
ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value");
|
||||
assert.ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value");
|
||||
});
|
||||
|
||||
test("toggledSelectedPost", function() {
|
||||
QUnit.test("toggledSelectedPost", function(assert) {
|
||||
var tc = this.subject({ model: buildTopic() }),
|
||||
post = Discourse.Post.create({id: 123, post_number: 2}),
|
||||
postStream = tc.get('model.postStream');
|
||||
|
@ -51,38 +50,38 @@ test("toggledSelectedPost", function() {
|
|||
postStream.appendPost(post);
|
||||
postStream.appendPost(Discourse.Post.create({id: 124, post_number: 3}));
|
||||
|
||||
blank(tc.get('selectedPosts'), "there are no selected posts by default");
|
||||
equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0");
|
||||
ok(!tc.postSelected(post), "the post is not selected by default");
|
||||
assert.blank(tc.get('selectedPosts'), "there are no selected posts by default");
|
||||
assert.equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0");
|
||||
assert.ok(!tc.postSelected(post), "the post is not selected by default");
|
||||
|
||||
tc.send('toggledSelectedPost', post);
|
||||
present(tc.get('selectedPosts'), "there is a selectedPosts collection");
|
||||
equal(tc.get('selectedPostsCount'), 1, "there is a selected post now");
|
||||
ok(tc.postSelected(post), "the post is now selected");
|
||||
assert.present(tc.get('selectedPosts'), "there is a selectedPosts collection");
|
||||
assert.equal(tc.get('selectedPostsCount'), 1, "there is a selected post now");
|
||||
assert.ok(tc.postSelected(post), "the post is now selected");
|
||||
|
||||
tc.send('toggledSelectedPost', post);
|
||||
ok(!tc.postSelected(post), "the post is no longer selected");
|
||||
assert.ok(!tc.postSelected(post), "the post is no longer selected");
|
||||
|
||||
});
|
||||
|
||||
test("selectAll", function() {
|
||||
QUnit.test("selectAll", function(assert) {
|
||||
var tc = this.subject({model: buildTopic(), appEvents: AppEvents.create()}),
|
||||
post = Discourse.Post.create({id: 123, post_number: 2}),
|
||||
postStream = tc.get('model.postStream');
|
||||
|
||||
postStream.appendPost(post);
|
||||
|
||||
ok(!tc.postSelected(post), "the post is not selected by default");
|
||||
assert.ok(!tc.postSelected(post), "the post is not selected by default");
|
||||
tc.send('selectAll');
|
||||
ok(tc.postSelected(post), "the post is now selected");
|
||||
ok(tc.get('allPostsSelected'), "all posts are selected");
|
||||
assert.ok(tc.postSelected(post), "the post is now selected");
|
||||
assert.ok(tc.get('allPostsSelected'), "all posts are selected");
|
||||
tc.send('deselectAll');
|
||||
ok(!tc.postSelected(post), "the post is deselected again");
|
||||
ok(!tc.get('allPostsSelected'), "all posts are not selected");
|
||||
assert.ok(!tc.postSelected(post), "the post is deselected again");
|
||||
assert.ok(!tc.get('allPostsSelected'), "all posts are not selected");
|
||||
|
||||
});
|
||||
|
||||
test("Automating setting of allPostsSelected", function() {
|
||||
QUnit.test("Automating setting of allPostsSelected", function(assert) {
|
||||
var topic = buildTopic(),
|
||||
tc = this.subject({model: topic}),
|
||||
post = Discourse.Post.create({id: 123, post_number: 2}),
|
||||
|
@ -90,39 +89,38 @@ test("Automating setting of allPostsSelected", function() {
|
|||
|
||||
topic.set('posts_count', 1);
|
||||
postStream.appendPost(post);
|
||||
ok(!tc.get('allPostsSelected'), "all posts are not selected by default");
|
||||
assert.ok(!tc.get('allPostsSelected'), "all posts are not selected by default");
|
||||
|
||||
tc.send('toggledSelectedPost', post);
|
||||
ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post");
|
||||
assert.ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post");
|
||||
|
||||
tc.send('toggledSelectedPost', post);
|
||||
ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected");
|
||||
assert.ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected");
|
||||
});
|
||||
|
||||
test("Select Replies when present", function() {
|
||||
QUnit.test("Select Replies when present", function(assert) {
|
||||
var topic = buildTopic(),
|
||||
tc = this.subject({ model: topic, appEvents: AppEvents.create() }),
|
||||
p1 = Discourse.Post.create({id: 1, post_number: 1, reply_count: 1}),
|
||||
p2 = Discourse.Post.create({id: 2, post_number: 2}),
|
||||
p3 = Discourse.Post.create({id: 2, post_number: 3, reply_to_post_number: 1});
|
||||
|
||||
ok(!tc.postSelected(p3), "replies are not selected by default");
|
||||
assert.ok(!tc.postSelected(p3), "replies are not selected by default");
|
||||
tc.send('toggledSelectedPostReplies', p1);
|
||||
ok(tc.postSelected(p1), "it selects the post");
|
||||
ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply");
|
||||
ok(tc.postSelected(p3), "it selects a post that is a reply");
|
||||
equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two");
|
||||
assert.ok(tc.postSelected(p1), "it selects the post");
|
||||
assert.ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply");
|
||||
assert.ok(tc.postSelected(p3), "it selects a post that is a reply");
|
||||
assert.equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two");
|
||||
|
||||
// If we deselected the post whose replies are selected...
|
||||
tc.send('toggledSelectedPost', p1);
|
||||
ok(!tc.postSelected(p1), "it deselects the post");
|
||||
ok(!tc.postSelected(p3), "it deselects the replies too");
|
||||
assert.ok(!tc.postSelected(p1), "it deselects the post");
|
||||
assert.ok(!tc.postSelected(p3), "it deselects the replies too");
|
||||
|
||||
// If we deselect a reply, it should deselect the parent's replies selected attribute. Weird but what else would make sense?
|
||||
tc.send('toggledSelectedPostReplies', p1);
|
||||
tc.send('toggledSelectedPost', p3);
|
||||
ok(tc.postSelected(p1), "the post stays selected");
|
||||
ok(!tc.postSelected(p3), "it deselects the replies too");
|
||||
assert.ok(tc.postSelected(p1), "the post stays selected");
|
||||
assert.ok(!tc.postSelected(p3), "it deselects the replies too");
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ import { setResolverOption, buildResolver } from 'discourse-common/resolver';
|
|||
let originalTemplates;
|
||||
let resolver;
|
||||
|
||||
function lookupTemplate(name, expectedTemplate, message) {
|
||||
function lookupTemplate(assert, name, expectedTemplate, message) {
|
||||
var parseName = resolver.parseName(name);
|
||||
var result = resolver.resolveTemplate(parseName);
|
||||
equal(result, expectedTemplate, message);
|
||||
assert.equal(result, expectedTemplate, message);
|
||||
}
|
||||
|
||||
function setTemplates(lookupTemplateStrings) {
|
||||
|
@ -17,20 +17,20 @@ function setTemplates(lookupTemplateStrings) {
|
|||
|
||||
const DiscourseResolver = buildResolver('discourse');
|
||||
|
||||
module("lib:resolver", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:resolver", {
|
||||
beforeEach() {
|
||||
originalTemplates = Ember.TEMPLATES;
|
||||
Ember.TEMPLATES = {};
|
||||
|
||||
resolver = DiscourseResolver.create();
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
Ember.TEMPLATES = originalTemplates;
|
||||
}
|
||||
});
|
||||
|
||||
test("finds templates in top level dir", function() {
|
||||
QUnit.test("finds templates in top level dir", assert => {
|
||||
setTemplates([
|
||||
"foobar",
|
||||
"fooBar",
|
||||
|
@ -38,24 +38,24 @@ test("finds templates in top level dir", function() {
|
|||
"foo.bar"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foobar", "foobar", "by lowcased name");
|
||||
lookupTemplate("template:fooBar", "fooBar", "by camel cased name");
|
||||
lookupTemplate("template:foo_bar", "foo_bar", "by underscored name");
|
||||
lookupTemplate("template:foo.bar", "foo.bar", "by dotted name");
|
||||
lookupTemplate(assert, "template:foobar", "foobar", "by lowcased name");
|
||||
lookupTemplate(assert, "template:fooBar", "fooBar", "by camel cased name");
|
||||
lookupTemplate(assert, "template:foo_bar", "foo_bar", "by underscored name");
|
||||
lookupTemplate(assert, "template:foo.bar", "foo.bar", "by dotted name");
|
||||
});
|
||||
|
||||
test("finds templates in first-level subdir", function() {
|
||||
QUnit.test("finds templates in first-level subdir", assert => {
|
||||
setTemplates([
|
||||
"foo/bar_baz"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foo/bar_baz", "foo/bar_baz", "with subdir defined by slash");
|
||||
lookupTemplate("template:foo.bar_baz", "foo/bar_baz", "with subdir defined by dot");
|
||||
lookupTemplate("template:fooBarBaz", "foo/bar_baz", "with subdir defined by first camel case and the rest of camel cases converted to underscores");
|
||||
lookupTemplate("template:foo_bar_baz", "foo/bar_baz", "with subdir defined by first underscore");
|
||||
lookupTemplate(assert, "template:foo/bar_baz", "foo/bar_baz", "with subdir defined by slash");
|
||||
lookupTemplate(assert, "template:foo.bar_baz", "foo/bar_baz", "with subdir defined by dot");
|
||||
lookupTemplate(assert, "template:fooBarBaz", "foo/bar_baz", "with subdir defined by first camel case and the rest of camel cases converted to underscores");
|
||||
lookupTemplate(assert, "template:foo_bar_baz", "foo/bar_baz", "with subdir defined by first underscore");
|
||||
});
|
||||
|
||||
test("resolves precedence between overlapping top level dir and first level subdir templates", function() {
|
||||
QUnit.test("resolves precedence between overlapping top level dir and first level subdir templates", assert => {
|
||||
setTemplates([
|
||||
"fooBar",
|
||||
"foo_bar",
|
||||
|
@ -63,28 +63,28 @@ test("resolves precedence between overlapping top level dir and first level subd
|
|||
"foo/bar"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foo.bar", "foo/bar", "preferring first level subdir for dotted name");
|
||||
lookupTemplate("template:fooBar", "fooBar", "preferring top level dir for camel cased name");
|
||||
lookupTemplate("template:foo_bar", "foo_bar", "preferring top level dir for underscored name");
|
||||
lookupTemplate(assert, "template:foo.bar", "foo/bar", "preferring first level subdir for dotted name");
|
||||
lookupTemplate(assert, "template:fooBar", "fooBar", "preferring top level dir for camel cased name");
|
||||
lookupTemplate(assert, "template:foo_bar", "foo_bar", "preferring top level dir for underscored name");
|
||||
});
|
||||
|
||||
test("finds templates in subdir deeper than one level", function() {
|
||||
QUnit.test("finds templates in subdir deeper than one level", assert => {
|
||||
setTemplates([
|
||||
"foo/bar/baz/qux"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foo/bar/baz/qux", "foo/bar/baz/qux", "for subdirs defined by slashes");
|
||||
lookupTemplate("template:foo.bar.baz.qux", "foo/bar/baz/qux", "for subdirs defined by dots");
|
||||
lookupTemplate("template:foo/bar/bazQux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one camel case");
|
||||
lookupTemplate("template:foo/bar/baz_qux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one underscore");
|
||||
lookupTemplate(assert, "template:foo/bar/baz/qux", "foo/bar/baz/qux", "for subdirs defined by slashes");
|
||||
lookupTemplate(assert, "template:foo.bar.baz.qux", "foo/bar/baz/qux", "for subdirs defined by dots");
|
||||
lookupTemplate(assert, "template:foo/bar/bazQux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one camel case");
|
||||
lookupTemplate(assert, "template:foo/bar/baz_qux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one underscore");
|
||||
|
||||
lookupTemplate("template:fooBarBazQux", undefined, "but not for subdirs defined by more than one camel case");
|
||||
lookupTemplate("template:foo_bar_baz_qux", undefined, "but not for subdirs defined by more than one underscore");
|
||||
lookupTemplate("template:foo.bar.bazQux", undefined, "but not for subdirs defined by dots plus one camel case");
|
||||
lookupTemplate("template:foo.bar.baz_qux", undefined, "but not for subdirs defined by dots plus one underscore");
|
||||
lookupTemplate(assert, "template:fooBarBazQux", undefined, "but not for subdirs defined by more than one camel case");
|
||||
lookupTemplate(assert, "template:foo_bar_baz_qux", undefined, "but not for subdirs defined by more than one underscore");
|
||||
lookupTemplate(assert, "template:foo.bar.bazQux", undefined, "but not for subdirs defined by dots plus one camel case");
|
||||
lookupTemplate(assert, "template:foo.bar.baz_qux", undefined, "but not for subdirs defined by dots plus one underscore");
|
||||
});
|
||||
|
||||
test("resolves mobile templates to 'mobile/' namespace", function() {
|
||||
QUnit.test("resolves mobile templates to 'mobile/' namespace", assert => {
|
||||
setTemplates([
|
||||
"mobile/foo",
|
||||
"bar",
|
||||
|
@ -94,12 +94,12 @@ test("resolves mobile templates to 'mobile/' namespace", function() {
|
|||
|
||||
setResolverOption('mobileView', true);
|
||||
|
||||
lookupTemplate("template:foo", "mobile/foo", "finding mobile version even if normal one is not present");
|
||||
lookupTemplate("template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present");
|
||||
lookupTemplate("template:baz", "baz", "falling back to a normal version when mobile version is not present");
|
||||
lookupTemplate(assert, "template:foo", "mobile/foo", "finding mobile version even if normal one is not present");
|
||||
lookupTemplate(assert, "template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present");
|
||||
lookupTemplate(assert, "template:baz", "baz", "falling back to a normal version when mobile version is not present");
|
||||
});
|
||||
|
||||
test("resolves plugin templates to 'javascripts/' namespace", function() {
|
||||
QUnit.test("resolves plugin templates to 'javascripts/' namespace", assert => {
|
||||
setTemplates([
|
||||
"javascripts/foo",
|
||||
"bar",
|
||||
|
@ -107,12 +107,12 @@ test("resolves plugin templates to 'javascripts/' namespace", function() {
|
|||
"baz"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foo", "javascripts/foo", "finding plugin version even if normal one is not present");
|
||||
lookupTemplate("template:bar", "javascripts/bar", "preferring plugin version when both versions are present");
|
||||
lookupTemplate("template:baz", "baz", "falling back to a normal version when plugin version is not present");
|
||||
lookupTemplate(assert, "template:foo", "javascripts/foo", "finding plugin version even if normal one is not present");
|
||||
lookupTemplate(assert, "template:bar", "javascripts/bar", "preferring plugin version when both versions are present");
|
||||
lookupTemplate(assert, "template:baz", "baz", "falling back to a normal version when plugin version is not present");
|
||||
});
|
||||
|
||||
test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", function() {
|
||||
QUnit.test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", assert => {
|
||||
setTemplates([
|
||||
"admin/templates/foo",
|
||||
"adminBar",
|
||||
|
@ -121,20 +121,20 @@ test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", f
|
|||
"admin/templates/bar"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:adminFoo", "admin/templates/foo", "when prefix is separated by camel case");
|
||||
lookupTemplate("template:admin_foo", "admin/templates/foo", "when prefix is separated by underscore");
|
||||
lookupTemplate("template:admin.foo", "admin/templates/foo", "when prefix is separated by dot");
|
||||
lookupTemplate(assert, "template:adminFoo", "admin/templates/foo", "when prefix is separated by camel case");
|
||||
lookupTemplate(assert, "template:admin_foo", "admin/templates/foo", "when prefix is separated by underscore");
|
||||
lookupTemplate(assert, "template:admin.foo", "admin/templates/foo", "when prefix is separated by dot");
|
||||
|
||||
lookupTemplate("template:adminfoo", undefined, "but not when prefix is not separated in any way");
|
||||
lookupTemplate("template:adminBar", "adminBar", "but not when template with the exact camel cased name exists");
|
||||
lookupTemplate("template:admin_bar", "admin_bar", "but not when template with the exact underscored name exists");
|
||||
lookupTemplate("template:admin.bar", "admin.bar", "but not when template with the exact dotted name exists");
|
||||
lookupTemplate(assert, "template:adminfoo", undefined, "but not when prefix is not separated in any way");
|
||||
lookupTemplate(assert, "template:adminBar", "adminBar", "but not when template with the exact camel cased name exists");
|
||||
lookupTemplate(assert, "template:admin_bar", "admin_bar", "but not when template with the exact underscored name exists");
|
||||
lookupTemplate(assert, "template:admin.bar", "admin.bar", "but not when template with the exact dotted name exists");
|
||||
});
|
||||
|
||||
test("returns 'not_found' template when template name cannot be resolved", function() {
|
||||
QUnit.test("returns 'not_found' template when template name cannot be resolved", assert => {
|
||||
setTemplates([
|
||||
"not_found"
|
||||
]);
|
||||
|
||||
lookupTemplate("template:foo/bar/baz", "not_found", "");
|
||||
lookupTemplate(assert, "template:foo/bar/baz", "not_found", "");
|
||||
});
|
||||
|
|
|
@ -8,14 +8,6 @@ function count(selector) {
|
|||
return find(selector).length;
|
||||
}
|
||||
|
||||
function containsInstance(collection, klass, text) {
|
||||
ok(klass.detectInstance(_.first(collection)), text);
|
||||
}
|
||||
|
||||
function not(state, message) {
|
||||
ok(!state, message);
|
||||
}
|
||||
|
||||
function visible(selector) {
|
||||
return find(selector + ":visible").length > 0;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ export default function(name, opts) {
|
|||
|
||||
this.registry.register('store:main', store, { instantiate: false });
|
||||
|
||||
if (opts.setup) {
|
||||
opts.setup.call(this, store);
|
||||
if (opts.beforeEach) {
|
||||
opts.beforeEach.call(this, store);
|
||||
}
|
||||
|
||||
andThen(() => {
|
||||
|
|
|
@ -379,4 +379,4 @@ export default function() {
|
|||
|
||||
server.checkPassthrough = request => request.requestHeaders['Discourse-Script'];
|
||||
return server;
|
||||
}
|
||||
}
|
|
@ -11,8 +11,11 @@ export default function() {
|
|||
register: {
|
||||
lookup(type) {
|
||||
if (type === "adapter:rest") {
|
||||
this._restAdapter = this._restAdapter || RestAdapter.create({ container: this });
|
||||
return (this._restAdapter);
|
||||
if (!this._restAdapter) {
|
||||
this._restAdapter = RestAdapter.create({ owner: this });
|
||||
// this._restAdapter.container = this;
|
||||
}
|
||||
return this._restAdapter;
|
||||
}
|
||||
if (type === "key-value-store:main") {
|
||||
this._kvs = this._kvs || new KeyValueStore();
|
||||
|
@ -34,5 +37,4 @@ export default function() {
|
|||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -5,4 +5,4 @@ export default function parseHTML(rawHtml) {
|
|||
|
||||
parser.parseComplete(rawHtml);
|
||||
return builder.dom;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* global asyncTest, fixtures */
|
||||
/* global QUnit, fixtures */
|
||||
|
||||
import sessionFixtures from 'fixtures/session-fixtures';
|
||||
import siteFixtures from 'fixtures/site-fixtures';
|
||||
|
@ -41,7 +41,7 @@ $.fn.modal = AcceptanceModal;
|
|||
|
||||
function acceptance(name, options) {
|
||||
module("Acceptance: " + name, {
|
||||
setup() {
|
||||
beforeEach() {
|
||||
resetMobile();
|
||||
|
||||
// For now don't do scrolling stuff in Test Mode
|
||||
|
@ -50,8 +50,8 @@ function acceptance(name, options) {
|
|||
resetExtraClasses();
|
||||
const siteJson = siteFixtures['site.json'].site;
|
||||
if (options) {
|
||||
if (options.setup) {
|
||||
options.setup.call(this);
|
||||
if (options.beforeEach) {
|
||||
options.beforeEach.call(this);
|
||||
}
|
||||
|
||||
if (options.mobileView) {
|
||||
|
@ -77,9 +77,9 @@ function acceptance(name, options) {
|
|||
Discourse.reset();
|
||||
},
|
||||
|
||||
teardown() {
|
||||
if (options && options.teardown) {
|
||||
options.teardown.call(this);
|
||||
afterEach() {
|
||||
if (options && options.afterEach) {
|
||||
options.afterEach.call(this);
|
||||
}
|
||||
flushMap();
|
||||
Discourse.User.resetCurrent();
|
||||
|
@ -102,10 +102,11 @@ function controllerFor(controller, model) {
|
|||
}
|
||||
|
||||
function asyncTestDiscourse(text, func) {
|
||||
asyncTest(text, function () {
|
||||
var self = this;
|
||||
Ember.run(function () {
|
||||
func.call(self);
|
||||
QUnit.test(text, function(assert) {
|
||||
const done = assert.async();
|
||||
Ember.run(() => {
|
||||
func.call(this, assert);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -117,20 +118,46 @@ function fixture(selector) {
|
|||
return $("#qunit-fixture");
|
||||
}
|
||||
|
||||
function present(obj, text) {
|
||||
ok(!Ember.isEmpty(obj), text);
|
||||
}
|
||||
QUnit.assert.not = function(actual, message) {
|
||||
this.pushResult({
|
||||
result: !actual,
|
||||
actual,
|
||||
expected: !actual,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function blank(obj, text) {
|
||||
ok(Ember.isEmpty(obj), text);
|
||||
}
|
||||
QUnit.assert.blank = function(actual, message) {
|
||||
this.pushResult({
|
||||
result: Ember.isEmpty(actual),
|
||||
actual,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function waitFor(callback, timeout) {
|
||||
QUnit.assert.present = function(actual, message) {
|
||||
this.pushResult({
|
||||
result: !Ember.isEmpty(actual),
|
||||
actual,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
QUnit.assert.containsInstance = function(collection, klass, message) {
|
||||
const result = klass.detectInstance(_.first(collection));
|
||||
this.pushResult({
|
||||
result,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function waitFor(assert, callback, timeout) {
|
||||
timeout = timeout || 500;
|
||||
stop();
|
||||
|
||||
const done = assert.async();
|
||||
Ember.run.later(() => {
|
||||
callback();
|
||||
start();
|
||||
done();
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
|
@ -140,6 +167,4 @@ export { acceptance,
|
|||
fixture,
|
||||
logIn,
|
||||
currentUser,
|
||||
blank,
|
||||
present,
|
||||
waitFor };
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -76,4 +76,4 @@ export default function(helpers) {
|
|||
});
|
||||
|
||||
this.delete('/widgets/:widget_id', success);
|
||||
};
|
||||
};
|
|
@ -6,4 +6,4 @@ export function moduleForWidget(name) {
|
|||
|
||||
export function widgetTest(name, opts) {
|
||||
return componentTest(name, opts);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
import PreloadStore from 'preload-store';
|
||||
import LocalizationInitializer from 'discourse/initializers/localization';
|
||||
|
||||
module("initializer:localization", {
|
||||
QUnit.module("initializer:localization", {
|
||||
_locale: I18n.locale,
|
||||
_translations: I18n.translations,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
I18n.locale = "fr";
|
||||
|
||||
I18n.translations = {
|
||||
|
@ -28,16 +28,16 @@ module("initializer:localization", {
|
|||
};
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
I18n.locale = this._locale;
|
||||
I18n.translations = this._translations;
|
||||
}
|
||||
});
|
||||
|
||||
test("translation overrides", function() {
|
||||
QUnit.test("translation overrides", assert => {
|
||||
PreloadStore.store('translationOverrides', {"js.composer.reply":"WAT","js.topic.reply.help":"foobar"});
|
||||
LocalizationInitializer.initialize(this.registry);
|
||||
|
||||
equal(I18n.t("composer.reply"), "WAT", "overrides existing translation in current locale");
|
||||
equal(I18n.t("topic.reply.help"), "foobar", "overrides translation in default locale");
|
||||
});
|
||||
assert.equal(I18n.t("composer.reply"), "WAT", "overrides existing translation in current locale");
|
||||
assert.equal(I18n.t("topic.reply.help"), "foobar", "overrides translation in default locale");
|
||||
});
|
|
@ -1,16 +1,15 @@
|
|||
import createStore from 'helpers/create-store';
|
||||
import { blank, present } from 'helpers/qunit-helpers';
|
||||
|
||||
module("lib:category-link");
|
||||
QUnit.module("lib:category-link");
|
||||
|
||||
import parseHTML from 'helpers/parse-html';
|
||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||
|
||||
test("categoryBadge without a category", function() {
|
||||
blank(categoryBadgeHTML(), "it returns no HTML");
|
||||
QUnit.test("categoryBadge without a category", assert => {
|
||||
assert.blank(categoryBadgeHTML(), "it returns no HTML");
|
||||
});
|
||||
|
||||
test("Regular categoryBadge", function() {
|
||||
QUnit.test("Regular categoryBadge", assert => {
|
||||
const store = createStore();
|
||||
const category = store.createRecord('category', {
|
||||
name: 'hello',
|
||||
|
@ -21,28 +20,28 @@ test("Regular categoryBadge", function() {
|
|||
});
|
||||
const tag = parseHTML(categoryBadgeHTML(category))[0];
|
||||
|
||||
equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
||||
equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
||||
assert.equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
||||
assert.equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
||||
|
||||
const label = tag.children[1];
|
||||
equal(label.attributes.title, 'cool description', 'it has the correct title');
|
||||
assert.equal(label.attributes.title, 'cool description', 'it has the correct title');
|
||||
|
||||
equal(label.children[0].data, 'hello', 'it has the category name');
|
||||
assert.equal(label.children[0].data, 'hello', 'it has the category name');
|
||||
});
|
||||
|
||||
test("undefined color", function() {
|
||||
QUnit.test("undefined color", assert => {
|
||||
const store = createStore();
|
||||
const noColor = store.createRecord('category', { name: 'hello', id: 123 });
|
||||
const tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
||||
|
||||
blank(tag.attributes.style, "it has no color style because there are no colors");
|
||||
assert.blank(tag.attributes.style, "it has no color style because there are no colors");
|
||||
});
|
||||
|
||||
test("allowUncategorized", function() {
|
||||
QUnit.test("allowUncategorized", assert => {
|
||||
const store = createStore();
|
||||
const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345});
|
||||
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
||||
|
||||
blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||
present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
||||
});
|
||||
assert.blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||
assert.present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
||||
});
|
|
@ -1,4 +1,3 @@
|
|||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
|
@ -6,8 +5,8 @@ var windowOpen,
|
|||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track-edit-history", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track-edit-history", {
|
||||
beforeEach() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
|
@ -56,56 +55,57 @@ var generateClickEventOn = function(selector) {
|
|||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", assert => {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", assert => {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", assert => {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
|
@ -115,32 +115,32 @@ var trackRightClick = function(target) {
|
|||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick('a'));
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", assert => {
|
||||
assert.ok(trackRightClick('a'));
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('a');
|
||||
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -160,31 +160,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
|||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
|
@ -6,8 +5,8 @@ var windowOpen,
|
|||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track-profile-page", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track-profile-page", {
|
||||
beforeEach() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
|
@ -50,56 +49,57 @@ var generateClickEventOn = function(selector) {
|
|||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", assert => {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", assert => {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", assert => {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", assert => {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
|
@ -109,38 +109,38 @@ var trackRightClick = function(target) {
|
|||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick('a'));
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", assert => {
|
||||
assert.ok(trackRightClick('a'));
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('a');
|
||||
equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("right clicks are tracked for second excerpt", function() {
|
||||
QUnit.test("right clicks are tracked for second excerpt", assert => {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick('.second a');
|
||||
equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
assert.equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -160,44 +160,44 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
|||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", assert => {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('.second a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
||||
test("tracks custom urls on second excerpt when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => {
|
||||
var clickEvent = generateClickEventOn('.second a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331'));
|
||||
});
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { blank } from 'helpers/qunit-helpers';
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
|
||||
|
@ -6,8 +5,8 @@ var windowOpen,
|
|||
win,
|
||||
redirectTo;
|
||||
|
||||
module("lib:click-track", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:click-track", {
|
||||
beforeEach() {
|
||||
// Prevent any of these tests from navigating away
|
||||
win = {focus: function() { } };
|
||||
redirectTo = sandbox.stub(DiscourseURL, "redirectTo");
|
||||
|
@ -47,87 +46,88 @@ var generateClickEventOn = function(selector) {
|
|||
return $.Event("click", { currentTarget: fixture(selector)[0] });
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
QUnit.test("does not track clicks on lightboxes", function(assert) {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
test("it calls preventDefault when clicking on an a", function() {
|
||||
QUnit.test("it calls preventDefault when clicking on an a", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
track(clickEvent);
|
||||
ok(clickEvent.preventDefault.calledOnce);
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track clicks when forcibly disabled", function() {
|
||||
ok(track(generateClickEventOn('.no-track-link')));
|
||||
QUnit.test("does not track clicks when forcibly disabled", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.no-track-link')));
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
QUnit.test("does not track clicks on back buttons", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks in quotes", function() {
|
||||
ok(track(generateClickEventOn('.inside-quote')));
|
||||
QUnit.test("does not track clicks in quotes", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.inside-quote')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
QUnit.test("does not track clicks on quote buttons", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("does not track clicks on category badges", () => {
|
||||
ok(track(generateClickEventOn('.hashtag')));
|
||||
QUnit.test("does not track clicks on category badges", assert => {
|
||||
assert.ok(track(generateClickEventOn('.hashtag')));
|
||||
});
|
||||
|
||||
test("does not track clicks on mailto", function() {
|
||||
ok(track(generateClickEventOn('.mailto')));
|
||||
QUnit.test("does not track clicks on mailto", function(assert) {
|
||||
assert.ok(track(generateClickEventOn('.mailto')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
QUnit.test("removes the href and put it as a data attribute", function(assert) {
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
var $link = fixture('a').first();
|
||||
ok($link.hasClass('no-href'));
|
||||
equal($link.data('href'), 'http://www.google.com');
|
||||
blank($link.attr('href'));
|
||||
ok($link.data('auto-route'));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok($link.hasClass('no-href'));
|
||||
assert.equal($link.data('href'), 'http://www.google.com');
|
||||
assert.blank($link.attr('href'));
|
||||
assert.ok($link.data('auto-route'));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
asyncTestDiscourse("restores the href after a while", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("restores the href after a while", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
track(generateClickEventOn('a'));
|
||||
|
||||
const done = assert.async();
|
||||
setTimeout(function() {
|
||||
start();
|
||||
equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
done();
|
||||
assert.equal(fixture('a').attr('href'), "http://www.google.com");
|
||||
}, 75);
|
||||
});
|
||||
|
||||
var badgeClickCount = function(id, expected) {
|
||||
var badgeClickCount = function(assert, id, expected) {
|
||||
track(generateClickEventOn('#' + id));
|
||||
var $badge = $('span.badge', fixture('#' + id).first());
|
||||
equal(parseInt($badge.html(), 10), expected);
|
||||
assert.equal(parseInt($badge.html(), 10), expected);
|
||||
};
|
||||
|
||||
test("does not update badge clicks on my own link", function() {
|
||||
QUnit.test("does not update badge clicks on my own link", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(314);
|
||||
badgeClickCount('with-badge', 1);
|
||||
badgeClickCount(assert, 'with-badge', 1);
|
||||
});
|
||||
|
||||
test("does not update badge clicks in my own post", function() {
|
||||
QUnit.test("does not update badge clicks in my own post", function(assert) {
|
||||
sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(3141);
|
||||
badgeClickCount('with-badge-but-not-mine', 1);
|
||||
badgeClickCount(assert, 'with-badge-but-not-mine', 1);
|
||||
});
|
||||
|
||||
test("updates badge counts correctly", function() {
|
||||
badgeClickCount('inside-onebox', 1);
|
||||
badgeClickCount('inside-onebox-forced', 2);
|
||||
badgeClickCount('with-badge', 2);
|
||||
QUnit.test("updates badge counts correctly", function(assert) {
|
||||
badgeClickCount(assert, 'inside-onebox', 1);
|
||||
badgeClickCount(assert, 'inside-onebox-forced', 2);
|
||||
badgeClickCount(assert, 'with-badge', 2);
|
||||
});
|
||||
|
||||
var trackRightClick = function() {
|
||||
|
@ -136,32 +136,32 @@ var trackRightClick = function() {
|
|||
return track(clickEvent);
|
||||
};
|
||||
|
||||
test("right clicks change the href", function() {
|
||||
ok(trackRightClick());
|
||||
equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
QUnit.test("right clicks change the href", function(assert) {
|
||||
assert.ok(trackRightClick());
|
||||
assert.equal(fixture('a').first().prop('href'), "http://www.google.com/");
|
||||
});
|
||||
|
||||
test("right clicks are tracked", function() {
|
||||
QUnit.test("right clicks are tracked", function(assert) {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick();
|
||||
equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337");
|
||||
});
|
||||
|
||||
test("preventDefault is not called for right clicks", function() {
|
||||
QUnit.test("preventDefault is not called for right clicks", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
|
||||
var testOpenInANewTab = function(description, clickEventModifier) {
|
||||
test(description, function() {
|
||||
test(description, function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEventModifier(clickEvent);
|
||||
sandbox.stub(clickEvent, "preventDefault");
|
||||
ok(track(clickEvent));
|
||||
ok(!clickEvent.preventDefault.calledOnce);
|
||||
assert.ok(track(clickEvent));
|
||||
assert.ok(!clickEvent.preventDefault.calledOnce);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -181,31 +181,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent)
|
|||
clickEvent.button = 2;
|
||||
});
|
||||
|
||||
test("tracks via AJAX if we're on the same site", function() {
|
||||
QUnit.test("tracks via AJAX if we're on the same site", function(assert) {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('#same-site')));
|
||||
ok(DiscourseURL.routeTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('#same-site')));
|
||||
assert.ok(DiscourseURL.routeTo.calledOnce);
|
||||
});
|
||||
|
||||
test("does not track via AJAX for attachments", function() {
|
||||
QUnit.test("does not track via AJAX for attachments", function(assert) {
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
|
||||
|
||||
ok(!track(generateClickEventOn('.attachment')));
|
||||
ok(DiscourseURL.redirectTo.calledOnce);
|
||||
assert.ok(!track(generateClickEventOn('.attachment')));
|
||||
assert.ok(DiscourseURL.redirectTo.calledOnce);
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
|
||||
ok(!track(clickEvent));
|
||||
ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank'));
|
||||
});
|
||||
|
||||
test("tracks custom urls when opening in another window", function() {
|
||||
QUnit.test("tracks custom urls when opening in another window", function(assert) {
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
ok(!track(clickEvent));
|
||||
ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
assert.ok(!track(clickEvent));
|
||||
assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337'));
|
||||
});
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
import { setting, propertyEqual, propertyNotEqual, fmt, i18n, url } from 'discourse/lib/computed';
|
||||
|
||||
module("lib:computed", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:computed", {
|
||||
beforeEach() {
|
||||
sandbox.stub(I18n, "t", function(scope) {
|
||||
return "%@ translated: " + scope;
|
||||
});
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
I18n.t.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("setting", function() {
|
||||
QUnit.test("setting", assert => {
|
||||
var t = Em.Object.extend({
|
||||
vehicle: setting('vehicle'),
|
||||
missingProp: setting('madeUpThing')
|
||||
}).create();
|
||||
|
||||
Discourse.SiteSettings.vehicle = "airplane";
|
||||
equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
assert.equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
assert.ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
});
|
||||
|
||||
test("propertyEqual", function() {
|
||||
QUnit.test("propertyEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
same: propertyEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
|
@ -31,12 +31,12 @@ test("propertyEqual", function() {
|
|||
biscuits: 10
|
||||
});
|
||||
|
||||
ok(t.get('same'), "it is true when the properties are the same");
|
||||
assert.ok(t.get('same'), "it is true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
ok(!t.get('same'), "it isn't true when one property is different");
|
||||
assert.ok(!t.get('same'), "it isn't true when one property is different");
|
||||
});
|
||||
|
||||
test("propertyNotEqual", function() {
|
||||
QUnit.test("propertyNotEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
diff: propertyNotEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
|
@ -44,13 +44,13 @@ test("propertyNotEqual", function() {
|
|||
biscuits: 10
|
||||
});
|
||||
|
||||
ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
assert.ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
ok(t.get('diff'), "it is true when one property is different");
|
||||
assert.ok(t.get('diff'), "it is true when one property is different");
|
||||
});
|
||||
|
||||
|
||||
test("fmt", function() {
|
||||
QUnit.test("fmt", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: fmt('username', "!!! %@ !!!"),
|
||||
multiple: fmt('username', 'mood', "%@ is %@")
|
||||
|
@ -59,17 +59,17 @@ test("fmt", function() {
|
|||
mood: "happy"
|
||||
});
|
||||
|
||||
equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
||||
equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
||||
assert.equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
||||
assert.equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
||||
assert.equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
||||
assert.equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
||||
});
|
||||
|
||||
|
||||
test("i18n", function() {
|
||||
QUnit.test("i18n", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: i18n('username', "!!! %@ !!!"),
|
||||
multiple: i18n('username', 'mood', "%@ is %@")
|
||||
|
@ -78,17 +78,17 @@ test("i18n", function() {
|
|||
mood: "happy"
|
||||
});
|
||||
|
||||
equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
||||
equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
||||
assert.equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
||||
assert.equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
||||
});
|
||||
|
||||
|
||||
test("url", function() {
|
||||
QUnit.test("url", assert => {
|
||||
var t, testClass;
|
||||
|
||||
testClass = Em.Object.extend({
|
||||
|
@ -96,9 +96,9 @@ test("url", function() {
|
|||
});
|
||||
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix");
|
||||
assert.equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix");
|
||||
|
||||
Discourse.BaseUri = "/prefixed";
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix");
|
||||
assert.equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix");
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module("lib:discourse");
|
||||
QUnit.module("lib:discourse");
|
||||
|
||||
test("getURL on subfolder install", function() {
|
||||
QUnit.test("getURL on subfolder install", assert => {
|
||||
Discourse.BaseUri = "/forum";
|
||||
equal(Discourse.getURL("/"), "/forum/", "root url has subfolder");
|
||||
equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder");
|
||||
});
|
||||
assert.equal(Discourse.getURL("/"), "/forum/", "root url has subfolder");
|
||||
assert.equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder");
|
||||
});
|
|
@ -1,13 +1,13 @@
|
|||
import { emojiSearch, IMAGE_VERSION as v } from 'pretty-text/emoji';
|
||||
import { emojiUnescape } from 'discourse/lib/text';
|
||||
|
||||
module('lib:emoji');
|
||||
QUnit.module('lib:emoji');
|
||||
|
||||
function testUnescape(input, expected, description) {
|
||||
equal(emojiUnescape(input), expected, description);
|
||||
};
|
||||
QUnit.test("emojiUnescape", assert => {
|
||||
const testUnescape = (input, expected, description) => {
|
||||
assert.equal(emojiUnescape(input), expected, description);
|
||||
};
|
||||
|
||||
test("emojiUnescape", () => {
|
||||
testUnescape("Not emoji :O) :frog) :smile)", "Not emoji :O) :frog) :smile)", "title without emoji");
|
||||
testUnescape("Not emoji :frog :smile", "Not emoji :frog :smile", "end colon is not optional");
|
||||
testUnescape("emoticons :)", `emoticons <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'>`, "emoticons are still supported");
|
||||
|
@ -24,11 +24,11 @@ test("emojiUnescape", () => {
|
|||
|
||||
});
|
||||
|
||||
test("Emoji search", () => {
|
||||
QUnit.test("Emoji search", assert => {
|
||||
// able to find an alias
|
||||
equal(emojiSearch("+1").length, 1);
|
||||
assert.equal(emojiSearch("+1").length, 1);
|
||||
|
||||
// able to find middle of line search
|
||||
equal(emojiSearch("check", {maxResults: 3}).length, 3);
|
||||
assert.equal(emojiSearch("check", {maxResults: 3}).length, 3);
|
||||
|
||||
});
|
||||
|
|
|
@ -2,12 +2,12 @@ var clock;
|
|||
|
||||
import { relativeAge, autoUpdatingRelativeAge, updateRelativeAge, breakUp, number, longDate } from 'discourse/lib/formatter';
|
||||
|
||||
module("lib:formatter", {
|
||||
setup: function() {
|
||||
QUnit.module("lib:formatter", {
|
||||
beforeEach() {
|
||||
clock = sinon.useFakeTimers(new Date(2012,11,31,12,0).getTime());
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
afterEach() {
|
||||
clock.restore();
|
||||
}
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ var shortDate = function(days){
|
|||
return moment().subtract(days, 'days').format('MMM D');
|
||||
};
|
||||
|
||||
test("formating medium length dates", function() {
|
||||
QUnit.test("formating medium length dates", assert => {
|
||||
|
||||
format = "medium";
|
||||
var strip = function(html){
|
||||
|
@ -46,133 +46,133 @@ test("formating medium length dates", function() {
|
|||
};
|
||||
|
||||
leaveAgo = true;
|
||||
equal(strip(formatMins(1.4)), "1 min ago");
|
||||
equal(strip(formatMins(2)), "2 mins ago");
|
||||
equal(strip(formatMins(55)), "55 mins ago");
|
||||
equal(strip(formatMins(56)), "1 hour ago");
|
||||
equal(strip(formatHours(4)), "4 hours ago");
|
||||
equal(strip(formatHours(22)), "22 hours ago");
|
||||
equal(strip(formatHours(23)), "23 hours ago");
|
||||
equal(strip(formatHours(23.5)), "1 day ago");
|
||||
equal(strip(formatDays(4.85)), "4 days ago");
|
||||
assert.equal(strip(formatMins(1.4)), "1 min ago");
|
||||
assert.equal(strip(formatMins(2)), "2 mins ago");
|
||||
assert.equal(strip(formatMins(55)), "55 mins ago");
|
||||
assert.equal(strip(formatMins(56)), "1 hour ago");
|
||||
assert.equal(strip(formatHours(4)), "4 hours ago");
|
||||
assert.equal(strip(formatHours(22)), "22 hours ago");
|
||||
assert.equal(strip(formatHours(23)), "23 hours ago");
|
||||
assert.equal(strip(formatHours(23.5)), "1 day ago");
|
||||
assert.equal(strip(formatDays(4.85)), "4 days ago");
|
||||
|
||||
leaveAgo = false;
|
||||
equal(strip(formatMins(0)), "just now");
|
||||
equal(strip(formatMins(1.4)), "1 min");
|
||||
equal(strip(formatMins(2)), "2 mins");
|
||||
equal(strip(formatMins(55)), "55 mins");
|
||||
equal(strip(formatMins(56)), "1 hour");
|
||||
equal(strip(formatHours(4)), "4 hours");
|
||||
equal(strip(formatHours(22)), "22 hours");
|
||||
equal(strip(formatHours(23)), "23 hours");
|
||||
equal(strip(formatHours(23.5)), "1 day");
|
||||
equal(strip(formatDays(4.85)), "4 days");
|
||||
assert.equal(strip(formatMins(0)), "just now");
|
||||
assert.equal(strip(formatMins(1.4)), "1 min");
|
||||
assert.equal(strip(formatMins(2)), "2 mins");
|
||||
assert.equal(strip(formatMins(55)), "55 mins");
|
||||
assert.equal(strip(formatMins(56)), "1 hour");
|
||||
assert.equal(strip(formatHours(4)), "4 hours");
|
||||
assert.equal(strip(formatHours(22)), "22 hours");
|
||||
assert.equal(strip(formatHours(23)), "23 hours");
|
||||
assert.equal(strip(formatHours(23.5)), "1 day");
|
||||
assert.equal(strip(formatDays(4.85)), "4 days");
|
||||
|
||||
equal(strip(formatDays(6)), shortDate(6));
|
||||
equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23
|
||||
equal(strip(formatDays(500)), shortDateYear(500));
|
||||
assert.equal(strip(formatDays(6)), shortDate(6));
|
||||
assert.equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23
|
||||
assert.equal(strip(formatDays(500)), shortDateYear(500));
|
||||
|
||||
equal($(formatDays(0)).attr("title"), longDate(new Date()));
|
||||
equal($(formatDays(0)).attr("class"), "date");
|
||||
assert.equal($(formatDays(0)).attr("title"), longDate(new Date()));
|
||||
assert.equal($(formatDays(0)).attr("class"), "date");
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,9,12,0).getTime()); // Jan 9, 2012
|
||||
|
||||
equal(strip(formatDays(8)), shortDate(8));
|
||||
equal(strip(formatDays(10)), shortDateYear(10));
|
||||
assert.equal(strip(formatDays(8)), shortDate(8));
|
||||
assert.equal(strip(formatDays(10)), shortDateYear(10));
|
||||
});
|
||||
|
||||
test("formating tiny dates", function() {
|
||||
QUnit.test("formating tiny dates", assert => {
|
||||
var shortDateYear = function(days){
|
||||
return moment().subtract(days, 'days').format("MMM 'YY");
|
||||
};
|
||||
|
||||
format = "tiny";
|
||||
equal(formatMins(0), "1m");
|
||||
equal(formatMins(1), "1m");
|
||||
equal(formatMins(2), "2m");
|
||||
equal(formatMins(60), "1h");
|
||||
equal(formatHours(4), "4h");
|
||||
equal(formatHours(23), "23h");
|
||||
equal(formatHours(23.5), "1d");
|
||||
equal(formatDays(1), "1d");
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDate(15));
|
||||
equal(formatDays(92), shortDate(92));
|
||||
equal(formatDays(364), shortDate(364));
|
||||
equal(formatDays(365), shortDate(365));
|
||||
equal(formatDays(366), shortDateYear(366)); // leap year
|
||||
equal(formatDays(500), shortDateYear(500));
|
||||
equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year
|
||||
assert.equal(formatMins(0), "1m");
|
||||
assert.equal(formatMins(1), "1m");
|
||||
assert.equal(formatMins(2), "2m");
|
||||
assert.equal(formatMins(60), "1h");
|
||||
assert.equal(formatHours(4), "4h");
|
||||
assert.equal(formatHours(23), "23h");
|
||||
assert.equal(formatHours(23.5), "1d");
|
||||
assert.equal(formatDays(1), "1d");
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(92), shortDate(92));
|
||||
assert.equal(formatDays(364), shortDate(364));
|
||||
assert.equal(formatDays(365), shortDate(365));
|
||||
assert.equal(formatDays(366), shortDateYear(366)); // leap year
|
||||
assert.equal(formatDays(500), shortDateYear(500));
|
||||
assert.equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year
|
||||
|
||||
var originalValue = Discourse.SiteSettings.relative_date_duration;
|
||||
Discourse.SiteSettings.relative_date_duration = 7;
|
||||
equal(formatDays(7), "7d");
|
||||
equal(formatDays(8), shortDate(8));
|
||||
assert.equal(formatDays(7), "7d");
|
||||
assert.equal(formatDays(8), shortDate(8));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 1;
|
||||
equal(formatDays(1), "1d");
|
||||
equal(formatDays(2), shortDate(2));
|
||||
assert.equal(formatDays(1), "1d");
|
||||
assert.equal(formatDays(2), shortDate(2));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 0;
|
||||
equal(formatMins(0), "1m");
|
||||
equal(formatMins(1), "1m");
|
||||
equal(formatMins(2), "2m");
|
||||
equal(formatMins(60), "1h");
|
||||
equal(formatDays(1), shortDate(1));
|
||||
equal(formatDays(2), shortDate(2));
|
||||
equal(formatDays(366), shortDateYear(366));
|
||||
assert.equal(formatMins(0), "1m");
|
||||
assert.equal(formatMins(1), "1m");
|
||||
assert.equal(formatMins(2), "2m");
|
||||
assert.equal(formatMins(60), "1h");
|
||||
assert.equal(formatDays(1), shortDate(1));
|
||||
assert.equal(formatDays(2), shortDate(2));
|
||||
assert.equal(formatDays(366), shortDateYear(366));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = null;
|
||||
equal(formatDays(1), '1d');
|
||||
equal(formatDays(14), '14d');
|
||||
equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(1), '1d');
|
||||
assert.equal(formatDays(14), '14d');
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = 14;
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,12,12,0).getTime()); // Jan 12, 2012
|
||||
|
||||
equal(formatDays(11), "11d");
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDateYear(15));
|
||||
equal(formatDays(366), shortDateYear(366));
|
||||
assert.equal(formatDays(11), "11d");
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDateYear(15));
|
||||
assert.equal(formatDays(366), shortDateYear(366));
|
||||
|
||||
clock.restore();
|
||||
clock = sinon.useFakeTimers(new Date(2012,0,20,12,0).getTime()); // Jan 20, 2012
|
||||
|
||||
equal(formatDays(14), "14d");
|
||||
equal(formatDays(15), shortDate(15));
|
||||
equal(formatDays(20), shortDateYear(20));
|
||||
assert.equal(formatDays(14), "14d");
|
||||
assert.equal(formatDays(15), shortDate(15));
|
||||
assert.equal(formatDays(20), shortDateYear(20));
|
||||
|
||||
Discourse.SiteSettings.relative_date_duration = originalValue;
|
||||
});
|
||||
|
||||
test("autoUpdatingRelativeAge", function() {
|
||||
QUnit.test("autoUpdatingRelativeAge", assert => {
|
||||
var d = moment().subtract(1, 'day').toDate();
|
||||
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
equal($elem.data('format'), "tiny");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
assert.equal($elem.data('format'), "tiny");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), undefined);
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d, {title: true}));
|
||||
equal($elem.attr('title'), longDate(d));
|
||||
assert.equal($elem.attr('title'), longDate(d));
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true}));
|
||||
equal($elem.data('format'), "medium-with-ago");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), longDate(d));
|
||||
equal($elem.html(), '1 day ago');
|
||||
assert.equal($elem.data('format'), "medium-with-ago");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), longDate(d));
|
||||
assert.equal($elem.html(), '1 day ago');
|
||||
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium'}));
|
||||
equal($elem.data('format'), "medium");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
equal($elem.html(), '1 day');
|
||||
assert.equal($elem.data('format'), "medium");
|
||||
assert.equal($elem.data('time'), d.getTime());
|
||||
assert.equal($elem.attr('title'), undefined);
|
||||
assert.equal($elem.html(), '1 day');
|
||||
});
|
||||
|
||||
test("updateRelativeAge", function(){
|
||||
QUnit.test("updateRelativeAge", assert =>{
|
||||
|
||||
var d = new Date();
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
|
@ -180,7 +180,7 @@ test("updateRelativeAge", function(){
|
|||
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2m");
|
||||
assert.equal($elem.html(), "2m");
|
||||
|
||||
d = new Date();
|
||||
$elem = $(autoUpdatingRelativeAge(d, {format: 'medium', leaveAgo: true}));
|
||||
|
@ -188,27 +188,27 @@ test("updateRelativeAge", function(){
|
|||
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2 mins ago");
|
||||
assert.equal($elem.html(), "2 mins ago");
|
||||
});
|
||||
|
||||
test("breakUp", function(){
|
||||
QUnit.test("breakUp", assert =>{
|
||||
|
||||
var b = function(s,hint){ return breakUp(s,hint); };
|
||||
|
||||
equal(b("hello"), "hello");
|
||||
equal(b("helloworld"), "helloworld");
|
||||
equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
||||
equal(b("he_man"), "he_<wbr>​man");
|
||||
equal(b("he11111"), "he<wbr>​11111");
|
||||
equal(b("HRCBob"), "HRC<wbr>​Bob");
|
||||
equal(b("bobmarleytoo","Bob Marley Too"), "bob<wbr>​marley<wbr>​too");
|
||||
assert.equal(b("hello"), "hello");
|
||||
assert.equal(b("helloworld"), "helloworld");
|
||||
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
||||
assert.equal(b("he_man"), "he_<wbr>​man");
|
||||
assert.equal(b("he11111"), "he<wbr>​11111");
|
||||
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
||||
assert.equal(b("bobmarleytoo","Bob Marley Too"), "bob<wbr>​marley<wbr>​too");
|
||||
|
||||
});
|
||||
|
||||
test("number", function() {
|
||||
equal(number(123), "123", "it returns a string version of the number");
|
||||
equal(number("123"), "123", "it works with a string command");
|
||||
equal(number(NaN), "0", "it returns 0 for NaN");
|
||||
equal(number(3333), "3.3k", "it abbreviates thousands");
|
||||
equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
});
|
||||
QUnit.test("number", assert => {
|
||||
assert.equal(number(123), "123", "it returns a string version of the number");
|
||||
assert.equal(number("123"), "123", "it works with a string command");
|
||||
assert.equal(number(NaN), "0", "it returns 0 for NaN");
|
||||
assert.equal(number(3333), "3.3k", "it abbreviates thousands");
|
||||
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
});
|
|
@ -1,8 +1,8 @@
|
|||
module("lib:i18n", {
|
||||
QUnit.module("lib:i18n", {
|
||||
_locale: I18n.locale,
|
||||
_translations: I18n.translations,
|
||||
|
||||
setup() {
|
||||
beforeEach() {
|
||||
I18n.locale = "fr";
|
||||
|
||||
I18n.translations = {
|
||||
|
@ -54,42 +54,42 @@ module("lib:i18n", {
|
|||
};
|
||||
},
|
||||
|
||||
teardown() {
|
||||
afterEach() {
|
||||
I18n.locale = this._locale;
|
||||
I18n.translations = this._translations;
|
||||
}
|
||||
});
|
||||
|
||||
test("defaults", function() {
|
||||
equal(I18n.defaultLocale, "en", "it has English as default locale");
|
||||
ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
||||
QUnit.test("defaults", assert => {
|
||||
assert.equal(I18n.defaultLocale, "en", "it has English as default locale");
|
||||
assert.ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
||||
});
|
||||
|
||||
test("translations", function() {
|
||||
equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
||||
equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
||||
equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
||||
equal(I18n.t("hello.universe"), "", "allows empty strings");
|
||||
QUnit.test("translations", assert => {
|
||||
assert.equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
||||
assert.equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
||||
assert.equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
||||
assert.equal(I18n.t("hello.universe"), "", "allows empty strings");
|
||||
});
|
||||
|
||||
test("extra translations", function() {
|
||||
QUnit.test("extra translations", assert => {
|
||||
I18n.extras = [{ "admin": { "title": "Discourse Admin" }}];
|
||||
|
||||
equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||
assert.equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||
});
|
||||
|
||||
test("pluralizations", function() {
|
||||
equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
||||
equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
||||
equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
||||
equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
||||
equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
||||
equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
||||
QUnit.test("pluralizations", assert => {
|
||||
assert.equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
||||
assert.equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
||||
assert.equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
||||
assert.equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
||||
assert.equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
||||
assert.equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
||||
|
||||
equal(I18n.t("word_count", { count: 0 }), "0 words");
|
||||
equal(I18n.t("word_count", { count: 1 }), "1 word");
|
||||
equal(I18n.t("word_count", { count: 2 }), "2 words");
|
||||
equal(I18n.t("word_count", { count: 3 }), "3 words");
|
||||
equal(I18n.t("word_count", { count: 10 }), "10 words");
|
||||
equal(I18n.t("word_count", { count: 100 }), "100 words");
|
||||
});
|
||||
assert.equal(I18n.t("word_count", { count: 0 }), "0 words");
|
||||
assert.equal(I18n.t("word_count", { count: 1 }), "1 word");
|
||||
assert.equal(I18n.t("word_count", { count: 2 }), "2 words");
|
||||
assert.equal(I18n.t("word_count", { count: 3 }), "3 words");
|
||||
assert.equal(I18n.t("word_count", { count: 10 }), "10 words");
|
||||
assert.equal(I18n.t("word_count", { count: 100 }), "100 words");
|
||||
});
|
|
@ -1,18 +1,18 @@
|
|||
import KeyValueStore from "discourse/lib/key-value-store";
|
||||
|
||||
module("lib:key-value-store");
|
||||
QUnit.module("lib:key-value-store");
|
||||
|
||||
test("it's able to get the result back from the store", (assert) => {
|
||||
QUnit.test("it's able to get the result back from the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob", value: "uncle" });
|
||||
assert.equal(store.get("bob"), "uncle");
|
||||
});
|
||||
|
||||
test("is able to nuke the store", (assert) => {
|
||||
QUnit.test("is able to nuke the store", (assert) => {
|
||||
const store = new KeyValueStore("_test");
|
||||
store.set({ key: "bob1", value: "uncle" });
|
||||
store.abandonLocal();
|
||||
localStorage.a = 1;
|
||||
assert.equal(store.get("bob1"), void 0);
|
||||
assert.equal(localStorage.a, "1");
|
||||
});
|
||||
});
|
|
@ -1,74 +1,78 @@
|
|||
import { blank } from 'helpers/qunit-helpers';
|
||||
import PreloadStore from 'preload-store';
|
||||
|
||||
module("preload-store", {
|
||||
setup() {
|
||||
QUnit.module("preload-store", {
|
||||
beforeEach() {
|
||||
PreloadStore.store('bane', 'evil');
|
||||
}
|
||||
});
|
||||
|
||||
test("get", function() {
|
||||
blank(PreloadStore.get('joker'), "returns blank for a missing key");
|
||||
equal(PreloadStore.get('bane'), 'evil', "returns the value for that key");
|
||||
QUnit.test("get", assert => {
|
||||
assert.blank(PreloadStore.get('joker'), "returns blank for a missing key");
|
||||
assert.equal(PreloadStore.get('bane'), 'evil', "returns the value for that key");
|
||||
});
|
||||
|
||||
test("remove", function() {
|
||||
QUnit.test("remove", assert => {
|
||||
PreloadStore.remove('bane');
|
||||
blank(PreloadStore.get('bane'), "removes the value if the key exists");
|
||||
assert.blank(PreloadStore.get('bane'), "removes the value if the key exists");
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker').then(function(result) {
|
||||
blank(result);
|
||||
start();
|
||||
assert.blank(result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() { return 'batdance'; };
|
||||
const done = assert.async();
|
||||
const finder = function() { return 'batdance'; };
|
||||
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
||||
equal(result, 'batdance');
|
||||
start();
|
||||
assert.equal(result, 'batdance');
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() {
|
||||
const finder = function() {
|
||||
return new Ember.RSVP.Promise(function(resolve) { resolve('hahahah'); });
|
||||
};
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
||||
equal(result, 'hahahah');
|
||||
start();
|
||||
assert.equal(result, 'hahahah');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var finder = function() {
|
||||
const finder = function() {
|
||||
return new Ember.RSVP.Promise(function(resolve, reject) { reject('error'); });
|
||||
};
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('joker', finder).then(null, function(result) {
|
||||
equal(result, 'error');
|
||||
start();
|
||||
assert.equal(result, 'error');
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
asyncTestDiscourse("returns a promise that resolves to 'evil'", function() {
|
||||
expect(1);
|
||||
asyncTestDiscourse("returns a promise that resolves to 'evil'", function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const done = assert.async();
|
||||
PreloadStore.getAndRemove('bane').then(function(result) {
|
||||
equal(result, 'evil');
|
||||
start();
|
||||
assert.equal(result, 'evil');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ import Post from 'discourse/models/post';
|
|||
import { default as PrettyText, buildOptions } from 'pretty-text/pretty-text';
|
||||
import { IMAGE_VERSION as v} from 'pretty-text/emoji';
|
||||
|
||||
module("lib:pretty-text");
|
||||
QUnit.module("lib:pretty-text");
|
||||
|
||||
const defaultOpts = buildOptions({
|
||||
siteSettings: {
|
||||
|
@ -17,602 +17,614 @@ const defaultOpts = buildOptions({
|
|||
getURL: url => url
|
||||
});
|
||||
|
||||
function cooked(input, expected, text) {
|
||||
equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
QUnit.assert.cooked = function(input, expected, message) {
|
||||
const actual = new PrettyText(defaultOpts).cook(input);
|
||||
this.pushResult({
|
||||
result: actual === expected.replace(/\/>/g, ">"),
|
||||
actual,
|
||||
expected,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function cookedOptions(input, opts, expected, text) {
|
||||
equal(new PrettyText(_.merge({}, defaultOpts, opts)).cook(input), expected, text);
|
||||
QUnit.assert.cookedOptions = function(input, opts, expected, message) {
|
||||
const actual = new PrettyText(_.merge({}, defaultOpts, opts)).cook(input);
|
||||
this.pushResult({
|
||||
result: actual === expected,
|
||||
actual,
|
||||
expected,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
function cookedPara(input, expected, text) {
|
||||
cooked(input, `<p>${expected}</p>`, text);
|
||||
QUnit.assert.cookedPara = function(input, expected, message) {
|
||||
QUnit.assert.cooked(input, `<p>${expected}</p>`, message);
|
||||
};
|
||||
|
||||
test("buildOptions", () => {
|
||||
ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled');
|
||||
ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled');
|
||||
QUnit.test("buildOptions", assert => {
|
||||
assert.ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled');
|
||||
|
||||
ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled');
|
||||
ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled');
|
||||
assert.ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled');
|
||||
assert.ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled');
|
||||
});
|
||||
|
||||
test("basic cooking", function() {
|
||||
cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
||||
cooked("**evil**", "<p><strong>evil</strong></p>", "it bolds text.");
|
||||
cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
||||
cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
|
||||
cooked("word_with_underscores", "<p>word_with_underscores</p>", "it doesn't do intraword italics");
|
||||
cooked("common/_special_font_face.html.erb", "<p>common/_special_font_face.html.erb</p>", "it doesn't intraword with a slash");
|
||||
cooked("hello \\*evil\\*", "<p>hello *evil*</p>", "it supports escaping of asterisks");
|
||||
cooked("hello \\_evil\\_", "<p>hello _evil_</p>", "it supports escaping of italics");
|
||||
cooked("brussels sprouts are *awful*.", "<p>brussels sprouts are <em>awful</em>.</p>", "it doesn't swallow periods.");
|
||||
QUnit.test("basic cooking", assert => {
|
||||
assert.cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
||||
assert.cooked("**evil**", "<p><strong>evil</strong></p>", "it bolds text.");
|
||||
assert.cooked("__bold__", "<p><strong>bold</strong></p>", "it bolds text.");
|
||||
assert.cooked("*trout*", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
assert.cooked("_trout_", "<p><em>trout</em></p>", "it italicizes text.");
|
||||
assert.cooked("***hello***", "<p><strong><em>hello</em></strong></p>", "it can do bold and italics at once.");
|
||||
assert.cooked("word_with_underscores", "<p>word_with_underscores</p>", "it doesn't do intraword italics");
|
||||
assert.cooked("common/_special_font_face.html.erb", "<p>common/_special_font_face.html.erb</p>", "it doesn't intraword with a slash");
|
||||
assert.cooked("hello \\*evil\\*", "<p>hello *evil*</p>", "it supports escaping of asterisks");
|
||||
assert.cooked("hello \\_evil\\_", "<p>hello _evil_</p>", "it supports escaping of italics");
|
||||
assert.cooked("brussels sprouts are *awful*.", "<p>brussels sprouts are <em>awful</em>.</p>", "it doesn't swallow periods.");
|
||||
});
|
||||
|
||||
test("Nested bold and italics", function() {
|
||||
cooked("*this is italic **with some bold** inside*", "<p><em>this is italic <strong>with some bold</strong> inside</em></p>", "it handles nested bold in italics");
|
||||
QUnit.test("Nested bold and italics", assert => {
|
||||
assert.cooked("*this is italic **with some bold** inside*", "<p><em>this is italic <strong>with some bold</strong> inside</em></p>", "it handles nested bold in italics");
|
||||
});
|
||||
|
||||
test("Traditional Line Breaks", function() {
|
||||
QUnit.test("Traditional Line Breaks", assert => {
|
||||
const input = "1\n2\n3";
|
||||
cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
assert.cooked(input, "<p>1<br/>2<br/>3</p>", "automatically handles trivial newlines");
|
||||
|
||||
const result = new PrettyText({ traditionalMarkdownLinebreaks: true }).cook(input);
|
||||
equal(result, "<p>1\n2\n3</p>");
|
||||
assert.equal(result, "<p>1\n2\n3</p>");
|
||||
});
|
||||
|
||||
test("Unbalanced underscores", function() {
|
||||
cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "<p><a href=\"http://eviltrout.com\">evil_trout</a> hello_</p>");
|
||||
QUnit.test("Unbalanced underscores", assert => {
|
||||
assert.cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "<p><a href=\"http://eviltrout.com\">evil_trout</a> hello_</p>");
|
||||
});
|
||||
|
||||
test("Line Breaks", function() {
|
||||
cooked("[] first choice\n[] second choice",
|
||||
QUnit.test("Line Breaks", assert => {
|
||||
assert.cooked("[] first choice\n[] second choice",
|
||||
"<p>[] first choice<br/>[] second choice</p>",
|
||||
"it handles new lines correctly with [] options");
|
||||
|
||||
cooked("<blockquote>evil</blockquote>\ntrout",
|
||||
assert.cooked("<blockquote>evil</blockquote>\ntrout",
|
||||
"<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"it doesn't insert <br> after blockquotes");
|
||||
|
||||
cooked("leading<blockquote>evil</blockquote>\ntrout",
|
||||
assert.cooked("leading<blockquote>evil</blockquote>\ntrout",
|
||||
"leading<blockquote>evil</blockquote>\n\n<p>trout</p>",
|
||||
"it doesn't insert <br> after blockquotes with leading text");
|
||||
});
|
||||
|
||||
test("Paragraphs for HTML", function() {
|
||||
cooked("<div>hello world</div>", "<div>hello world</div>", "it doesn't surround <div> with paragraphs");
|
||||
cooked("<p>hello world</p>", "<p>hello world</p>", "it doesn't surround <p> with paragraphs");
|
||||
cooked("<i>hello world</i>", "<p><i>hello world</i></p>", "it surrounds inline <i> html tags with paragraphs");
|
||||
cooked("<b>hello world</b>", "<p><b>hello world</b></p>", "it surrounds inline <b> html tags with paragraphs");
|
||||
QUnit.test("Paragraphs for HTML", assert => {
|
||||
assert.cooked("<div>hello world</div>", "<div>hello world</div>", "it doesn't surround <div> with paragraphs");
|
||||
assert.cooked("<p>hello world</p>", "<p>hello world</p>", "it doesn't surround <p> with paragraphs");
|
||||
assert.cooked("<i>hello world</i>", "<p><i>hello world</i></p>", "it surrounds inline <i> html tags with paragraphs");
|
||||
assert.cooked("<b>hello world</b>", "<p><b>hello world</b></p>", "it surrounds inline <b> html tags with paragraphs");
|
||||
});
|
||||
|
||||
test("Links", function() {
|
||||
QUnit.test("Links", assert => {
|
||||
|
||||
cooked("EvilTrout: http://eviltrout.com",
|
||||
assert.cooked("EvilTrout: http://eviltrout.com",
|
||||
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>',
|
||||
"autolinks a URL");
|
||||
|
||||
cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A",
|
||||
assert.cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A",
|
||||
'<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>',
|
||||
"allows links to contain query params");
|
||||
|
||||
cooked("Derpy: http://derp.com?__test=1",
|
||||
assert.cooked("Derpy: http://derp.com?__test=1",
|
||||
'<p>Derpy: <a href="http://derp.com?__test=1">http://derp.com?__test=1</a></p>',
|
||||
"works with double underscores in urls");
|
||||
|
||||
cooked("Derpy: http://derp.com?_test_=1",
|
||||
assert.cooked("Derpy: http://derp.com?_test_=1",
|
||||
'<p>Derpy: <a href="http://derp.com?_test_=1">http://derp.com?_test_=1</a></p>',
|
||||
"works with underscores in urls");
|
||||
|
||||
cooked("Atwood: www.codinghorror.com",
|
||||
assert.cooked("Atwood: www.codinghorror.com",
|
||||
'<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>',
|
||||
"autolinks something that begins with www");
|
||||
|
||||
cooked("Atwood: http://www.codinghorror.com",
|
||||
assert.cooked("Atwood: http://www.codinghorror.com",
|
||||
'<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>',
|
||||
"autolinks a URL with http://www");
|
||||
|
||||
cooked("EvilTrout: http://eviltrout.com hello",
|
||||
assert.cooked("EvilTrout: http://eviltrout.com hello",
|
||||
'<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a> hello</p>',
|
||||
"autolinks with trailing text");
|
||||
|
||||
cooked("here is [an example](http://twitter.com)",
|
||||
assert.cooked("here is [an example](http://twitter.com)",
|
||||
'<p>here is <a href="http://twitter.com">an example</a></p>',
|
||||
"supports markdown style links");
|
||||
|
||||
cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
|
||||
assert.cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)",
|
||||
'<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>',
|
||||
"autolinks a URL with parentheses (like Wikipedia)");
|
||||
|
||||
cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
||||
assert.cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200",
|
||||
"<p>Here's a tweet:<br/><a href=\"https://twitter.com/evil_trout/status/345954894420787200\" class=\"onebox\" target=\"_blank\">https://twitter.com/evil_trout/status/345954894420787200</a></p>",
|
||||
"It doesn't strip the new line.");
|
||||
|
||||
cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
||||
assert.cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity<br/>next line.",
|
||||
"<ol><li>View <span class=\"mention\">@eviltrout</span>'s profile here: <a href=\"http://meta.discourse.org/u/eviltrout/activity\">http://meta.discourse.org/u/eviltrout/activity</a><br>next line.</li></ol>",
|
||||
"allows autolinking within a list without inserting a paragraph.");
|
||||
|
||||
cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
|
||||
assert.cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references");
|
||||
|
||||
cooked("[]: http://eviltrout.com", "<p>[]: <a href=\"http://eviltrout.com\">http://eviltrout.com</a></p>", "It doesn't accept empty link references");
|
||||
assert.cooked("[]: http://eviltrout.com", "<p>[]: <a href=\"http://eviltrout.com\">http://eviltrout.com</a></p>", "It doesn't accept empty link references");
|
||||
|
||||
cooked("[b]label[/b]: description", "<p><span class=\"bbcode-b\">label</span>: description</p>", "It doesn't accept BBCode as link references");
|
||||
assert.cooked("[b]label[/b]: description", "<p><span class=\"bbcode-b\">label</span>: description</p>", "It doesn't accept BBCode as link references");
|
||||
|
||||
cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
|
||||
assert.cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369",
|
||||
"<p><a href=\"http://discourse.org\">http://discourse.org</a> and " +
|
||||
"<a href=\"http://discourse.org/another_url\">http://discourse.org/another_url</a> and " +
|
||||
"<a href=\"http://www.imdb.com/name/nm2225369\">http://www.imdb.com/name/nm2225369</a></p>",
|
||||
'allows multiple links on one line');
|
||||
|
||||
cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com",
|
||||
assert.cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com",
|
||||
"<ul><li><a href=\"http://eviltrout.com\">Evil Trout</a></li></ul>",
|
||||
"allows markdown link references in a list");
|
||||
|
||||
cooked("User [MOD]: Hello!",
|
||||
assert.cooked("User [MOD]: Hello!",
|
||||
"<p>User [MOD]: Hello!</p>",
|
||||
"It does not consider references that are obviously not URLs");
|
||||
|
||||
cooked("<small>http://eviltrout.com</small>", "<p><small><a href=\"http://eviltrout.com\">http://eviltrout.com</a></small></p>", "Links within HTML tags");
|
||||
assert.cooked("<small>http://eviltrout.com</small>", "<p><small><a href=\"http://eviltrout.com\">http://eviltrout.com</a></small></p>", "Links within HTML tags");
|
||||
|
||||
cooked("[http://google.com ... wat](http://discourse.org)",
|
||||
assert.cooked("[http://google.com ... wat](http://discourse.org)",
|
||||
"<p><a href=\"http://discourse.org\">http://google.com ... wat</a></p>",
|
||||
"it supports links within links");
|
||||
|
||||
cooked("[http://google.com](http://discourse.org)",
|
||||
assert.cooked("[http://google.com](http://discourse.org)",
|
||||
"<p><a href=\"http://discourse.org\">http://google.com</a></p>",
|
||||
"it supports markdown links where the name and link match");
|
||||
|
||||
|
||||
cooked("[Link](http://www.example.com) (with an outer \"description\")",
|
||||
assert.cooked("[Link](http://www.example.com) (with an outer \"description\")",
|
||||
"<p><a href=\"http://www.example.com\">Link</a> (with an outer \"description\")</p>",
|
||||
"it doesn't consume closing parens as part of the url");
|
||||
|
||||
cooked("A link inside parentheses (http://www.example.com)",
|
||||
assert.cooked("A link inside parentheses (http://www.example.com)",
|
||||
"<p>A link inside parentheses (<a href=\"http://www.example.com\">http://www.example.com</a>)</p>",
|
||||
"it auto-links a url within parentheses");
|
||||
|
||||
cooked("[ul][1]\n\n[1]: http://eviltrout.com",
|
||||
assert.cooked("[ul][1]\n\n[1]: http://eviltrout.com",
|
||||
"<p><a href=\"http://eviltrout.com\">ul</a></p>",
|
||||
"it can use `ul` as a link name");
|
||||
});
|
||||
|
||||
test("simple quotes", function() {
|
||||
cooked("> nice!", "<blockquote><p>nice!</p></blockquote>", "it supports simple quotes");
|
||||
cooked(" > nice!", "<blockquote><p>nice!</p></blockquote>", "it allows quotes with preceding spaces");
|
||||
cooked("> level 1\n> > level 2",
|
||||
QUnit.test("simple quotes", assert => {
|
||||
assert.cooked("> nice!", "<blockquote><p>nice!</p></blockquote>", "it supports simple quotes");
|
||||
assert.cooked(" > nice!", "<blockquote><p>nice!</p></blockquote>", "it allows quotes with preceding spaces");
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"it allows nesting of blockquotes");
|
||||
cooked("> level 1\n> > level 2",
|
||||
assert.cooked("> level 1\n> > level 2",
|
||||
"<blockquote><p>level 1</p><blockquote><p>level 2</p></blockquote></blockquote>",
|
||||
"it allows nesting of blockquotes with spaces");
|
||||
|
||||
cooked("- hello\n\n > world\n > eviltrout",
|
||||
assert.cooked("- hello\n\n > world\n > eviltrout",
|
||||
"<ul><li>hello</li></ul>\n\n<blockquote><p>world<br/>eviltrout</p></blockquote>",
|
||||
"it allows quotes within a list.");
|
||||
|
||||
cooked("- <p>eviltrout</p>",
|
||||
assert.cooked("- <p>eviltrout</p>",
|
||||
"<ul><li><p>eviltrout</p></li></ul>",
|
||||
"it allows paragraphs within a list.");
|
||||
|
||||
|
||||
cooked(" > indent 1\n > indent 2", "<blockquote><p>indent 1<br/>indent 2</p></blockquote>", "allow multiple spaces to indent");
|
||||
assert.cooked(" > indent 1\n > indent 2", "<blockquote><p>indent 1<br/>indent 2</p></blockquote>", "allow multiple spaces to indent");
|
||||
|
||||
});
|
||||
|
||||
test("Quotes", function() {
|
||||
QUnit.test("Quotes", assert => {
|
||||
|
||||
cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]",
|
||||
assert.cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]",
|
||||
{ topicId: 2 },
|
||||
"<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:</div><blockquote>" +
|
||||
"<p>a quote</p><p>second line</p><p>third line</p></blockquote></aside>",
|
||||
"works with multiple lines");
|
||||
|
||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
{ topicId: 2, lookupAvatar: function(name) { return "" + name; }, sanitize: true },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob" +
|
||||
"bob:</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
"handles quotes properly");
|
||||
|
||||
cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2",
|
||||
{ topicId: 2, lookupAvatar: function() { } },
|
||||
"<p>1</p>\n\n<aside class=\"quote\" data-post=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>bob:" +
|
||||
"</div><blockquote><p>my quote</p></blockquote></aside>\n\n<p>2</p>",
|
||||
"includes no avatar if none is found");
|
||||
|
||||
cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
||||
assert.cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`,
|
||||
"<p><aside class=\"quote\"><blockquote><p>a</p><p><aside class=\"quote\"><blockquote><p>b</p></blockquote></aside></p></blockquote></aside></p>",
|
||||
"handles nested quotes properly");
|
||||
|
||||
});
|
||||
|
||||
test("Mentions", function() {
|
||||
QUnit.test("Mentions", assert => {
|
||||
|
||||
const alwaysTrue = { mentionLookup: (function() { return "user"; }) };
|
||||
|
||||
cookedOptions("Hello @sam", alwaysTrue,
|
||||
assert.cookedOptions("Hello @sam", alwaysTrue,
|
||||
"<p>Hello <a class=\"mention\" href=\"/u/sam\">@sam</a></p>",
|
||||
"translates mentions to links");
|
||||
|
||||
cooked("[@codinghorror](https://twitter.com/codinghorror)",
|
||||
assert.cooked("[@codinghorror](https://twitter.com/codinghorror)",
|
||||
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||
"it doesn't do mentions within links");
|
||||
|
||||
cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
|
||||
assert.cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
|
||||
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||
"it doesn't do link mentions within links");
|
||||
|
||||
cooked("Hello @EvilTrout",
|
||||
assert.cooked("Hello @EvilTrout",
|
||||
"<p>Hello <span class=\"mention\">@EvilTrout</span></p>",
|
||||
"adds a mention class");
|
||||
|
||||
cooked("robin@email.host",
|
||||
assert.cooked("robin@email.host",
|
||||
"<p>robin@email.host</p>",
|
||||
"won't add mention class to an email address");
|
||||
|
||||
cooked("hanzo55@yahoo.com",
|
||||
assert.cooked("hanzo55@yahoo.com",
|
||||
"<p>hanzo55@yahoo.com</p>",
|
||||
"won't be affected by email addresses that have a number before the @ symbol");
|
||||
|
||||
cooked("@EvilTrout yo",
|
||||
assert.cooked("@EvilTrout yo",
|
||||
"<p><span class=\"mention\">@EvilTrout</span> yo</p>",
|
||||
"it handles mentions at the beginning of a string");
|
||||
|
||||
cooked("yo\n@EvilTrout",
|
||||
assert.cooked("yo\n@EvilTrout",
|
||||
"<p>yo<br/><span class=\"mention\">@EvilTrout</span></p>",
|
||||
"it handles mentions at the beginning of a new line");
|
||||
|
||||
cooked("`evil` @EvilTrout `trout`",
|
||||
assert.cooked("`evil` @EvilTrout `trout`",
|
||||
"<p><code>evil</code> <span class=\"mention\">@EvilTrout</span> <code>trout</code></p>",
|
||||
"deals correctly with multiple <code> blocks");
|
||||
|
||||
cooked("```\na @test\n```",
|
||||
assert.cooked("```\na @test\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a @test</code></pre></p>",
|
||||
"should not do mentions within a code block.");
|
||||
|
||||
cooked("> foo bar baz @eviltrout",
|
||||
assert.cooked("> foo bar baz @eviltrout",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span></p></blockquote>",
|
||||
"handles mentions in simple quotes");
|
||||
|
||||
cooked("> foo bar baz @eviltrout ohmagerd\nlook at this",
|
||||
assert.cooked("> foo bar baz @eviltrout ohmagerd\nlook at this",
|
||||
"<blockquote><p>foo bar baz <span class=\"mention\">@eviltrout</span> ohmagerd<br/>look at this</p></blockquote>",
|
||||
"does mentions properly with trailing text within a simple quote");
|
||||
|
||||
cooked("`code` is okay before @mention",
|
||||
assert.cooked("`code` is okay before @mention",
|
||||
"<p><code>code</code> is okay before <span class=\"mention\">@mention</span></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("@mention is okay before `code`",
|
||||
assert.cooked("@mention is okay before `code`",
|
||||
"<p><span class=\"mention\">@mention</span> is okay before <code>code</code></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("don't `@mention`",
|
||||
assert.cooked("don't `@mention`",
|
||||
"<p>don't <code>@mention</code></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("Yes `@this` should be code @eviltrout",
|
||||
assert.cooked("Yes `@this` should be code @eviltrout",
|
||||
"<p>Yes <code>@this</code> should be code <span class=\"mention\">@eviltrout</span></p>",
|
||||
"Does not mention in an inline code block");
|
||||
|
||||
cooked("@eviltrout and `@eviltrout`",
|
||||
assert.cooked("@eviltrout and `@eviltrout`",
|
||||
"<p><span class=\"mention\">@eviltrout</span> and <code>@eviltrout</code></p>",
|
||||
"you can have a mention in an inline code block following a real mention.");
|
||||
|
||||
cooked("1. this is a list\n\n2. this is an @eviltrout mention\n",
|
||||
assert.cooked("1. this is a list\n\n2. this is an @eviltrout mention\n",
|
||||
"<ol><li><p>this is a list</p></li><li><p>this is an <span class=\"mention\">@eviltrout</span> mention</p></li></ol>",
|
||||
"it mentions properly in a list.");
|
||||
|
||||
cooked("Hello @foo/@bar",
|
||||
assert.cooked("Hello @foo/@bar",
|
||||
"<p>Hello <span class=\"mention\">@foo</span>/<span class=\"mention\">@bar</span></p>",
|
||||
"handles mentions separated by a slash.");
|
||||
|
||||
cookedOptions("@eviltrout", alwaysTrue,
|
||||
assert.cookedOptions("@eviltrout", alwaysTrue,
|
||||
"<p><a class=\"mention\" href=\"/u/eviltrout\">@eviltrout</a></p>",
|
||||
"it doesn't onebox mentions");
|
||||
|
||||
cookedOptions("<small>a @sam c</small>", alwaysTrue,
|
||||
assert.cookedOptions("<small>a @sam c</small>", alwaysTrue,
|
||||
"<p><small>a <a class=\"mention\" href=\"/u/sam\">@sam</a> c</small></p>",
|
||||
"it allows mentions within HTML tags");
|
||||
});
|
||||
|
||||
test("Category hashtags", () => {
|
||||
QUnit.test("Category hashtags", assert => {
|
||||
const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) };
|
||||
|
||||
cookedOptions("Check out #category-hashtag", alwaysTrue,
|
||||
assert.cookedOptions("Check out #category-hashtag", alwaysTrue,
|
||||
"<p>Check out <a class=\"hashtag\" href=\"http://test.discourse.org/category-hashtag\">#<span>category-hashtag</span></a></p>",
|
||||
"it translates category hashtag into links");
|
||||
|
||||
cooked("Check out #category-hashtag",
|
||||
assert.cooked("Check out #category-hashtag",
|
||||
"<p>Check out <span class=\"hashtag\">#category-hashtag</span></p>",
|
||||
"it does not translate category hashtag into links if it is not a valid category hashtag");
|
||||
|
||||
cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
|
||||
assert.cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue,
|
||||
"<p><a href=\"http://www.test.com\">#category-hashtag</a></p>",
|
||||
"it does not translate category hashtag within links");
|
||||
|
||||
cooked("```\n# #category-hashtag\n```",
|
||||
assert.cooked("```\n# #category-hashtag\n```",
|
||||
"<p><pre><code class=\"lang-auto\"># #category-hashtag</code></pre></p>",
|
||||
"it does not translate category hashtags to links in code blocks");
|
||||
|
||||
cooked("># #category-hashtag\n",
|
||||
assert.cooked("># #category-hashtag\n",
|
||||
"<blockquote><h1><span class=\"hashtag\">#category-hashtag</span></h1></blockquote>",
|
||||
"it handles category hashtags in simple quotes");
|
||||
|
||||
cooked("# #category-hashtag",
|
||||
assert.cooked("# #category-hashtag",
|
||||
"<h1><span class=\"hashtag\">#category-hashtag</span></h1>",
|
||||
"it works within ATX-style headers");
|
||||
|
||||
cooked("don't `#category-hashtag`",
|
||||
assert.cooked("don't `#category-hashtag`",
|
||||
"<p>don't <code>#category-hashtag</code></p>",
|
||||
"it does not mention in an inline code block");
|
||||
|
||||
cooked("test #hashtag1/#hashtag2",
|
||||
assert.cooked("test #hashtag1/#hashtag2",
|
||||
"<p>test <span class=\"hashtag\">#hashtag1</span>/#hashtag2</p>",
|
||||
"it does not convert category hashtag not bounded by spaces");
|
||||
|
||||
cooked("<small>#category-hashtag</small>",
|
||||
assert.cooked("<small>#category-hashtag</small>",
|
||||
"<p><small><span class=\"hashtag\">#category-hashtag</span></small></p>",
|
||||
"it works between HTML tags");
|
||||
});
|
||||
|
||||
|
||||
test("Heading", function() {
|
||||
cooked("**Bold**\n----------", "<h2><strong>Bold</strong></h2>", "It will bold the heading");
|
||||
QUnit.test("Heading", assert => {
|
||||
assert.cooked("**Bold**\n----------", "<h2><strong>Bold</strong></h2>", "It will bold the heading");
|
||||
});
|
||||
|
||||
test("bold and italics", function() {
|
||||
cooked("a \"**hello**\"", "<p>a \"<strong>hello</strong>\"</p>", "bolds in quotes");
|
||||
cooked("(**hello**)", "<p>(<strong>hello</strong>)</p>", "bolds in parens");
|
||||
cooked("**hello**\nworld", "<p><strong>hello</strong><br>world</p>", "allows newline after bold");
|
||||
cooked("**hello**\n**world**", "<p><strong>hello</strong><br><strong>world</strong></p>", "newline between two bolds");
|
||||
cooked("**a*_b**", "<p><strong>a*_b</strong></p>", "allows for characters within bold");
|
||||
cooked("** hello**", "<p>** hello**</p>", "does not bold on a space boundary");
|
||||
cooked("**hello **", "<p>**hello **</p>", "does not bold on a space boundary");
|
||||
cooked("你**hello**", "<p>你**hello**</p>", "does not bold chinese intra word");
|
||||
cooked("**你hello**", "<p><strong>你hello</strong></p>", "allows bolded chinese");
|
||||
QUnit.test("bold and italics", assert => {
|
||||
assert.cooked("a \"**hello**\"", "<p>a \"<strong>hello</strong>\"</p>", "bolds in quotes");
|
||||
assert.cooked("(**hello**)", "<p>(<strong>hello</strong>)</p>", "bolds in parens");
|
||||
assert.cooked("**hello**\nworld", "<p><strong>hello</strong><br>world</p>", "allows newline after bold");
|
||||
assert.cooked("**hello**\n**world**", "<p><strong>hello</strong><br><strong>world</strong></p>", "newline between two bolds");
|
||||
assert.cooked("**a*_b**", "<p><strong>a*_b</strong></p>", "allows for characters within bold");
|
||||
assert.cooked("** hello**", "<p>** hello**</p>", "does not bold on a space boundary");
|
||||
assert.cooked("**hello **", "<p>**hello **</p>", "does not bold on a space boundary");
|
||||
assert.cooked("你**hello**", "<p>你**hello**</p>", "does not bold chinese intra word");
|
||||
assert.cooked("**你hello**", "<p><strong>你hello</strong></p>", "allows bolded chinese");
|
||||
});
|
||||
|
||||
test("Escaping", function() {
|
||||
cooked("*\\*laughs\\**", "<p><em>*laughs*</em></p>", "allows escaping strong");
|
||||
cooked("*\\_laughs\\_*", "<p><em>_laughs_</em></p>", "allows escaping em");
|
||||
QUnit.test("Escaping", assert => {
|
||||
assert.cooked("*\\*laughs\\**", "<p><em>*laughs*</em></p>", "allows escaping strong");
|
||||
assert.cooked("*\\_laughs\\_*", "<p><em>_laughs_</em></p>", "allows escaping em");
|
||||
});
|
||||
|
||||
test("New Lines", function() {
|
||||
QUnit.test("New Lines", assert => {
|
||||
// Note: This behavior was discussed and we determined it does not make sense to do this
|
||||
// unless you're using traditional line breaks
|
||||
cooked("_abc\ndef_", "<p>_abc<br>def_</p>", "it does not allow markup to span new lines");
|
||||
cooked("_abc\n\ndef_", "<p>_abc</p>\n\n<p>def_</p>", "it does not allow markup to span new paragraphs");
|
||||
assert.cooked("_abc\ndef_", "<p>_abc<br>def_</p>", "it does not allow markup to span new lines");
|
||||
assert.cooked("_abc\n\ndef_", "<p>_abc</p>\n\n<p>def_</p>", "it does not allow markup to span new paragraphs");
|
||||
});
|
||||
|
||||
test("Oneboxing", function() {
|
||||
QUnit.test("Oneboxing", assert => {
|
||||
|
||||
function matches(input, regexp) {
|
||||
return new PrettyText(defaultOpts).cook(input).match(regexp);
|
||||
};
|
||||
|
||||
ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/),
|
||||
assert.ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/),
|
||||
"doesn't onebox a link within a list");
|
||||
|
||||
ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line");
|
||||
ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
|
||||
ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
|
||||
assert.ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line");
|
||||
assert.ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
|
||||
assert.ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
|
||||
|
||||
ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
|
||||
ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
assert.ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
|
||||
assert.ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
|
||||
"onebox"),
|
||||
"Markdown links where the label is the same as the url are oneboxed");
|
||||
|
||||
cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
||||
assert.cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
|
||||
"<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\"" +
|
||||
" target=\"_blank\">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>",
|
||||
"works with links that have underscores in them");
|
||||
|
||||
});
|
||||
|
||||
test("links with full urls", function() {
|
||||
cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
|
||||
QUnit.test("links with full urls", assert => {
|
||||
assert.cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com",
|
||||
"<p><a href=\"http://eviltrout.com\">http://eviltrout.com</a> is a url</p>",
|
||||
"it supports links that are full URLs");
|
||||
});
|
||||
|
||||
test("Code Blocks", function() {
|
||||
QUnit.test("Code Blocks", assert => {
|
||||
|
||||
cooked("<pre>\nhello\n</pre>\n",
|
||||
assert.cooked("<pre>\nhello\n</pre>\n",
|
||||
"<p><pre>hello</pre></p>",
|
||||
"pre blocks don't include extra lines");
|
||||
|
||||
cooked("```\na\nb\nc\n\nd\n```",
|
||||
assert.cooked("```\na\nb\nc\n\nd\n```",
|
||||
"<p><pre><code class=\"lang-auto\">a\nb\nc\n\nd</code></pre></p>",
|
||||
"it treats new lines properly");
|
||||
|
||||
cooked("```\ntest\n```",
|
||||
assert.cooked("```\ntest\n```",
|
||||
"<p><pre><code class=\"lang-auto\">test</code></pre></p>",
|
||||
"it supports basic code blocks");
|
||||
|
||||
cooked("```json\n{hello: 'world'}\n```\ntrailing",
|
||||
assert.cooked("```json\n{hello: 'world'}\n```\ntrailing",
|
||||
"<p><pre><code class=\"lang-json\">{hello: 'world'}</code></pre></p>\n\n<p>trailing</p>",
|
||||
"It does not truncate text after a code block.");
|
||||
|
||||
cooked("```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
assert.cooked("```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"it maintains new lines inside a code block.");
|
||||
|
||||
cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
assert.cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```",
|
||||
"<p>hello<br/>world<br/></p>\n\n<p><pre><code class=\"lang-json\">line 1\n\nline 2\n\n\nline3</code></pre></p>",
|
||||
"it maintains new lines inside a code block with leading content.");
|
||||
|
||||
cooked("```ruby\n<header>hello</header>\n```",
|
||||
assert.cooked("```ruby\n<header>hello</header>\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"><header>hello</header></code></pre></p>",
|
||||
"it escapes code in the code block");
|
||||
|
||||
cooked("```text\ntext\n```",
|
||||
assert.cooked("```text\ntext\n```",
|
||||
"<p><pre><code class=\"lang-nohighlight\">text</code></pre></p>",
|
||||
"handles text by adding nohighlight");
|
||||
|
||||
cooked("```ruby\n# cool\n```",
|
||||
assert.cooked("```ruby\n# cool\n```",
|
||||
"<p><pre><code class=\"lang-ruby\"># cool</code></pre></p>",
|
||||
"it supports changing the language");
|
||||
|
||||
cooked(" ```\n hello\n ```",
|
||||
assert.cooked(" ```\n hello\n ```",
|
||||
"<pre><code>```\nhello\n```</code></pre>",
|
||||
"only detect ``` at the beginning of lines");
|
||||
|
||||
cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
||||
assert.cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">def self.parse(text)\n\n text\nend</code></pre></p>",
|
||||
"it allows leading spaces on lines in a code block.");
|
||||
|
||||
cooked("```ruby\nhello `eviltrout`\n```",
|
||||
assert.cooked("```ruby\nhello `eviltrout`\n```",
|
||||
"<p><pre><code class=\"lang-ruby\">hello `eviltrout`</code></pre></p>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
cooked("```eviltrout\nhello\n```",
|
||||
assert.cooked("```eviltrout\nhello\n```",
|
||||
"<p><pre><code class=\"lang-auto\">hello</code></pre></p>",
|
||||
"it doesn't not whitelist all classes");
|
||||
|
||||
cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]\n```",
|
||||
assert.cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `<not>` a bug.[/quote]\n```",
|
||||
"<p><pre><code class=\"lang-auto\">[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]</code></pre></p>",
|
||||
"it allows code with backticks in it");
|
||||
|
||||
cooked(" hello\n<blockquote>test</blockquote>",
|
||||
assert.cooked(" hello\n<blockquote>test</blockquote>",
|
||||
"<pre><code>hello</code></pre>\n\n<blockquote>test</blockquote>",
|
||||
"it allows an indented code block to by followed by a `<blockquote>`");
|
||||
|
||||
cooked("``` foo bar ```",
|
||||
assert.cooked("``` foo bar ```",
|
||||
"<p><code>foo bar</code></p>",
|
||||
"it tolerates misuse of code block tags as inline code");
|
||||
|
||||
cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
|
||||
assert.cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
|
||||
"<p><pre><code class=\"lang-auto\">line1</code></pre></p>\n\n<p><pre><code class=\"lang-auto\">line2\n\nline3</code></pre></p>",
|
||||
"it does not consume next block's trailing newlines");
|
||||
|
||||
cooked(" <pre>test</pre>",
|
||||
assert.cooked(" <pre>test</pre>",
|
||||
"<pre><code><pre>test</pre></code></pre>",
|
||||
"it does not parse other block types in markdown code blocks");
|
||||
|
||||
cooked(" [quote]test[/quote]",
|
||||
assert.cooked(" [quote]test[/quote]",
|
||||
"<pre><code>[quote]test[/quote]</code></pre>",
|
||||
"it does not parse other block types in markdown code blocks");
|
||||
|
||||
cooked("## a\nb\n```\nc\n```",
|
||||
assert.cooked("## a\nb\n```\nc\n```",
|
||||
"<h2>a</h2>\n\n<p><pre><code class=\"lang-auto\">c</code></pre></p>",
|
||||
"it handles headings with code blocks after them.");
|
||||
});
|
||||
|
||||
test("URLs in BBCode tags", function() {
|
||||
QUnit.test("URLs in BBCode tags", assert => {
|
||||
|
||||
cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
||||
assert.cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]",
|
||||
"<p><img src=\"http://eviltrout.com/eviltrout.png\"/><img src=\"http://samsaffron.com/samsaffron.png\"/></p>",
|
||||
"images are properly parsed");
|
||||
|
||||
cooked("[url]http://discourse.org[/url]",
|
||||
assert.cooked("[url]http://discourse.org[/url]",
|
||||
"<p><a href=\"http://discourse.org\">http://discourse.org</a></p>",
|
||||
"links are properly parsed");
|
||||
|
||||
cooked("[url=http://discourse.org]discourse[/url]",
|
||||
assert.cooked("[url=http://discourse.org]discourse[/url]",
|
||||
"<p><a href=\"http://discourse.org\">discourse</a></p>",
|
||||
"named links are properly parsed");
|
||||
|
||||
});
|
||||
|
||||
test("images", function() {
|
||||
cooked("[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)",
|
||||
QUnit.test("images", assert => {
|
||||
assert.cooked("[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)",
|
||||
"<p><a href=\"http://folksy.com/\"><img src=\"http://folksy.com/images/folksy-colour.png\" alt=\"folksy logo\"/></a></p>",
|
||||
"It allows images with links around them");
|
||||
|
||||
cooked("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">",
|
||||
assert.cooked("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\">",
|
||||
"<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==\" alt=\"Red dot\"></p>",
|
||||
"It allows data images");
|
||||
});
|
||||
|
||||
test("censoring", function() {
|
||||
cooked("aw shucks, golly gee whiz.",
|
||||
QUnit.test("censoring", assert => {
|
||||
assert.cooked("aw shucks, golly gee whiz.",
|
||||
"<p>aw ■■■■■■, golly gee ■■■■.</p>",
|
||||
"it censors words in the Site Settings");
|
||||
|
||||
cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||
assert.cooked("you are a whizzard! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a whizzard! I love cheesewhiz. ■■■■.</p>",
|
||||
"it doesn't censor words unless they have boundaries.");
|
||||
|
||||
cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||
assert.cooked("you are a whizzer! I love cheesewhiz. Whiz.",
|
||||
"<p>you are a ■■■■■■■! I love cheesewhiz. ■■■■.</p>",
|
||||
"it censors words even if previous partial matches exist.");
|
||||
|
||||
cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||
assert.cooked("The link still works. [whiz](http://www.whiz.com)",
|
||||
"<p>The link still works. <a href=\"http://www.whiz.com\">■■■■</a></p>",
|
||||
"it won't break links by censoring them.");
|
||||
|
||||
cooked("Call techapj the computer whiz at 555-555-1234 for free help.",
|
||||
assert.cooked("Call techapj the computer whiz at 555-555-1234 for free help.",
|
||||
"<p>Call ■■■■■■■ the computer ■■■■ at 555-■■■■■■■■ for free help.</p>",
|
||||
"uses both censored words and patterns from site settings");
|
||||
|
||||
cooked("I have a pen, I have an a**le",
|
||||
assert.cooked("I have a pen, I have an a**le",
|
||||
"<p>I have a pen, I have an ■■■■■</p>",
|
||||
"it escapes regexp chars");
|
||||
});
|
||||
|
||||
test("code blocks/spans hoisting", function() {
|
||||
cooked("```\n\n some code\n```",
|
||||
QUnit.test("code blocks/spans hoisting", assert => {
|
||||
assert.cooked("```\n\n some code\n```",
|
||||
"<p><pre><code class=\"lang-auto\"> some code</code></pre></p>",
|
||||
"it works when nesting standard markdown code blocks within a fenced code block");
|
||||
|
||||
cooked("`$&`",
|
||||
assert.cooked("`$&`",
|
||||
"<p><code>$&</code></p>",
|
||||
"it works even when hoisting special replacement patterns");
|
||||
});
|
||||
|
||||
test('basic bbcode', function() {
|
||||
cookedPara("[b]strong[/b]", "<span class=\"bbcode-b\">strong</span>", "bolds text");
|
||||
cookedPara("[i]emphasis[/i]", "<span class=\"bbcode-i\">emphasis</span>", "italics text");
|
||||
cookedPara("[u]underlined[/u]", "<span class=\"bbcode-u\">underlined</span>", "underlines text");
|
||||
cookedPara("[s]strikethrough[/s]", "<span class=\"bbcode-s\">strikethrough</span>", "strikes-through text");
|
||||
cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
cookedPara("[b]evil [i]trout[/i][/b]",
|
||||
QUnit.test('basic bbcode', assert => {
|
||||
assert.cookedPara("[b]strong[/b]", "<span class=\"bbcode-b\">strong</span>", "bolds text");
|
||||
assert.cookedPara("[i]emphasis[/i]", "<span class=\"bbcode-i\">emphasis</span>", "italics text");
|
||||
assert.cookedPara("[u]underlined[/u]", "<span class=\"bbcode-u\">underlined</span>", "underlines text");
|
||||
assert.cookedPara("[s]strikethrough[/s]", "<span class=\"bbcode-s\">strikethrough</span>", "strikes-through text");
|
||||
assert.cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
|
||||
assert.cookedPara("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
|
||||
assert.cookedPara("[b]evil [i]trout[/i][/b]",
|
||||
"<span class=\"bbcode-b\">evil <span class=\"bbcode-i\">trout</span></span>",
|
||||
"allows embedding of tags");
|
||||
cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
cookedPara("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
assert.cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports upper case bbcode");
|
||||
assert.cookedPara("[b]strong [b]stronger[/b][/b]", "<span class=\"bbcode-b\">strong <span class=\"bbcode-b\">stronger</span></span>", "accepts nested bbcode tags");
|
||||
});
|
||||
|
||||
test('urls', function() {
|
||||
cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
|
||||
cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
|
||||
cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
|
||||
cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
|
||||
cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
QUnit.test('urls', assert => {
|
||||
assert.cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
|
||||
assert.cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
|
||||
assert.cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
|
||||
assert.cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
|
||||
assert.cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",
|
||||
"<a href=\"http://www.example.com\"><img src=\"http://example.com/logo.png\"></a>",
|
||||
"supports [url] with an embedded [img]");
|
||||
});
|
||||
test('invalid bbcode', function() {
|
||||
QUnit.test('invalid bbcode', assert => {
|
||||
const result = new PrettyText({ lookupAvatar: false }).cook("[code]I am not closed\n\nThis text exists.");
|
||||
equal(result, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
assert.equal(result, "<p>[code]I am not closed</p>\n\n<p>This text exists.</p>", "does not raise an error with an open bbcode tag.");
|
||||
});
|
||||
|
||||
test('code', function() {
|
||||
cookedPara("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
cookedPara("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
cookedPara("[code]abc\n#def\n[/code]", '<pre><code class=\"lang-auto\">abc\n#def</code></pre>', 'it handles headings in a [code] block');
|
||||
cookedPara("[code]\n s[/code]",
|
||||
QUnit.test('code', assert => {
|
||||
assert.cookedPara("[code]\nx++\n[/code]", "<pre><code class=\"lang-auto\">x++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]\nx++\ny++\nz++\n[/code]", "<pre><code class=\"lang-auto\">x++\ny++\nz++</code></pre>", "makes code into pre");
|
||||
assert.cookedPara("[code]abc\n#def\n[/code]", '<pre><code class=\"lang-auto\">abc\n#def</code></pre>', 'it handles headings in a [code] block');
|
||||
assert.cookedPara("[code]\n s[/code]",
|
||||
"<pre><code class=\"lang-auto\"> s</code></pre>",
|
||||
"it doesn't trim leading whitespace");
|
||||
});
|
||||
|
||||
test('lists', function() {
|
||||
cookedPara("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
cookedPara("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
QUnit.test('lists', assert => {
|
||||
assert.cookedPara("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
|
||||
assert.cookedPara("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
|
||||
assert.cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "<ul><li>option one</li><li>option two</li></ul>", "suppresses empty lines in lists");
|
||||
});
|
||||
|
||||
test('tags with arguments', function() {
|
||||
cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
cookedPara("[u][i]abc[/i][/u]", "<span class=\"bbcode-u\"><span class=\"bbcode-i\">abc</span></span>", "can nest tags");
|
||||
cookedPara("[b]first[/b] [b]second[/b]", "<span class=\"bbcode-b\">first</span> <span class=\"bbcode-b\">second</span>", "can bold two things on the same line");
|
||||
QUnit.test('tags with arguments', assert => {
|
||||
assert.cookedPara("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
|
||||
assert.cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
assert.cookedPara("[u][i]abc[/i][/u]", "<span class=\"bbcode-u\"><span class=\"bbcode-i\">abc</span></span>", "can nest tags");
|
||||
assert.cookedPara("[b]first[/b] [b]second[/b]", "<span class=\"bbcode-b\">first</span> <span class=\"bbcode-b\">second</span>", "can bold two things on the same line");
|
||||
});
|
||||
|
||||
|
||||
test("quotes", function() {
|
||||
QUnit.test("quotes", assert => {
|
||||
const post = Post.create({
|
||||
cooked: "<p><b>lorem</b> ipsum</p>",
|
||||
username: "eviltrout",
|
||||
|
@ -621,7 +633,7 @@ test("quotes", function() {
|
|||
});
|
||||
|
||||
function formatQuote(val, expected, text) {
|
||||
equal(Quote.build(post, val), expected, text);
|
||||
assert.equal(Quote.build(post, val), expected, text);
|
||||
};
|
||||
|
||||
formatQuote(undefined, "", "empty string for undefined content");
|
||||
|
@ -646,80 +658,80 @@ test("quotes", function() {
|
|||
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n",
|
||||
"it escapes the contents of the quote");
|
||||
|
||||
cookedPara("[quote]test[/quote]",
|
||||
assert.cookedPara("[quote]test[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p>test</p></blockquote></aside>",
|
||||
"it supports quotes without params");
|
||||
|
||||
cookedPara("[quote]\n*test*\n[/quote]",
|
||||
assert.cookedPara("[quote]\n*test*\n[/quote]",
|
||||
"<aside class=\"quote\"><blockquote><p><em>test</em></p></blockquote></aside>",
|
||||
"it doesn't insert a new line for italics");
|
||||
|
||||
cookedPara("[quote=,script='a'><script>alert('test');//':a][/quote]",
|
||||
assert.cookedPara("[quote=,script='a'><script>alert('test');//':a][/quote]",
|
||||
"<aside class=\"quote\"><blockquote></blockquote></aside>",
|
||||
"It will not create a script tag within an attribute");
|
||||
});
|
||||
|
||||
test("quote formatting", function() {
|
||||
QUnit.test("quote formatting", assert => {
|
||||
|
||||
cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]",
|
||||
assert.cooked("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]",
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>[sam]</p></blockquote></aside>",
|
||||
"it allows quotes with [] inside");
|
||||
|
||||
cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>",
|
||||
"renders quotes properly");
|
||||
|
||||
cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||
assert.cooked("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]\nhello",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>eviltrout:" +
|
||||
"</div><blockquote><p>abc</p></blockquote></aside>\n\n<p>hello</p>",
|
||||
"handles new lines properly");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><aside class=\"quote\" data-post=\"2\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Bob:" +
|
||||
"</div><blockquote></blockquote></aside></blockquote></aside>",
|
||||
"quotes can be nested");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n[quote=\"Bob, post:2, topic:1\"]\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:" +
|
||||
"</div><blockquote><p>[quote=\"Bob, post:2, topic:1\"]</p></blockquote></aside>",
|
||||
"handles mismatched nested quote tags");
|
||||
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks without leading newline");
|
||||
cooked("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
assert.cooked("[quote=\"Alice, post:1, topic:1\"]\n\n```javascript\nvar foo ='foo';\nvar bar = 'bar';\n```\n[/quote]",
|
||||
"<aside class=\"quote\" data-post=\"1\" data-topic=\"1\"><div class=\"title\"><div class=\"quote-controls\"></div>Alice:</div><blockquote><p><pre><code class=\"lang-javascript\">var foo ='foo';\nvar bar = 'bar';</code></pre></p></blockquote></aside>",
|
||||
"quotes can have code blocks with leading newline");
|
||||
});
|
||||
|
||||
test("quotes with trailing formatting", function() {
|
||||
QUnit.test("quotes with trailing formatting", assert => {
|
||||
const result = new PrettyText(defaultOpts).cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]\nhello\n[/quote]\n*Test*");
|
||||
equal(result,
|
||||
assert.equal(result,
|
||||
"<aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">" +
|
||||
"<div class=\"quote-controls\"></div>EvilTrout:</div><blockquote><p>hello</p></blockquote></aside>\n\n<p><em>Test</em></p>",
|
||||
"it allows trailing formatting");
|
||||
});
|
||||
|
||||
test("enable/disable features", () => {
|
||||
QUnit.test("enable/disable features", assert => {
|
||||
const table = `<table><tr><th>hello</th></tr><tr><td>world</td></tr></table>`;
|
||||
const hasTable = new PrettyText({ features: {table: true}, sanitize: true}).cook(table);
|
||||
equal(hasTable, `<table class="md-table"><tr><th>hello</th></tr><tr><td>world</td></tr></table>`);
|
||||
assert.equal(hasTable, `<table class="md-table"><tr><th>hello</th></tr><tr><td>world</td></tr></table>`);
|
||||
|
||||
const noTable = new PrettyText({ features: { table: false }, sanitize: true}).cook(table);
|
||||
equal(noTable, `<p></p>`, 'tables are stripped when disabled');
|
||||
assert.equal(noTable, `<p></p>`, 'tables are stripped when disabled');
|
||||
});
|
||||
|
||||
test("emoji", () => {
|
||||
cooked(":smile:", `<p><img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
cooked(":(", `<p><img src="/images/emoji/emoji_one/frowning.png?v=${v}" title=":frowning:" class="emoji" alt=":frowning:"></p>`);
|
||||
cooked("8-)", `<p><img src="/images/emoji/emoji_one/sunglasses.png?v=${v}" title=":sunglasses:" class="emoji" alt=":sunglasses:"></p>`);
|
||||
QUnit.test("emoji", assert => {
|
||||
assert.cooked(":smile:", `<p><img src="/images/emoji/emoji_one/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
assert.cooked(":(", `<p><img src="/images/emoji/emoji_one/frowning.png?v=${v}" title=":frowning:" class="emoji" alt=":frowning:"></p>`);
|
||||
assert.cooked("8-)", `<p><img src="/images/emoji/emoji_one/sunglasses.png?v=${v}" title=":sunglasses:" class="emoji" alt=":sunglasses:"></p>`);
|
||||
});
|
||||
|
||||
test("emoji - emojiSet", () => {
|
||||
cookedOptions(":smile:",
|
||||
QUnit.test("emoji - emojiSet", assert => {
|
||||
assert.cookedOptions(":smile:",
|
||||
{ emojiSet: 'twitter' },
|
||||
`<p><img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:"></p>`);
|
||||
});
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { default as PrettyText, buildOptions } from 'pretty-text/pretty-text';
|
||||
import { hrefAllowed } from 'pretty-text/sanitizer';
|
||||
|
||||
module("lib:sanitizer");
|
||||
QUnit.module("lib:sanitizer");
|
||||
|
||||
test("sanitize", function() {
|
||||
QUnit.test("sanitize", assert => {
|
||||
const pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
const cooked = (input, expected, text) => equal(pt.cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
const cooked = (input, expected, text) => assert.equal(pt.cook(input), expected.replace(/\/>/g, ">"), text);
|
||||
|
||||
equal(pt.sanitize("<i class=\"fa-bug fa-spin\">bug</i>"), "<i>bug</i>");
|
||||
equal(pt.sanitize("<div><script>alert('hi');</script></div>"), "<div></div>");
|
||||
equal(pt.sanitize("<div><p class=\"funky\" wrong='1'>hello</p></div>"), "<div><p>hello</p></div>");
|
||||
equal(pt.sanitize("<3 <3"), "<3 <3");
|
||||
equal(pt.sanitize("<_<"), "<_<");
|
||||
assert.equal(pt.sanitize("<i class=\"fa-bug fa-spin\">bug</i>"), "<i>bug</i>");
|
||||
assert.equal(pt.sanitize("<div><script>alert('hi');</script></div>"), "<div></div>");
|
||||
assert.equal(pt.sanitize("<div><p class=\"funky\" wrong='1'>hello</p></div>"), "<div><p>hello</p></div>");
|
||||
assert.equal(pt.sanitize("<3 <3"), "<3 <3");
|
||||
assert.equal(pt.sanitize("<_<"), "<_<");
|
||||
cooked("hello<script>alert(42)</script>", "<p>hello</p>", "it sanitizes while cooking");
|
||||
|
||||
cooked("<a href='http://disneyland.disney.go.com/'>disney</a> <a href='http://reddit.com'>reddit</a>",
|
||||
|
@ -32,11 +32,11 @@ test("sanitize", function() {
|
|||
"<iframe width=\"425\" height=\"350\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" src=\"http://www.openstreetmap.org/export/embed.html?bbox=22.49454975128174%2C51.220338322410775%2C22.523088455200195%2C51.23345342732931&layer=mapnik\"></iframe>",
|
||||
"it allows iframe to OpenStreetMap");
|
||||
|
||||
equal(pt.sanitize("<textarea>hullo</textarea>"), "hullo");
|
||||
equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
||||
equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
||||
equal(pt.sanitize("<progress>hello"), "hello");
|
||||
equal(pt.sanitize("<mark>highlight</mark>"), "highlight");
|
||||
assert.equal(pt.sanitize("<textarea>hullo</textarea>"), "hullo");
|
||||
assert.equal(pt.sanitize("<button>press me!</button>"), "press me!");
|
||||
assert.equal(pt.sanitize("<canvas>draw me!</canvas>"), "draw me!");
|
||||
assert.equal(pt.sanitize("<progress>hello"), "hello");
|
||||
assert.equal(pt.sanitize("<mark>highlight</mark>"), "highlight");
|
||||
|
||||
cooked("[the answer](javascript:alert(42))", "<p><a>the answer</a></p>", "it prevents XSS");
|
||||
|
||||
|
@ -60,26 +60,26 @@ test("sanitize", function() {
|
|||
cooked(`<div dir="rtl">RTL text</div>`, `<div dir="rtl">RTL text</div>`);
|
||||
});
|
||||
|
||||
test("ids on headings", () => {
|
||||
QUnit.test("ids on headings", assert => {
|
||||
const pt = new PrettyText(buildOptions({ siteSettings: {} }));
|
||||
equal(pt.sanitize("<h3>Test Heading</h3>"), "<h3>Test Heading</h3>");
|
||||
equal(pt.sanitize(`<h1 id="test-heading">Test Heading</h1>`), `<h1 id="test-heading">Test Heading</h1>`);
|
||||
equal(pt.sanitize(`<h2 id="test-heading">Test Heading</h2>`), `<h2 id="test-heading">Test Heading</h2>`);
|
||||
equal(pt.sanitize(`<h3 id="test-heading">Test Heading</h3>`), `<h3 id="test-heading">Test Heading</h3>`);
|
||||
equal(pt.sanitize(`<h4 id="test-heading">Test Heading</h4>`), `<h4 id="test-heading">Test Heading</h4>`);
|
||||
equal(pt.sanitize(`<h5 id="test-heading">Test Heading</h5>`), `<h5 id="test-heading">Test Heading</h5>`);
|
||||
equal(pt.sanitize(`<h6 id="test-heading">Test Heading</h6>`), `<h6 id="test-heading">Test Heading</h6>`);
|
||||
assert.equal(pt.sanitize("<h3>Test Heading</h3>"), "<h3>Test Heading</h3>");
|
||||
assert.equal(pt.sanitize(`<h1 id="test-heading">Test Heading</h1>`), `<h1 id="test-heading">Test Heading</h1>`);
|
||||
assert.equal(pt.sanitize(`<h2 id="test-heading">Test Heading</h2>`), `<h2 id="test-heading">Test Heading</h2>`);
|
||||
assert.equal(pt.sanitize(`<h3 id="test-heading">Test Heading</h3>`), `<h3 id="test-heading">Test Heading</h3>`);
|
||||
assert.equal(pt.sanitize(`<h4 id="test-heading">Test Heading</h4>`), `<h4 id="test-heading">Test Heading</h4>`);
|
||||
assert.equal(pt.sanitize(`<h5 id="test-heading">Test Heading</h5>`), `<h5 id="test-heading">Test Heading</h5>`);
|
||||
assert.equal(pt.sanitize(`<h6 id="test-heading">Test Heading</h6>`), `<h6 id="test-heading">Test Heading</h6>`);
|
||||
});
|
||||
|
||||
test("urlAllowed", () => {
|
||||
const allowed = (url, msg) => equal(hrefAllowed(url), url, msg);
|
||||
QUnit.test("urlAllowed", assert => {
|
||||
const allowed = (url, msg) => assert.equal(hrefAllowed(url), url, msg);
|
||||
|
||||
allowed("/foo/bar.html", "allows relative urls");
|
||||
allowed("http://eviltrout.com/evil/trout", "allows full urls");
|
||||
allowed("https://eviltrout.com/evil/trout", "allows https urls");
|
||||
allowed("//eviltrout.com/evil/trout", "allows protocol relative urls");
|
||||
|
||||
equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"),
|
||||
assert.equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"),
|
||||
"http://google.com/test%27onmouseover=alert(%27XSS!%27);//.swf",
|
||||
"escape single quotes");
|
||||
});
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue