FEATURE: autocomplete usernames early in topic based on participation

Following this change when a user hits `@` and is replying to a topic they
will see usernames of people who were last seen and participated in the topic

This is somewhat experimental, we may tweak this, or make it optional.

Also, a regression in a423a938 where hitting TAB would eat a post you were writing:

Eg this would eat a post:

``` text
@hello, testing 123 <tab>
```
This commit is contained in:
Sam
2019-02-20 13:33:56 +11:00
parent cff108762a
commit 1f4ace4f56
4 changed files with 65 additions and 14 deletions

View File

@ -1,5 +1,4 @@
import userSearch from "discourse/lib/user-search";
import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
QUnit.module("lib:user-search", {
beforeEach() {
@ -73,7 +72,29 @@ QUnit.test("it strips @ from the beginning", async assert => {
assert.equal(results[results.length - 1]["name"], "team");
});
QUnit.test("it does not search for invalid usernames", async assert => {
let results = await userSearch({ term: "foo, " });
assert.equal(results, CANCELLED_STATUS);
QUnit.test("it skips a search depending on punctuations", async assert => {
let skippedTerms = [
"@sam s", // double space is not allowed
"@sam;",
"@sam,",
"@sam:"
];
skippedTerms.forEach(async term => {
let results = await userSearch({ term });
assert.equal(results.length, 0);
});
let allowedTerms = [
"@sam sam", // double space is not allowed
"@sam.sam",
"@"
];
let topicId = 100;
allowedTerms.forEach(async term => {
let results = await userSearch({ term, topicId });
assert.equal(results.length, 6);
});
});