-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
66 changes: 66 additions & 0 deletions
66
packages/components/src/utils/__tests__/getWordsFromPermalink.test.ts
This file contains 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,66 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import { getWordsFromPermalink } from "~/utils" | ||
|
||
describe("getWordsFromPermalink", () => { | ||
it("should trim out all symbols and return the permalink as a space separated sentence for single level permalinks", () => { | ||
// Arrange | ||
const singleLevelPermalink = "/this-._single=level|" | ||
const expected = "this+single+level" | ||
|
||
// Act | ||
const actual = getWordsFromPermalink(singleLevelPermalink) | ||
|
||
// Assert | ||
expect(actual).toBe(expected) | ||
}) | ||
|
||
it("should trim out all symbols and return the last section as a space separated sentence for nested permalinks", () => { | ||
// Arrange | ||
const nestedPermalink = "/nested/deeply/this-._nest'fff=level|" | ||
const expected = "this+nest+fff+level" | ||
|
||
// Act | ||
const actual = getWordsFromPermalink(nestedPermalink) | ||
|
||
// Assert | ||
expect(actual).toBe(expected) | ||
}) | ||
|
||
it("should preserve `=` in the original permalink", () => { | ||
// Arrange | ||
const singleLevelPermalink = "/this-._single=level|" | ||
const expected = "this+single+level" | ||
|
||
// Act | ||
const actual = getWordsFromPermalink(singleLevelPermalink) | ||
|
||
// Assert | ||
expect(actual).toBe(expected) | ||
}) | ||
|
||
it("should handle uri-encoded strings correctly", () => { | ||
// Arrange | ||
const singleLevelPermalink = "/this-._single=level|" | ||
const encodedPermalink = encodeURIComponent(singleLevelPermalink) | ||
const expected = "this+single+level" | ||
|
||
// Act | ||
const actual = getWordsFromPermalink(encodedPermalink) | ||
|
||
// Assert | ||
expect(actual).toBe(expected) | ||
}) | ||
|
||
it("should work with a trailing /", () => { | ||
// Arrange | ||
const singleLevelPermalink = "/this-._single=level|/" | ||
const expected = "this+single+level" | ||
|
||
// Act | ||
const actual = getWordsFromPermalink(singleLevelPermalink) | ||
|
||
// Assert | ||
expect(actual).toBe(expected) | ||
}) | ||
}) |
This file contains 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