@@ -234,6 +234,34 @@ func TestEditFileToNewBranchFork(t *testing.T) {
234234 })
235235}
236236
237+ func testEditFileDiffPreview (t * testing.T , session * TestSession , user , repo , branch , filePath string ) {
238+ // Get to the 'edit this file' page
239+ req := NewRequest (t , "GET" , path .Join (user , repo , "_edit" , branch , filePath ))
240+ resp := session .MakeRequest (t , req , http .StatusOK )
241+
242+ htmlDoc := NewHTMLParser (t , resp .Body )
243+ lastCommit := htmlDoc .GetInputValueByName ("last_commit" )
244+ assert .NotEmpty (t , lastCommit )
245+
246+ // Preview the changes
247+ req = NewRequestWithValues (t , "POST" , path .Join (user , repo , "_preview" , branch , filePath ),
248+ map [string ]string {
249+ "_csrf" : htmlDoc .GetCSRF (),
250+ "content" : "Hello, World (Edited)\n " ,
251+ },
252+ )
253+ resp = session .MakeRequest (t , req , http .StatusOK )
254+
255+ assert .Contains (t , resp .Body .String (), `<span class="added-code">Hello, World (Edited)</span>` )
256+ }
257+
258+ func TestEditFileDiffPreview (t * testing.T ) {
259+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
260+ session := loginUser (t , "user2" )
261+ testEditFileDiffPreview (t , session , "user2" , "repo1" , "master" , "README.md" )
262+ })
263+ }
264+
237265func TestDeleteFile (t * testing.T ) {
238266 onGiteaRun (t , func (t * testing.T , u * url.URL ) {
239267 session := loginUser (t , "user2" )
0 commit comments