mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-14 14:57:21 +00:00
When you access Actions logs, there is a momentary render of a partially blank screen such as this:  This is caused by the `RepoActionView` Vue component having no data. It then performs a fetch to two APIs in parallel (shown here as `/0` and `/artifacts`) to retrieve the steps and artifacts for the action run, and then it renders the page. And then, even if the job is complete and the user hasn't yet interacted to expand any logs, it performs the same API calls a second time.  This PR fixes both problems by: - Injecting the initial data for the Action's steps & Artifacts into the initial page render, and using that data into the `RepoActionView` to serve as its initial data load. - No longer unconditionally starting a second invocation of `loadJob` 1 second later, as the initial data can be used to determine whether the job is still running and requires an interval refresh. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests **WIP** - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [x] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - User Interface bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/9099): <!--number 9099 --><!--line 0 --><!--description cHJldmVudCBpbml0aWFsICdibGFuaycgZGlzcGxheSBvZiBhY3Rpb24gbG9ncyB2aWV3LCByZW1vdmUgdW5uZWNlc3NhcnkgQVBJIGNhbGxz-->prevent initial 'blank' display of action logs view, remove unnecessary API calls<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9099 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
121 lines
3.9 KiB
Go
121 lines
3.9 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// HTMLDoc struct
|
|
type HTMLDoc struct {
|
|
doc *goquery.Document
|
|
}
|
|
|
|
// NewHTMLParser parse html file
|
|
func NewHTMLParser(t testing.TB, body *bytes.Buffer) *HTMLDoc {
|
|
t.Helper()
|
|
doc, err := goquery.NewDocumentFromReader(body)
|
|
require.NoError(t, err)
|
|
return &HTMLDoc{doc: doc}
|
|
}
|
|
|
|
func (doc *HTMLDoc) AssertAttrPredicate(t testing.TB, selector, attr string, predicate func(attrValue string) bool) bool {
|
|
t.Helper()
|
|
selection := doc.doc.Find(selector)
|
|
require.NotEmpty(t, selection, selector)
|
|
|
|
actual, exists := selection.Attr(attr)
|
|
require.True(t, exists, "%s not found in %s", attr, selection.Text())
|
|
|
|
return predicate(actual)
|
|
}
|
|
|
|
func (doc *HTMLDoc) AssertAttrEqual(t testing.TB, selector, attr, expected string) bool {
|
|
t.Helper()
|
|
return doc.AssertAttrPredicate(t, selector, attr, func(actual string) bool {
|
|
return assert.Equal(t, expected, actual)
|
|
})
|
|
}
|
|
|
|
// GetInputValueByID for get input value by id
|
|
func (doc *HTMLDoc) GetInputValueByID(id string) string {
|
|
text, _ := doc.doc.Find("#" + id).Attr("value")
|
|
return text
|
|
}
|
|
|
|
// GetInputValueByName for get input value by name
|
|
func (doc *HTMLDoc) GetInputValueByName(name string) string {
|
|
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
|
return text
|
|
}
|
|
|
|
func (doc *HTMLDoc) AssertDropdown(t testing.TB, name string) *goquery.Selection {
|
|
t.Helper()
|
|
|
|
dropdownGroup := doc.Find(fmt.Sprintf(".dropdown:has(input[name='%s'])", name))
|
|
assert.Equal(t, 1, dropdownGroup.Length(), "%s dropdown does not exist", name)
|
|
return dropdownGroup
|
|
}
|
|
|
|
// Assert that a dropdown has at least one non-empty option
|
|
func (doc *HTMLDoc) AssertDropdownHasOptions(t testing.TB, dropdownName string) {
|
|
t.Helper()
|
|
|
|
options := doc.AssertDropdown(t, dropdownName).Find(".menu [data-value]:not([data-value=''])")
|
|
assert.Positive(t, options.Length(), "%s dropdown has no options", dropdownName)
|
|
}
|
|
|
|
func (doc *HTMLDoc) AssertDropdownHasSelectedOption(t testing.TB, dropdownName, expectedValue string) {
|
|
t.Helper()
|
|
|
|
dropdownGroup := doc.AssertDropdown(t, dropdownName)
|
|
|
|
selectedValue, _ := dropdownGroup.Find(fmt.Sprintf("input[name='%s']", dropdownName)).Attr("value")
|
|
assert.Equal(t, expectedValue, selectedValue, "%s dropdown doesn't have expected value selected", dropdownName)
|
|
|
|
dropdownValues := dropdownGroup.Find(".menu [data-value]").Map(func(i int, s *goquery.Selection) string {
|
|
value, _ := s.Attr("data-value")
|
|
return value
|
|
})
|
|
assert.Contains(t, dropdownValues, expectedValue, "%s dropdown doesn't have an option with expected value", dropdownName)
|
|
}
|
|
|
|
// Find gets the descendants of each element in the current set of
|
|
// matched elements, filtered by a selector. It returns a new Selection
|
|
// object containing these matched elements.
|
|
func (doc *HTMLDoc) Find(selector string) *goquery.Selection {
|
|
return doc.doc.Find(selector)
|
|
}
|
|
|
|
// FindByText gets all elements by selector that also has the given text
|
|
func (doc *HTMLDoc) FindByText(selector, text string) *goquery.Selection {
|
|
return doc.doc.Find(selector).FilterFunction(func(i int, s *goquery.Selection) bool {
|
|
return s.Text() == text
|
|
})
|
|
}
|
|
|
|
// GetCSRF for getting CSRF token value from input
|
|
func (doc *HTMLDoc) GetCSRF() string {
|
|
return doc.GetInputValueByName("_csrf")
|
|
}
|
|
|
|
// AssertSelection check if selection exists or does not exist depending on checkExists
|
|
func (doc *HTMLDoc) AssertSelection(t testing.TB, selection *goquery.Selection, checkExists bool) {
|
|
if checkExists {
|
|
assert.Equal(t, 1, selection.Length())
|
|
} else {
|
|
assert.Equal(t, 0, selection.Length())
|
|
}
|
|
}
|
|
|
|
// AssertElement check if element by selector exists or does not exist depending on checkExists
|
|
func (doc *HTMLDoc) AssertElement(t testing.TB, selector string, checkExists bool) {
|
|
doc.AssertSelection(t, doc.doc.Find(selector), checkExists)
|
|
}
|