1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Apply prettier formatting

This commit is contained in:
Michael Weimann
2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
1576 changed files with 65385 additions and 62478 deletions

View File

@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import EmojiProvider from '../../src/autocomplete/EmojiProvider';
import { mkStubRoom } from '../test-utils/test-utils';
import EmojiProvider from "../../src/autocomplete/EmojiProvider";
import { mkStubRoom } from "../test-utils/test-utils";
import { add } from "../../src/emojipicker/recent";
import { stubClient } from "../test-utils";
import { MatrixClientPeg } from '../../src/MatrixClientPeg';
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
const EMOJI_SHORTCODES = [
":+1",
@ -39,20 +39,18 @@ const EMOJI_SHORTCODES = [
// Some emoji shortcodes are too short and do not actually trigger autocompletion until the ending `:`.
// This means that we cannot compare their autocompletion before and after the ending `:` and have
// to simply assert that the final completion with the colon is the exact emoji.
const TOO_SHORT_EMOJI_SHORTCODE = [
{ emojiShortcode: ":o", expectedEmoji: "⭕️" },
];
const TOO_SHORT_EMOJI_SHORTCODE = [{ emojiShortcode: ":o", expectedEmoji: "⭕️" }];
describe('EmojiProvider', function() {
describe("EmojiProvider", function () {
const testRoom = mkStubRoom(undefined, undefined, undefined);
stubClient();
MatrixClientPeg.get();
it.each(EMOJI_SHORTCODES)('Returns consistent results after final colon %s', async function(emojiShortcode) {
it.each(EMOJI_SHORTCODES)("Returns consistent results after final colon %s", async function (emojiShortcode) {
const ep = new EmojiProvider(testRoom);
const range = { "beginning": true, "start": 0, "end": 3 };
const range = { beginning: true, start: 0, end: 3 };
const completionsBeforeColon = await ep.getCompletions(emojiShortcode, range);
const completionsAfterColon = await ep.getCompletions(emojiShortcode + ':', range);
const completionsAfterColon = await ep.getCompletions(emojiShortcode + ":", range);
const firstCompletionWithoutColon = completionsBeforeColon[0].completion;
const firstCompletionWithColon = completionsAfterColon[0].completion;
@ -60,17 +58,18 @@ describe('EmojiProvider', function() {
expect(firstCompletionWithoutColon).toEqual(firstCompletionWithColon);
});
it.each(
TOO_SHORT_EMOJI_SHORTCODE,
)('Returns correct results after final colon $emojiShortcode', async ({ emojiShortcode, expectedEmoji }) => {
const ep = new EmojiProvider(testRoom);
const range = { "beginning": true, "start": 0, "end": 3 };
const completions = await ep.getCompletions(emojiShortcode + ':', range);
it.each(TOO_SHORT_EMOJI_SHORTCODE)(
"Returns correct results after final colon $emojiShortcode",
async ({ emojiShortcode, expectedEmoji }) => {
const ep = new EmojiProvider(testRoom);
const range = { beginning: true, start: 0, end: 3 };
const completions = await ep.getCompletions(emojiShortcode + ":", range);
expect(completions[0].completion).toEqual(expectedEmoji);
});
expect(completions[0].completion).toEqual(expectedEmoji);
},
);
it('Returns correct autocompletion based on recently used emoji', async function() {
it("Returns correct autocompletion based on recently used emoji", async function () {
add("😘"); //kissing_heart
add("😘");
add("😚"); //kissing_closed_eyes

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import QueryMatcher from '../../src/autocomplete/QueryMatcher';
import QueryMatcher from "../../src/autocomplete/QueryMatcher";
const OBJECTS = [
{ name: "Mel B", nick: "Scary" },
@ -24,160 +24,151 @@ const OBJECTS = [
{ name: "Victoria", nick: "Posh" },
];
const NONWORDOBJECTS = [
{ name: "B.O.B" },
{ name: "bob" },
];
const NONWORDOBJECTS = [{ name: "B.O.B" }, { name: "bob" }];
describe('QueryMatcher', function() {
it('Returns results by key', function() {
describe("QueryMatcher", function () {
it("Returns results by key", function () {
const qm = new QueryMatcher(OBJECTS, { keys: ["name"] });
const results = qm.match('Geri');
const results = qm.match("Geri");
expect(results.length).toBe(1);
expect(results[0].name).toBe('Geri');
expect(results[0].name).toBe("Geri");
});
it('Returns results by prefix', function() {
it("Returns results by prefix", function () {
const qm = new QueryMatcher(OBJECTS, { keys: ["name"] });
const results = qm.match('Ge');
const results = qm.match("Ge");
expect(results.length).toBe(1);
expect(results[0].name).toBe('Geri');
expect(results[0].name).toBe("Geri");
});
it('Matches case-insensitive', function() {
it("Matches case-insensitive", function () {
const qm = new QueryMatcher(OBJECTS, { keys: ["name"] });
const results = qm.match('geri');
const results = qm.match("geri");
expect(results.length).toBe(1);
expect(results[0].name).toBe('Geri');
expect(results[0].name).toBe("Geri");
});
it('Matches ignoring accents', function() {
it("Matches ignoring accents", function () {
const qm = new QueryMatcher([{ name: "Gëri", foo: 46 }], { keys: ["name"] });
const results = qm.match('geri');
const results = qm.match("geri");
expect(results.length).toBe(1);
expect(results[0].foo).toBe(46);
});
it('Returns multiple results in order of search string appearance', function() {
it("Returns multiple results in order of search string appearance", function () {
const qm = new QueryMatcher(OBJECTS, { keys: ["name", "nick"] });
const results = qm.match('or');
const results = qm.match("or");
expect(results.length).toBe(2);
expect(results[0].name).toBe('Mel C');
expect(results[1].name).toBe('Victoria');
expect(results[0].name).toBe("Mel C");
expect(results[1].name).toBe("Victoria");
qm.setObjects(OBJECTS.slice().reverse());
const reverseResults = qm.match('or');
const reverseResults = qm.match("or");
// should still be in the same order: search string position
// takes precedence over input order
expect(reverseResults.length).toBe(2);
expect(reverseResults[0].name).toBe('Mel C');
expect(reverseResults[1].name).toBe('Victoria');
expect(reverseResults[0].name).toBe("Mel C");
expect(reverseResults[1].name).toBe("Victoria");
});
it('Returns results with search string in same place according to key index', function() {
it("Returns results with search string in same place according to key index", function () {
const objects = [
{ name: "a", first: "hit", second: "miss", third: "miss" },
{ name: "b", first: "miss", second: "hit", third: "miss" },
{ name: "c", first: "miss", second: "miss", third: "hit" },
];
const qm = new QueryMatcher(objects, { keys: ["second", "first", "third"] });
const results = qm.match('hit');
const results = qm.match("hit");
expect(results.length).toBe(3);
expect(results[0].name).toBe('b');
expect(results[1].name).toBe('a');
expect(results[2].name).toBe('c');
expect(results[0].name).toBe("b");
expect(results[1].name).toBe("a");
expect(results[2].name).toBe("c");
qm.setObjects(objects.slice().reverse());
const reverseResults = qm.match('hit');
const reverseResults = qm.match("hit");
// should still be in the same order: key index
// takes precedence over input order
expect(reverseResults.length).toBe(3);
expect(reverseResults[0].name).toBe('b');
expect(reverseResults[1].name).toBe('a');
expect(reverseResults[2].name).toBe('c');
expect(reverseResults[0].name).toBe("b");
expect(reverseResults[1].name).toBe("a");
expect(reverseResults[2].name).toBe("c");
});
it('Returns results with search string in same place and key in same place in insertion order', function() {
it("Returns results with search string in same place and key in same place in insertion order", function () {
const qm = new QueryMatcher(OBJECTS, { keys: ["name"] });
const results = qm.match('Mel');
const results = qm.match("Mel");
expect(results.length).toBe(2);
expect(results[0].name).toBe('Mel B');
expect(results[1].name).toBe('Mel C');
expect(results[0].name).toBe("Mel B");
expect(results[1].name).toBe("Mel C");
qm.setObjects(OBJECTS.slice().reverse());
const reverseResults = qm.match('Mel');
const reverseResults = qm.match("Mel");
expect(reverseResults.length).toBe(2);
expect(reverseResults[0].name).toBe('Mel C');
expect(reverseResults[1].name).toBe('Mel B');
expect(reverseResults[0].name).toBe("Mel C");
expect(reverseResults[1].name).toBe("Mel B");
});
it('Returns numeric results in correct order (input pos)', function() {
it("Returns numeric results in correct order (input pos)", function () {
// regression test for depending on object iteration order
const qm = new QueryMatcher([
{ name: "123456badger" },
{ name: "123456" },
], { keys: ["name"] });
const results = qm.match('123456');
const qm = new QueryMatcher([{ name: "123456badger" }, { name: "123456" }], { keys: ["name"] });
const results = qm.match("123456");
expect(results.length).toBe(2);
expect(results[0].name).toBe('123456badger');
expect(results[1].name).toBe('123456');
expect(results[0].name).toBe("123456badger");
expect(results[1].name).toBe("123456");
});
it('Returns numeric results in correct order (query pos)', function() {
const qm = new QueryMatcher([
{ name: "999999123456" },
{ name: "123456badger" },
], { keys: ["name"] });
const results = qm.match('123456');
it("Returns numeric results in correct order (query pos)", function () {
const qm = new QueryMatcher([{ name: "999999123456" }, { name: "123456badger" }], { keys: ["name"] });
const results = qm.match("123456");
expect(results.length).toBe(2);
expect(results[0].name).toBe('123456badger');
expect(results[1].name).toBe('999999123456');
expect(results[0].name).toBe("123456badger");
expect(results[1].name).toBe("999999123456");
});
it('Returns results by function', function() {
it("Returns results by function", function () {
const qm = new QueryMatcher(OBJECTS, {
keys: ["name"],
funcs: [x => x.name.replace('Mel', 'Emma')],
funcs: [(x) => x.name.replace("Mel", "Emma")],
});
const results = qm.match('Emma');
const results = qm.match("Emma");
expect(results.length).toBe(3);
expect(results[0].name).toBe('Emma');
expect(results[1].name).toBe('Mel B');
expect(results[2].name).toBe('Mel C');
expect(results[0].name).toBe("Emma");
expect(results[1].name).toBe("Mel B");
expect(results[2].name).toBe("Mel C");
});
it('Matches words only by default', function() {
it("Matches words only by default", function () {
const qm = new QueryMatcher(NONWORDOBJECTS, { keys: ["name"] });
const results = qm.match('bob');
const results = qm.match("bob");
expect(results.length).toBe(2);
expect(results[0].name).toBe('B.O.B');
expect(results[1].name).toBe('bob');
expect(results[0].name).toBe("B.O.B");
expect(results[1].name).toBe("bob");
});
it('Matches all chars with words-only off', function() {
it("Matches all chars with words-only off", function () {
const qm = new QueryMatcher(NONWORDOBJECTS, {
keys: ["name"],
shouldMatchWordsOnly: false,
});
const results = qm.match('bob');
const results = qm.match("bob");
expect(results.length).toBe(1);
expect(results[0].name).toBe('bob');
expect(results[0].name).toBe("bob");
});
});