diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index f783d58187..51f526f889 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -91,6 +91,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1700000001 + updated_unix: 1700000001 - id: 4 @@ -152,6 +154,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1700000002 + updated_unix: 1700000002 - id: 6 @@ -182,6 +186,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1710000001 + updated_unix: 1710000001 - id: 7 @@ -212,6 +218,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1710000003 + updated_unix: 1710000003 - id: 8 @@ -242,6 +250,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1710000002 + updated_unix: 1710000002 - id: 9 @@ -968,6 +978,8 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + created_unix: 1700000003 + updated_unix: 1700000003 - id: 33 @@ -1811,4 +1823,4 @@ template_id: 0 size: 0 is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false \ No newline at end of file + close_issues_via_commit_in_any_branch: false diff --git a/models/organization/org_test.go b/models/organization/org_test.go index fa4c512189..39ccc2d466 100644 --- a/models/organization/org_test.go +++ b/models/organization/org_test.go @@ -299,8 +299,8 @@ func TestAccessibleReposEnv_RepoIDs(t *testing.T) { require.NoError(t, err) assert.Equal(t, expectedRepoIDs, repoIDs) } - testSuccess(2, []int64{3, 5, 32}) - testSuccess(4, []int64{3, 32}) + testSuccess(2, []int64{32, 5, 3}) + testSuccess(4, []int64{32, 3}) } func TestAccessibleReposEnv_Repos(t *testing.T) { @@ -318,8 +318,8 @@ func TestAccessibleReposEnv_Repos(t *testing.T) { } assert.Equal(t, expectedRepos, repos) } - testSuccess(2, []int64{3, 5, 32}) - testSuccess(4, []int64{3, 32}) + testSuccess(2, []int64{32, 5, 3}) + testSuccess(4, []int64{32, 3}) } func TestAccessibleReposEnv_MirrorRepos(t *testing.T) { diff --git a/models/repo/search.go b/models/repo/search.go index a73d9fc215..ffb8e26745 100644 --- a/models/repo/search.go +++ b/models/repo/search.go @@ -36,6 +36,7 @@ var OrderByMap = map[string]map[string]db.SearchOrderBy{ var OrderByFlatMap = map[string]db.SearchOrderBy{ "newest": OrderByMap["desc"]["created"], "oldest": OrderByMap["asc"]["created"], + "recentupdate": OrderByMap["desc"]["updated"], "leastupdate": OrderByMap["asc"]["updated"], "reversealphabetically": OrderByMap["desc"]["alpha"], "alphabetically": OrderByMap["asc"]["alpha"], diff --git a/tests/integration/last_updated_time_test.go b/tests/integration/last_updated_time_test.go index e7bf3a4a07..54c0eeb629 100644 --- a/tests/integration/last_updated_time_test.go +++ b/tests/integration/last_updated_time_test.go @@ -16,11 +16,10 @@ func TestRepoLastUpdatedTime(t *testing.T) { user := "user2" session := loginUser(t, user) - req := NewRequest(t, "GET", path.Join("explore", "repos")) + req := NewRequest(t, "GET", "/explore/repos?q=repo1") resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) node := doc.doc.Find(".flex-item-body").First() - { buf := "" findTextNonNested(t, node, &buf) diff --git a/tests/integration/org_test.go b/tests/integration/org_test.go index 912ad0ca0b..74579d7d51 100644 --- a/tests/integration/org_test.go +++ b/tests/integration/org_test.go @@ -28,6 +28,7 @@ func TestOrgRepos(t *testing.T) { users = []string{"user1", "user2"} cases = map[string][]string{ "alphabetically": {"repo21", "repo3", "repo5"}, + "recentupdate": {"repo21", "repo5", "repo3"}, "reversealphabetically": {"repo5", "repo3", "repo21"}, } ) diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index 73976b9a35..5f803b032d 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -819,3 +819,27 @@ func TestUserTOTPEnrolled(t *testing.T) { assert.True(t, called) }) } + +func TestUserRepos(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + cases := map[string][]string{ + "alphabetically": {"repo6", "repo7", "repo8"}, + "recentupdate": {"repo7", "repo8", "repo6"}, + "reversealphabetically": {"repo8", "repo7", "repo6"}, + } + + session := loginUser(t, "user10") + for sortBy, repos := range cases { + req := NewRequest(t, "GET", "/user10?sort="+sortBy) + resp := session.MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + + sel := htmlDoc.doc.Find("a.name") + assert.Len(t, repos, len(sel.Nodes)) + for i := 0; i < len(repos); i++ { + assert.EqualValues(t, repos[i], strings.TrimSpace(sel.Eq(i).Text())) + } + } +}