diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-09 20:54:11 +0200 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-09 20:53:58 +0200 |
commit | be325a30885cadaff6792c6aa79413fc1c20be5e (patch) | |
tree | 669cd79517fc15f57201f35a8937b5b9e048e699 /hugolib/menu_test.go | |
parent | bef0f281d1d9a6f58c0b50140ddb2c4e6991bc95 (diff) |
Fix IsMenuCurrent for SectionPagesMenu
Pretty sure it has worked at some point, but that PR probably has been rebased to pieces.
This refactors the fix by @dannys42 into a method, as this URL fix is applied several places.
Fixes #1114
Diffstat (limited to 'hugolib/menu_test.go')
-rw-r--r-- | hugolib/menu_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 73aeb07dd..4ec659f8d 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -319,6 +319,52 @@ func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) { assert.Equal(t, expected, unicodeRussian.URL, "uglyURLs[%t]", uglyURLs) } +// Issue #1114 +func TestSectionPagesMenu(t *testing.T) { + viper.Set("SectionPagesMenu", "spm") + defer viper.Set("SectionPagesMenu", "") + + for _, canonify := range []bool{true, false} { + doTestSectionPagesMenu(canonify, t) + } +} + +func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) { + viper.Set("CanonifyURLs", canonifyUrls) + ts := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES) + defer resetMenuTestState(ts) + + assert.Equal(t, 2, len(ts.site.Sections)) + + firstSectionPages := ts.site.Sections["first"] + assert.Equal(t, 2, len(firstSectionPages)) + secondSectionPages := ts.site.Sections["second-section"] + assert.Equal(t, 1, len(secondSectionPages)) + + nodeFirst := ts.site.newSectionListNode("first", firstSectionPages) + nodeSecond := ts.site.newSectionListNode("second-section", secondSectionPages) + + firstSectionMenuEntry := ts.findTestMenuEntryByID("spm", "first") + secondSectionMenuEntry := ts.findTestMenuEntryByID("spm", "second-section") + + assert.NotNil(t, firstSectionMenuEntry) + assert.NotNil(t, secondSectionMenuEntry) + assert.NotNil(t, nodeFirst) + assert.NotNil(t, nodeSecond) + + for _, p := range firstSectionPages { + assert.True(t, p.Page.HasMenuCurrent("spm", firstSectionMenuEntry)) + assert.False(t, p.Page.HasMenuCurrent("spm", secondSectionMenuEntry)) + assert.True(t, nodeFirst.IsMenuCurrent("spm", firstSectionMenuEntry)) + assert.False(t, nodeFirst.IsMenuCurrent("spm", secondSectionMenuEntry)) + } + + for _, p := range secondSectionPages { + assert.False(t, p.Page.HasMenuCurrent("spm", firstSectionMenuEntry)) + assert.True(t, p.Page.HasMenuCurrent("spm", secondSectionMenuEntry)) + } +} + func TestTaxonomyNodeMenu(t *testing.T) { viper.Set("CanonifyURLs", true) ts := setupMenuTests(t, MENU_PAGE_SOURCES) |