Skip to content

Commit 3f673ce

Browse files
BeowulfR0ko
authored andcommitted
fix(ui): show commit icon in branch dropdown button when viewing a commit (go-gitea#7571)
Closes https://codeberg.org/forgejo/forgejo/issues/7570 Fixed never running repo-home e2e test for language switcher Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7571 Reviewed-by: 0ko <[email protected]> Co-authored-by: Beowulf <[email protected]> Co-committed-by: Beowulf <[email protected]>
1 parent 6d7b1f8 commit 3f673ce

File tree

5 files changed

+50
-25
lines changed

5 files changed

+50
-25
lines changed

templates/repo/branch_dropdown.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@
7777
{{else}}
7878
{{if eq $type "tag"}}
7979
{{svg "octicon-tag"}}
80-
{{else}}
80+
{{else if eq $type "branch"}}
8181
{{svg "octicon-git-branch"}}
82+
{{else}}
83+
{{svg "octicon-git-commit"}}
8284
{{end}}
8385
<strong ref="dropdownRefName" class="tw-ml-2 tw-inline-block gt-ellipsis">{{if and .root.IsViewTag (not .noTag)}}{{.root.TagName}}{{else if .root.IsViewBranch}}{{.root.BranchName}}{{else}}{{ShortSha .root.CommitID}}{{end}}</strong>
8486
{{end}}

tests/e2e/declare_repos_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"forgejo.org/models/unittest"
1414
user_model "forgejo.org/models/user"
1515
"forgejo.org/modules/git"
16+
"forgejo.org/modules/indexer/stats"
1617
files_service "forgejo.org/services/repository/files"
1718
"forgejo.org/tests"
1819

@@ -36,6 +37,10 @@ func DeclareGitRepos(t *testing.T) func() {
3637
Filename: "testfile",
3738
Versions: []string{"hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
3839
}}),
40+
newRepo(t, 2, "language-stats-test", []FileChanges{{
41+
Filename: "main.rs",
42+
Versions: []string{"fn main() {", "println!(\"Hello World!\");", "}"},
43+
}}),
3944
newRepo(t, 2, "mentions-highlighted", []FileChanges{
4045
{
4146
Filename: "history1.md",
@@ -105,5 +110,8 @@ func newRepo(t *testing.T, userID int64, repoName string, fileChanges []FileChan
105110
}
106111
}
107112

113+
err := stats.UpdateRepoIndexer(somerepo)
114+
require.NoError(t, err)
115+
108116
return cleanupFunc
109117
}

tests/e2e/repo-home.e2e.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/e2e/repo-home.test.e2e.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @watch start
2+
// web_src/js/components/RepoBranchTagSelector.vue
3+
// web_src/js/features/common-global.js
4+
// web_src/css/repo.css
5+
// @watch end
6+
7+
import {expect} from '@playwright/test';
8+
import {save_visual, test} from './utils_e2e.ts';
9+
10+
test('Language stats bar', async ({page}) => {
11+
const response = await page.goto('/user2/language-stats-test');
12+
expect(response?.status()).toBe(200);
13+
14+
await expect(page.locator('#language-stats-legend')).toBeHidden();
15+
16+
await page.click('#language-stats-bar');
17+
await expect(page.locator('#language-stats-legend')).toBeVisible();
18+
await save_visual(page);
19+
20+
await page.click('#language-stats-bar');
21+
await expect(page.locator('#language-stats-legend')).toBeHidden();
22+
await save_visual(page);
23+
});
24+
25+
test('Branch selector commit icon', async ({page}) => {
26+
const response = await page.goto('/user2/repo1');
27+
expect(response?.status()).toBe(200);
28+
29+
await expect(page.locator('.branch-dropdown-button svg.octicon-git-branch')).toBeVisible();
30+
31+
await page.goto('/user2/repo1/src/commit/65f1bf27bc');
32+
await expect(page.locator('.branch-dropdown-button svg.octicon-git-commit')).toBeVisible();
33+
});

web_src/js/components/RepoBranchTagSelector.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ const sfc = {
5454
if (this.viewType === 'tree') {
5555
this.isViewTree = true;
5656
this.refNameText = this.commitIdShort;
57-
} else if (this.viewType === 'tag') {
57+
} else if (this.viewType === 'branch') {
58+
this.isViewBranch = true;
59+
this.refNameText = this.viewType;
60+
} else {
5861
this.isViewTag = true;
5962
this.refNameText = this.tagName;
60-
} else {
61-
this.isViewBranch = true;
62-
this.refNameText = this.branchName;
6363
}
6464
6565
document.body.addEventListener('click', (event) => {
@@ -252,7 +252,8 @@ export default sfc; // activate IDE's Vue plugin
252252
<template v-if="release">{{ textReleaseCompare }}</template>
253253
<template v-else>
254254
<svg-icon v-if="isViewTag" name="octicon-tag"/>
255-
<svg-icon v-else name="octicon-git-branch"/>
255+
<svg-icon v-else-if="isViewBranch" name="octicon-git-branch"/>
256+
<svg-icon v-else name="octicon-git-commit"/>
256257
<strong ref="dropdownRefName" class="tw-ml-2 tw-inline-block gt-ellipsis">{{ refNameText }}</strong>
257258
</template>
258259
</span>

0 commit comments

Comments
 (0)