@@ -13,6 +13,7 @@ import (
1313
1414 auth_model "code.gitea.io/gitea/models/auth"
1515 api "code.gitea.io/gitea/modules/structs"
16+ "code.gitea.io/gitea/modules/util"
1617 "code.gitea.io/gitea/routers/web/shared/user"
1718
1819 "github.com/stretchr/testify/assert"
@@ -56,98 +57,76 @@ func TestOrgProfile(t *testing.T) {
5657}
5758
5859func testOrgProfile (t * testing.T , u * url.URL ) {
59- // selectors: "[data-profile-view-as-member=true/false]", "#org-home-view-as-dropdown" (indicate whether the view as dropdown menu is present)
60+ const contentPublicReadme = "Public Readme Content"
61+ const contentPrivateReadme = "Private Readme Content"
62+ // HTML: "#org-home-view-as-dropdown" (indicate whether the view as dropdown menu is present)
6063
6164 // PART 1: Test Both Private and Public
62- createTestProfile (t , "org3" , user .RepoNameProfile , "Public Readme" )
63- createTestProfile (t , "org3" , user .RepoNameProfilePrivate , "Private Readme" )
65+ createTestProfile (t , "org3" , user .RepoNameProfile , contentPublicReadme )
66+ createTestProfile (t , "org3" , user .RepoNameProfilePrivate , contentPrivateReadme )
6467
6568 // Anonymous User
6669 req := NewRequest (t , "GET" , "org3" )
6770 resp := MakeRequest (t , req , http .StatusOK )
68- htmlDoc := NewHTMLParser (t , resp .Body )
69-
70- profileDivs := htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
71- assert .EqualValues (t , 1 , profileDivs .Length ())
72-
73- dropDownDiv := htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
74- assert .EqualValues (t , 0 , dropDownDiv .Length ())
71+ bodyString := util .UnsafeBytesToString (resp .Body .Bytes ())
72+ assert .Contains (t , bodyString , contentPublicReadme )
73+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
7574
7675 // Logged in but not member
7776 session := loginUser (t , "user24" )
7877 req = NewRequest (t , "GET" , "org3" )
7978 resp = session .MakeRequest (t , req , http .StatusOK )
80- htmlDoc = NewHTMLParser (t , resp .Body )
81-
82- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
83- assert .EqualValues (t , 1 , profileDivs .Length ())
84-
85- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
86- assert .EqualValues (t , 0 , dropDownDiv .Length ())
79+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
80+ assert .Contains (t , bodyString , contentPublicReadme )
81+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
8782
8883 // Site Admin
8984 session = loginUser (t , "user1" )
9085 req = NewRequest (t , "GET" , "org3" )
9186 resp = session .MakeRequest (t , req , http .StatusOK )
92- htmlDoc = NewHTMLParser (t , resp .Body )
93-
94- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
95- assert .EqualValues (t , 1 , profileDivs .Length ())
96-
97- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
98- assert .EqualValues (t , 1 , dropDownDiv .Length ())
87+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
88+ assert .Contains (t , bodyString , contentPublicReadme )
89+ assert .Contains (t , bodyString , `id="org-home-view-as-dropdown"` )
9990
10091 req = NewRequest (t , "GET" , "/org3?view_as=member" )
10192 resp = session .MakeRequest (t , req , http .StatusOK )
102- htmlDoc = NewHTMLParser (t , resp .Body )
103-
104- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=true]" )
105- assert .EqualValues (t , 1 , profileDivs .Length ())
93+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
94+ assert .Contains (t , bodyString , contentPrivateReadme )
95+ assert .Contains (t , bodyString , `id="org-home-view-as-dropdown"` )
10696
10797 req = NewRequest (t , "GET" , "/org3?view_as=public" )
10898 resp = session .MakeRequest (t , req , http .StatusOK )
109- htmlDoc = NewHTMLParser (t , resp .Body )
110-
111- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
112- assert .EqualValues (t , 1 , profileDivs .Length ())
99+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
100+ assert .Contains (t , bodyString , contentPublicReadme )
101+ assert .Contains (t , bodyString , `id="org-home-view-as-dropdown"` )
113102
114103 // PART 2: Each org has either one of private pr public profile
115- createTestProfile (t , "org41" , user .RepoNameProfile , "Public Readme" )
116- createTestProfile (t , "org42" , user .RepoNameProfilePrivate , "Private Readme" )
104+ createTestProfile (t , "org41" , user .RepoNameProfile , contentPublicReadme )
105+ createTestProfile (t , "org42" , user .RepoNameProfilePrivate , contentPrivateReadme )
117106
118107 // Anonymous User
119108 req = NewRequest (t , "GET" , "/org41" )
120109 resp = MakeRequest (t , req , http .StatusOK )
121- htmlDoc = NewHTMLParser (t , resp .Body )
122- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
123- assert .EqualValues (t , 1 , profileDivs .Length ())
124- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
125- assert .EqualValues (t , 0 , dropDownDiv .Length ())
110+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
111+ assert .Contains (t , bodyString , contentPublicReadme )
112+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
126113
127114 req = NewRequest (t , "GET" , "/org42" )
128115 resp = MakeRequest (t , req , http .StatusOK )
129- htmlDoc = NewHTMLParser (t , resp .Body )
130- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
131- assert .EqualValues (t , 0 , profileDivs .Length ())
132- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
133- assert .EqualValues (t , 0 , profileDivs .Length ())
134- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
135- assert .EqualValues (t , 0 , dropDownDiv .Length ())
116+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
117+ assert .NotContains (t , bodyString , contentPrivateReadme )
118+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
136119
137120 // Site Admin
138121 req = NewRequest (t , "GET" , "/org41" )
139122 resp = session .MakeRequest (t , req , http .StatusOK )
140- htmlDoc = NewHTMLParser (t , resp .Body )
141- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=false]" )
142- assert .EqualValues (t , 1 , profileDivs .Length ())
143- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
144- assert .EqualValues (t , 0 , dropDownDiv .Length ())
123+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
124+ assert .Contains (t , bodyString , contentPublicReadme )
125+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
145126
146127 req = NewRequest (t , "GET" , "/org42" )
147128 resp = session .MakeRequest (t , req , http .StatusOK )
148- htmlDoc = NewHTMLParser (t , resp .Body )
149- profileDivs = htmlDoc .doc .Find ("[data-profile-view-as-member=true]" )
150- assert .EqualValues (t , 1 , profileDivs .Length ())
151- dropDownDiv = htmlDoc .doc .Find ("#org-home-view-as-dropdown" )
152- assert .EqualValues (t , 0 , dropDownDiv .Length ())
129+ bodyString = util .UnsafeBytesToString (resp .Body .Bytes ())
130+ assert .Contains (t , bodyString , contentPrivateReadme )
131+ assert .NotContains (t , bodyString , `id="org-home-view-as-dropdown"` )
153132}
0 commit comments