This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 808
Add basic linkify-matrix tests #7199
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
825737f
Add basic linkify-matrix tests
4d67706
Add missing header
cdedb64
Fix different beforeAll call
fc62a2a
Fix stray new line
0b8d98e
Fix invalid test
231e0de
Fix test not parsing multiple room aliases
a35cfb0
Fix mor tests
cb53cb5
Fix test without domain
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,238 @@ | ||
| /* | ||
| Copyright 2021 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| import * as linkify from "linkifyjs"; | ||
| import linkifyMatrix from '../src/linkify-matrix'; | ||
|
|
||
| beforeAll(() => { | ||
| linkifyMatrix(linkify); | ||
| }); | ||
|
|
||
| describe('linkify-matrix', () => { | ||
| describe('roomalias', () => { | ||
| it('properly parses #_foonetic_xkcd:matrix.org', () => { | ||
| const test = '#_foonetic_xkcd:matrix.org'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#_foonetic_xkcd:matrix.org", | ||
| type: "roomalias", | ||
| value: "#_foonetic_xkcd:matrix.org", | ||
| }])); | ||
| }); | ||
| it('properly parses #foo:localhost', () => { | ||
| const test = "#foo:localhost"; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:localhost", | ||
| type: "roomalias", | ||
| value: "#foo:localhost", | ||
| }])); | ||
| }); | ||
| it('accept #foo:bar.com', () => { | ||
| const test = '#foo:bar.com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:bar.com", | ||
| type: "roomalias", | ||
| value: "#foo:bar.com", | ||
| }])); | ||
| }); | ||
| it('accept #foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { | ||
| const test = '#foo:com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:com", | ||
| type: "roomalias", | ||
| value: "#foo:com", | ||
| }])); | ||
| }); | ||
| it('accept repeated TLDs (e.g .org.uk)', () => { | ||
| const test = '#foo:bar.org.uk'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:bar.org.uk", | ||
| type: "roomalias", | ||
| value: "#foo:bar.org.uk", | ||
| }])); | ||
| }); | ||
| it('ignores trailing `:`', () => { | ||
| const test = '#foo:bar.com:'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:bar.com", | ||
| type: "roomalias", | ||
| value: "#foo:bar.com", | ||
|
|
||
| }])); | ||
| }); | ||
| it('accept :NUM (port specifier)', () => { | ||
| const test = '#foo:bar.com:2225'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:bar.com:2225", | ||
| type: "roomalias", | ||
| value: "#foo:bar.com:2225", | ||
| }])); | ||
| }); | ||
| it('ignores all the trailing :', () => { | ||
| const test = '#foo:bar.com::::'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo:bar.com", | ||
| type: "roomalias", | ||
| value: "#foo:bar.com", | ||
|
|
||
| }])); | ||
| }); | ||
| it('properly parses room alias with dots in name', () => { | ||
| const test = '#foo.asdf:bar.com::::'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "#foo.asdf:bar.com", | ||
| type: "roomalias", | ||
| value: "#foo.asdf:bar.com", | ||
|
|
||
| }])); | ||
| }); | ||
| it('does not parse room alias with too many separators', () => { | ||
| const test = '#foo:::bar.com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "http://bar.com", | ||
| type: "url", | ||
| value: "bar.com", | ||
| }])); | ||
| }); | ||
| it('does not parse multiple room aliases in one string', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test name doesn't seem to match the fixture |
||
| const test = '#foo:bar.com-baz.com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| "href": "#foo:bar.com-baz.com", | ||
| "type": "roomalias", | ||
| "value": "#foo:bar.com-baz.com", | ||
| }])); | ||
| }); | ||
| }); | ||
|
|
||
| describe('groupid', () => { | ||
| it('properly parses +foo:localhost', () => { | ||
| const test = "+foo:localhost"; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "+foo:localhost", | ||
| type: "groupid", | ||
| value: "+foo:localhost", | ||
| }])); | ||
| }); | ||
| it('accept +foo:bar.com', () => { | ||
| const test = '+foo:bar.com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "+foo:bar.com", | ||
| type: "groupid", | ||
| value: "+foo:bar.com", | ||
| }])); | ||
| }); | ||
| it('accept +foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { | ||
| const test = '+foo:com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "+foo:com", | ||
| type: "groupid", | ||
| value: "+foo:com", | ||
| }])); | ||
| }); | ||
| it('accept repeated TLDs (e.g .org.uk)', () => { | ||
| const test = '+foo:bar.org.uk'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "+foo:bar.org.uk", | ||
| type: "groupid", | ||
| value: "+foo:bar.org.uk", | ||
| }])); | ||
| }); | ||
| it('ignore trailing `:`', () => { | ||
| const test = '+foo:bar.com:'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| "href": "+foo:bar.com", | ||
| "type": "groupid", | ||
| "value": "+foo:bar.com", | ||
| }])); | ||
| }); | ||
| it('accept :NUM (port specifier)', () => { | ||
| const test = '+foo:bar.com:2225'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "+foo:bar.com:2225", | ||
| type: "groupid", | ||
| value: "+foo:bar.com:2225", | ||
| }])); | ||
| }); | ||
| }); | ||
|
|
||
| describe('userid', () => { | ||
| it('should not parse @foo without domain', () => { | ||
| const test = "@foo"; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([])); | ||
| }); | ||
| it('accept @foo:bar.com', () => { | ||
| const test = '@foo:bar.com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "@foo:bar.com", | ||
| type: "userid", | ||
| value: "@foo:bar.com", | ||
| }])); | ||
| }); | ||
| it('accept @foo:com (mostly for (TLD|DOMAIN)+ mixing)', () => { | ||
| const test = '@foo:com'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "@foo:com", | ||
| type: "userid", | ||
| value: "@foo:com", | ||
| }])); | ||
| }); | ||
| it('accept repeated TLDs (e.g .org.uk)', () => { | ||
| const test = '@foo:bar.org.uk'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "@foo:bar.org.uk", | ||
| type: "userid", | ||
| value: "@foo:bar.org.uk", | ||
| }])); | ||
| }); | ||
| it('do not accept trailing `:`', () => { | ||
| const test = '@foo:bar.com:'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "@foo:bar.com", | ||
| type: "userid", | ||
| value: "@foo:bar.com", | ||
| }])); | ||
| }); | ||
| it('accept :NUM (port specifier)', () => { | ||
| const test = '@foo:bar.com:2225'; | ||
| const found = linkify.find(test); | ||
| expect(found).toEqual(([{ | ||
| href: "@foo:bar.com:2225", | ||
| type: "userid", | ||
| value: "@foo:bar.com:2225", | ||
| }])); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.