@ -6,9 +6,14 @@ package integration
import (
"fmt"
"net/http"
"net/url"
"strings"
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
repo_service "code.gitea.io/gitea/services/repository"
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
@ -118,3 +123,37 @@ func TestCompareBranches(t *testing.T) {
inspectCompare ( t , htmlDoc , diffCount , diffChanges )
}
func TestCompareCodeExpand ( t * testing . T ) {
onGiteaRun ( t , func ( t * testing . T , u * url . URL ) {
user1 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 1 } )
repo , err := repo_service . CreateRepositoryDirectly ( db . DefaultContext , user1 , user1 , repo_service . CreateRepoOptions {
Name : "test_blob_excerpt" ,
Readme : "Default" ,
AutoInit : true ,
DefaultBranch : "main" ,
} )
assert . NoError ( t , err )
session := loginUser ( t , user1 . Name )
testEditFile ( t , session , user1 . Name , repo . Name , "main" , "README.md" , strings . Repeat ( "a\n" , 30 ) )
user2 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } )
session = loginUser ( t , user2 . Name )
testRepoFork ( t , session , user1 . Name , repo . Name , user2 . Name , "test_blob_excerpt-fork" )
testCreateBranch ( t , session , user2 . Name , "test_blob_excerpt-fork" , "branch/main" , "forked-branch" , http . StatusSeeOther )
testEditFile ( t , session , user2 . Name , "test_blob_excerpt-fork" , "forked-branch" , "README.md" , strings . Repeat ( "a\n" , 15 ) + "CHANGED\n" + strings . Repeat ( "a\n" , 15 ) )
req := NewRequest ( t , "GET" , "/user1/test_blob_excerpt/compare/main...user2/test_blob_excerpt-fork:forked-branch" )
resp := session . MakeRequest ( t , req , http . StatusOK )
htmlDoc := NewHTMLParser ( t , resp . Body )
els := htmlDoc . Find ( ` button.code-expander-button[hx-get] ` )
// all the links in the comparison should be to the forked repo&branch
assert . NotZero ( t , els . Length ( ) )
for i := 0 ; i < els . Length ( ) ; i ++ {
link := els . Eq ( i ) . AttrOr ( "hx-get" , "" )
assert . True ( t , strings . HasPrefix ( link , "/user2/test_blob_excerpt-fork/blob_excerpt/" ) )
}
} )
}