FEATURE: Watched Words: when posts contain words, do one of flag, require approval, censor, or block

This commit is contained in:
Neil Lalonde
2017-06-28 16:56:44 -04:00
parent 9d774a951a
commit 24cb950432
49 changed files with 1096 additions and 37 deletions
@@ -0,0 +1,68 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Watched Words", { loggedIn: true });
QUnit.test("list words in groups", assert => {
visit("/admin/watched_words/action/block");
andThen(() => {
assert.ok(exists('.watched-words-list'));
assert.ok(!exists('.watched-words-list .watched-word'), "Don't show bad words by default.");
});
fillIn('.admin-controls .controls input[type=text]', 'li');
andThen(() => {
assert.equal(find('.watched-words-list .watched-word').length, 1, "When filtering, show words even if checkbox is unchecked.");
});
fillIn('.admin-controls .controls input[type=text]', '');
andThen(() => {
assert.ok(!exists('.watched-words-list .watched-word'), "Clearing the filter hides words again.");
});
click('.show-words-checkbox');
andThen(() => {
assert.ok(exists('.watched-words-list .watched-word'), "Always show the words when checkbox is checked.");
});
click('.nav-stacked .censor');
andThen(() => {
assert.ok(exists('.watched-words-list'));
assert.ok(!exists('.watched-words-list .watched-word'), "Empty word list.");
});
});
QUnit.test("add words", assert => {
visit("/admin/watched_words/action/block");
andThen(() => {
click('.show-words-checkbox');
fillIn('.watched-word-form input', 'poutine');
});
click('.watched-word-form button');
andThen(() => {
let found = [];
_.each(find('.watched-words-list .watched-word'), i => {
if ($(i).text().trim() === 'poutine') {
found.push(true);
}
});
assert.equal(found.length, 1);
});
});
QUnit.test("remove words", assert => {
visit("/admin/watched_words/action/block");
click('.show-words-checkbox');
let word = null;
andThen(() => {
_.each(find('.watched-words-list .watched-word'), i => {
if ($(i).text().trim() === 'anise') {
word = i;
}
});
click('#' + $(word).attr('id'));
});
andThen(() => {
assert.equal(find('.watched-words-list .watched-word').length, 1);
});
});
@@ -0,0 +1,12 @@
export default {
"/admin/watched_words.json": {
"actions": ["block", "censor", "require_approval", "flag"],
"words": [
{id: 1, word: "liquorice", action: "block"},
{id: 2, word: "anise", action: "block"},
{id: 3, word: "pyramid", action: "flag"},
{id: 4, word: "scheme", action: "flag"},
{id: 5, word: "coupon", action: "require_approval"}
]
}
};
@@ -334,6 +334,17 @@ export default function() {
this.post('/admin/badges', success);
this.delete('/admin/badges/:id', success);
this.get('/admin/watched_words', () => {
return response(200, fixturesByUrl['/admin/watched_words.json']);
});
this.delete('/admin/watched_words/:id.json', success);
this.post('/admin/watched_words.json', request => {
const result = parsePostData(request.requestBody);
result.id = new Date().getTime();
return response(200, result);
});
this.get('/onebox', request => {
if (request.queryParams.url === 'http://www.example.com/has-title.html' ||
request.queryParams.url === 'http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html') {
+1 -1
View File
@@ -11,9 +11,9 @@ const rawOpts = {
emoji_set: 'emoji_one',
highlighted_languages: 'json|ruby|javascript',
default_code_lang: 'auto',
censored_words: 'shucks|whiz|whizzer|a**le',
censored_pattern: '\\d{3}-\\d{4}|tech\\w*'
},
censoredWords: 'shucks|whiz|whizzer|a**le',
getURL: url => url
};