test(shared): add unit tests for BranchDropdown component - #1544
Open
sabhi128 wants to merge 2 commits into
Open
test(shared): add unit tests for BranchDropdown component#1544sabhi128 wants to merge 2 commits into
sabhi128 wants to merge 2 commits into
Conversation
sabhi128
requested review from
hiveer,
ice201508,
jialudev,
ymh6315431,
yoiteyou and
zhendi
as code owners
August 31, 2026 13:49
There was a problem hiding this comment.
Pull request overview
Adds Vitest unit coverage for the shared BranchDropdown Vue component to validate branch fetching and selection behavior on mount and user interaction.
Changes:
- Adds a new spec file for
BranchDropdownunderfrontend/src/components/__tests__/shared/. - Introduces mocks for
useFetchApianduseRepoTabStoreto drive deterministic branch-list behavior. - Adds assertions around emitted
changeBranchevents and store resets.
Suppressed comments (2)
frontend/src/components/tests/shared/BranchDropdown.spec.js:51
- PR description mentions verifying pathname parsing / dynamic branch API querying, but the test only checks that
json()was called (and does so before awaiting mount effects). Consider asserting the actual URL passed touseFetchApiafter awaiting pending promises, and reset the captured request log between tests to avoid cross-test bleed.
beforeEach(async () => {
getApiMockFn.mockClear();
mockResetFileNotFound.mockClear();
wrapper = mount(BranchDropdown, {
props: {
currentBranch: "main"
}
});
});
it("mounts correctly", () => {
expect(wrapper.exists()).toBe(true);
});
it("fetches branches on mount and resolves them", async () => {
expect(getApiMockFn).toHaveBeenCalled();
await flushPromises();
expect(wrapper.vm.branches).toEqual([{ name: "main" }, { name: "dev" }]);
});
frontend/src/components/tests/shared/BranchDropdown.spec.js:58
- This test says "when clicked" but it calls
handleClick()directly, so it doesn’t validate that the template wiring (@click="handleClick(branch.name)") actually works. Trigger a click on the rendered dropdown item instead.
it("triggers changeBranch event and resets file not found state when clicked", async () => {
await flushPromises();
await wrapper.vm.handleClick("dev");
expect(wrapper.emitted().changeBranch[0]).toEqual(["dev"]);
expect(mockResetFileNotFound).toHaveBeenCalled();
});
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
This PR adds unit test coverage for the
BranchDropdownshared component underfrontend/src/components/shared/.Changes:
frontend/src/components/__tests__/shared/BranchDropdown.spec.jschangeBranch) and store resets (resetFileNotFound).