-
Notifications
You must be signed in to change notification settings - Fork 39
Enable wiki URLs to declare a lineup using location.hash in addition to location.pathname #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dobbs
wants to merge
12
commits into
fedwiki:legacy
Choose a base branch
from
dobbs:lineup-urls
base: legacy
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
08e8077
add conformance test for current state behavior
dobbs 9abbfa3
replace use of jquery to get location.pathname
dobbs 74a6993
refactor to introduce internal [{site, slug}...] structure
dobbs b545572
changed toURL() to a private function & added unchaged()
dobbs 20c1f61
verify same test cases work with URL.search (except setUrl)
dobbs 8b9076b
state.setUrl() now sets URL.search if it is present
dobbs 1546c47
state.setUrl() uses URL.search if URL.pathname is /
dobbs 9e924ba
test/state needs to stub lineup.bestTitle() when running all tests
dobbs 5a60bbb
use location.hash instead of location.search
dobbs 04e4c29
state.fromLocation() now understands welcome-visitors.html
dobbs 76158e2
clarify names: pathname refers only to url.pathname
dobbs 41252bf
rename parameter from stat to sfw
dobbs 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
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
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
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,91 @@ | ||
| state = require('../lib/state') | ||
| lineup = require('../lib/lineup') | ||
| expect = require 'expect.js' | ||
|
|
||
| # here we test manipulations of the lineup and window.location | ||
|
|
||
| describe 'state', -> | ||
| actual = null | ||
| title = null | ||
| tests = [ | ||
| # [pathname, locs, pages] | ||
| ['/', [], []], | ||
| ['/view/welcome-visitors', ['view'], ['welcome-visitors']], | ||
| ['/view/foo/view/bar', ['view', 'view'], ['foo', 'bar']], | ||
| ['/view/welcome-visitors/fed.wiki.org/featured-sites', | ||
| ['view', 'fed.wiki.org'], ['welcome-visitors', 'featured-sites']], | ||
| ['/welcome-visitors.html', ['view'], ['welcome-visitors']], | ||
| ['/how-to-wiki.html', ['view'], ['how-to-wiki']] | ||
| ] | ||
| before -> | ||
| global.$ = (el) -> {attr: (key) -> el[key]} | ||
| global.history = | ||
| pushState: (state, title, url) -> actual = url | ||
| lineup.bestTitle = () -> title | ||
|
Comment on lines
+20
to
+24
Member
Author
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. We're stubbing jQuery's |
||
|
|
||
| context 'using URL.pathname', -> | ||
| for [pathname, locs, pages] in tests | ||
| context pathname, -> | ||
| beforeEach -> | ||
| global.location = new URL("https://example.com#{pathname}") | ||
| it "urlPages() is [#{pages}]", -> | ||
| expect(state.urlPages()).to.eql(pages) | ||
| it "urlLocs() is [#{locs}]", -> | ||
| expect(state.urlLocs()).to.eql(locs) | ||
| describe 'setUrl', -> | ||
| beforeEach -> | ||
| actual = null | ||
| title = 'Welcome Visitors' | ||
| global.location = new URL('https://example.com/view/welcome-visitors') | ||
| global.document = {title: null} | ||
| it 'does not push url to history for the same location', -> | ||
| state.pagesInDom = -> ['welcome-visitors'] | ||
| state.locsInDom = -> ['view'] | ||
| state.setUrl() | ||
| expect(actual).to.be(null) | ||
| it 'pushes url to history when location changes', -> | ||
| state.pagesInDom = -> ['welcome-visitors', 'welcome-visitors'] | ||
| state.locsInDom = -> ['view', 'fed.wiki.org'] | ||
| state.setUrl() | ||
| expect(global.document.title).to.be('Welcome Visitors') | ||
| expect(actual.pathname).to.be('/view/welcome-visitors/fed.wiki.org/welcome-visitors') | ||
|
|
||
| context 'using URL.hash', -> | ||
| for [sfw, locs, pages] in tests | ||
| context sfw, -> | ||
| beforeEach -> | ||
| global.location = new URL("https://example.com#sfw=#{sfw}") | ||
| it "urlPages() is [#{pages}]", -> | ||
| expect(state.urlPages()).to.eql(pages) | ||
| it "urlLocs() is [#{locs}]", -> | ||
| expect(state.urlLocs()).to.eql(locs) | ||
| describe 'setUrl', -> | ||
| beforeEach -> | ||
| actual = null | ||
| title = 'Welcome Visitors' | ||
| global.location = new URL('https://example.com#sfw=view/welcome-visitors') | ||
| global.document = {title: null} | ||
| it 'does not push url to history for the same location', -> | ||
| state.pagesInDom = -> ['welcome-visitors'] | ||
| state.locsInDom = -> ['view'] | ||
| state.setUrl() | ||
| expect(actual).to.be(null) | ||
| it 'pushes url to history when location changes', -> | ||
| state.pagesInDom = -> ['welcome-visitors', 'welcome-visitors'] | ||
| state.locsInDom = -> ['view', 'fed.wiki.org'] | ||
| state.setUrl() | ||
| expect(global.document.title).to.be('Welcome Visitors') | ||
| params = new URLSearchParams(actual.hash.substring(1)) | ||
| expect(params.get('sfw')) | ||
| .to.be('view/welcome-visitors/fed.wiki.org/welcome-visitors') | ||
|
|
||
| it 'setUrl() defaults to URL.hash', -> | ||
| actual = null | ||
| global.location = new URL('https://example.com') | ||
| global.document = {title: null} | ||
| state.pagesInDom = -> ['welcome-visitors'] | ||
| state.locsInDom = -> ['view'] | ||
| state.setUrl() | ||
| expect(actual.pathname).to.be('/') | ||
| params = new URLSearchParams(actual.hash.substring(1)) | ||
| expect(params.get('sfw')).to.be('view/welcome-visitors') | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is where we introduce more confusion to the bootstrapping of wiki-client.
We replace the contents of
<section class="main">with our own page divs computed fromwindow.location.For comparison, here is where @paul90 made a similar intervention in the DAT/hypercore variant.
paul90/wiki-client-dat-variant@15cb656#diff-5b6ac0ea3ef5483a6e071c1ff85d99a3c4ef31d97b567deff46686fb93a25921R17-R33
For the time being, we are deferring the work to understand and change the existing wiki-client bootstrap.