-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix browser back/forward navigation with enabled hash navigation
- Loading branch information
1 parent
293f7c2
commit 31d815b
Showing
4 changed files
with
462 additions
and
10 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/__tests__/hash-includes-navigation-query-params.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,45 @@ | ||
import hashIncludesNavigationQueryParams from '../helpers/hash-includes-navigation-query-params' | ||
|
||
describe('hashIncludesNavigationQueryParams helper', () => { | ||
test('returns true if hash includes both query params: gid and pid', () => { | ||
expect(hashIncludesNavigationQueryParams('gid=my-gallery&pid=123')).toBe( | ||
true, | ||
) | ||
expect( | ||
hashIncludesNavigationQueryParams('args=1&gid=my-gallery&pid=my-slide'), | ||
).toBe(true) | ||
expect( | ||
hashIncludesNavigationQueryParams('args=1&gid=321&pid=my-slide'), | ||
).toBe(true) | ||
expect(hashIncludesNavigationQueryParams('gid=321&pid=my-slide')).toBe(true) | ||
expect(hashIncludesNavigationQueryParams('pid=my-slide&gid=321')).toBe(true) | ||
expect( | ||
hashIncludesNavigationQueryParams( | ||
'gid=gallery&args=value&a=1&pid=321&b=2', | ||
), | ||
).toBe(true) | ||
}) | ||
|
||
test('returns false if hash includes both query params: gid and pid', () => { | ||
expect(hashIncludesNavigationQueryParams('')).toBe(false) | ||
expect(hashIncludesNavigationQueryParams('gid=my-gallery')).toBe(false) | ||
expect(hashIncludesNavigationQueryParams('pid=123')).toBe(false) | ||
expect(hashIncludesNavigationQueryParams('args=1&gid=321')).toBe(false) | ||
expect( | ||
hashIncludesNavigationQueryParams('args=value&a=1&gid=321&b=2'), | ||
).toBe(false) | ||
expect(hashIncludesNavigationQueryParams('args=value&a=1&b=2')).toBe(false) | ||
expect(hashIncludesNavigationQueryParams('args=value&pid=1&pid=2')).toBe( | ||
false, | ||
) | ||
expect(hashIncludesNavigationQueryParams('args=value&pid=1&pid=2')).toBe( | ||
false, | ||
) | ||
expect(hashIncludesNavigationQueryParams('args=value&gid=1&pid=')).toBe( | ||
false, | ||
) | ||
expect(hashIncludesNavigationQueryParams('args=value&gid=&pid=2')).toBe( | ||
false, | ||
) | ||
}) | ||
}) |
Oops, something went wrong.