Skip to content

Conversation

Sumit-13082004
Copy link

@Sumit-13082004 Sumit-13082004 commented Sep 24, 2025

Fixes

This PR helps fix issue #1717 by adding comprehensive unit tests for AccountDialogComponent (component + template).

Files changed

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts

Coverage

The tests provide 100% coverage...

Summary by Sourcery

Add comprehensive unit tests for AccountDialogComponent to achieve 100% coverage, verifying component rendering, default state, event emissions, and external link behavior.

Tests:

  • Add snapshot test for component rendering
  • Verify default showDialog and account initial values
  • Test handleLoginChange emission on login click and via submitLogin
  • Test openBillingPage, openUpgradeProUrl, and buyCredits methods to call API and externalLink correctly, including handling missing URL case

Summary by CodeRabbit

  • Tests
    • Expanded coverage for the account dialog, validating default visibility and account state.
    • Added tests for login submission flow and event emission.
    • Verified external link handling for billing and upgrade actions.
    • Covered credit purchase behavior, including both successful URL returns and empty URL scenarios.
    • Introduced setup to reset test mocks between runs for reliability.

Copy link

sourcery-ai bot commented Sep 24, 2025

Reviewer's Guide

This PR implements comprehensive Jest unit tests for AccountDialogComponent by setting up mock isolation, asserting default component state, verifying event emissions, and testing external link logic via API client mocks and externalUtils spies.

Sequence diagram for external link opening in AccountDialogComponent tests

sequenceDiagram
participant Test as "Jest Test"
participant Component as "AccountDialogComponent"
participant API as "apiClient"
participant Utils as "externalUtils"
Test->>Component: call openBillingPage(event)
Component->>API: getBillingUrl()
API-->>Component: { url }
Component->>Utils: externalLink(url, event)

Test->>Component: call openUpgradeProUrl(event)
Component->>API: getUpgradeProUrl()
API-->>Component: { url }
Component->>Utils: externalLink(url, event)

Test->>Component: call buyCredits(event)
Component->>API: buyCredits()
API-->>Component: { url }
alt url exists
  Component->>Utils: externalLink(url, event)
else url missing
  Component-->>Utils: (no call)
end
Loading

File-Level Changes

Change Details Files
Test setup enhancement
  • Added jest.clearAllMocks() in beforeEach to reset spies and mocks
account-dialog.component.spec.ts
Default state assertions
  • Assert component.showDialog initializes to true
  • Assert component.account is undefined by default
account-dialog.component.spec.ts
Event emission tests
  • Verify clicking login button emits handleLoginChange
  • Spy on and test submitLogin() emitting handleLoginChange
account-dialog.component.spec.ts
External link flow tests
  • Mock apiClient.getBillingUrl and test openBillingPage triggers externalLink
  • Mock apiClient.getUpgradeProUrl and test openUpgradeProUrl triggers externalLink
  • Test buyCredits(): externalLink called when URL exists and not called when empty
account-dialog.component.spec.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Adds new unit tests to the account dialog component spec, importing API client and external utilities, introducing cases for defaults, event emissions, and link-opening behaviors for billing, upgrade, and credit purchase flows, including handling of empty URLs, with mocks cleared before each test.

Changes

Cohort / File(s) Summary of Changes
Account dialog tests
packages/altair-app/src/app/modules/altair/components/altair/components/account-dialog/account-dialog.component.spec.ts
Added imports for apiClient, external utilities, and mock helper; new tests for default state, login emit, billing/upgrade URL retrieval and external opening, buyCredits success and empty-URL handling; added beforeEach to reset mocks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nose the specs, hop through each case,
Billing burrows, upgrade chase.
If URL’s empty, I’ll stay put—no race!
Mocks get groomed before each run,
Emit, assert—tests neatly spun.
With carrot-keys and tidy logs,
I ship this patch with happy hops. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change by indicating that unit tests were added for the AccountDialogComponent and that 100% coverage was achieved, matching the detailed test additions described in the changeset. It follows conventional commit style with a scope and keeps noise to a minimum. Any teammate scanning the history can immediately understand the intent and impact of this pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Summary of Changes

Hello @Sumit-13082004, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the test coverage and reliability of the AccountDialogComponent by introducing a comprehensive set of unit tests. These tests validate the component's initial state, event emissions, and its critical interactions with external API services for billing, upgrades, and credit purchases, ensuring robust behavior and maintainability.

Highlights

  • Comprehensive Unit Tests: Added a new suite of unit tests for the AccountDialogComponent to ensure its functionality and interactions are thoroughly validated.
  • 100% Code Coverage: The newly introduced tests achieve 100% code coverage for the AccountDialogComponent, as stated in the PR description.
  • Component State Verification: Tests now verify the default initial state of the component's showDialog property and the account property.
  • Event Emission Testing: Ensured that the handleLoginChange event is correctly emitted when the login button is clicked and when submitLogin is called.
  • External API Interaction Testing: Implemented tests to verify the component's interaction with apiClient for fetching billing URLs, upgrade URLs, and credit purchase URLs, and subsequently opening these links externally.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts:58` </location>
<code_context>
+    expect(component.handleLoginChange.emit).toHaveBeenCalled();
+  });
+
+  it ('should open billing page with correct URL', async () => {
+    const mockUrl = 'https://billing.example.com';
+    jest.spyOn(apiClient, 'getBillingUrl').mockResolvedValue({ url: mockUrl });
</code_context>

<issue_to_address>
**issue (complexity):** Consider combining the repetitive API call and externalLink tests into a single parameterized test and one edge-case test to reduce boilerplate.

Consider collapsing the repetitive API‐call + `externalLink` tests into a small `test.each` (and one edge‐case test) instead of writing one `it` per method. For example:

```ts
// at top of your describe:
const linkScenarios = [
  { method: 'openBillingPage', api: 'getBillingUrl' },
  { method: 'openUpgradeProUrl', api: 'getUpgradeProUrl' },
  { method: 'buyCredits', api: 'buyCredits' },
];

beforeEach(() => {
  jest.clearAllMocks();
});

// replaces the three “should open … with correct URL” tests:
test.each(linkScenarios)(
  '%s calls apiClient.%s and externalLink when url is truthy',
  async ({ method, api }) => {
    const mockUrl = `https://${api}.example.com`;
    jest.spyOn(apiClient, api).mockResolvedValue({ url: mockUrl });
    const externalSpy = jest
      .spyOn(externalUtils, 'externalLink')
      .mockImplementation(() => {});
    const ev = new MouseEvent('click');

    // @ts-ignore
    await component[method](ev);

    expect(apiClient[api]).toHaveBeenCalled();
    expect(externalSpy).toHaveBeenCalledWith(mockUrl, ev);
  }
);

// edge case for buyCredits with empty URL
it('buyCredits does NOT call externalLink when url is empty', async () => {
  jest.spyOn(apiClient, 'buyCredits').mockResolvedValue({ url: '' });
  const externalSpy = jest
    .spyOn(externalUtils, 'externalLink')
    .mockImplementation(() => {});
  const ev = new MouseEvent('click');

  await component.buyCredits(ev);

  expect(apiClient.buyCredits).toHaveBeenCalled();
  expect(externalSpy).not.toHaveBeenCalled();
});
```

This shrinks eight tests into two, removes boilerplate, and keeps full coverage.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive suite of unit tests for the AccountDialogComponent, achieving 100% test coverage. The tests are well-written and cover various aspects of the component's functionality. I have a couple of suggestions to improve the code quality further: removing an unused import and refactoring similar tests to reduce duplication. Overall, this is a great contribution to improving the test coverage of the application.

import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { mount, NgxTestWrapper } from '../../../../../testing';
import { mock, mount, NgxTestWrapper } from '../../../../../testing';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The mock utility is imported but is not used within this file. It's good practice to remove unused imports to maintain code cleanliness.

Suggested change
import { mock, mount, NgxTestWrapper } from '../../../../../testing';
import { mount, NgxTestWrapper } from '../../../../../testing';

Comment on lines +58 to +92
it ('should open billing page with correct URL', async () => {
const mockUrl = 'https://billing.example.com';
jest.spyOn(apiClient, 'getBillingUrl').mockResolvedValue({ url: mockUrl });
const mockEvent = new MouseEvent('click');
const externalSpy = jest.spyOn(externalUtils, 'externalLink').mockImplementation(() => {});

await component.openBillingPage(mockEvent);

expect(apiClient.getBillingUrl).toHaveBeenCalledWith();
expect(externalSpy).toHaveBeenCalledWith(mockUrl, mockEvent);
});

it ('should call getUpgradeProUrl and open external link', async () => {
const mockUrl = 'https://upgrade.example.com';
jest.spyOn(apiClient, 'getUpgradeProUrl').mockResolvedValue({ url: mockUrl });
const mockEvent = new MouseEvent('click');
const externalSpy = jest.spyOn(externalUtils, 'externalLink').mockImplementation(() => {});

await component.openUpgradeProUrl(mockEvent);

expect(apiClient.getUpgradeProUrl).toHaveBeenCalledWith();
expect(externalSpy).toHaveBeenCalledWith(mockUrl, mockEvent);
});

it ('should call buyCredits and open external link if url exists', async () => {
const mockUrl = 'https://credits.example.com';
jest.spyOn(apiClient, 'buyCredits').mockResolvedValue({ url: mockUrl });
const mockEvent = new MouseEvent('click');
const externalSpy = jest.spyOn(externalUtils, 'externalLink').mockImplementation(() => {});

await component.buyCredits(mockEvent);

expect(apiClient.buyCredits).toHaveBeenCalledWith();
expect(externalSpy).toHaveBeenCalledWith(mockUrl, mockEvent);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These three tests for openBillingPage, openUpgradeProUrl, and buyCredits are very similar in structure. To improve maintainability and reduce code duplication, you could refactor them into a single parameterized test using Jest's it.each.

  it.each([
    { method: 'openBillingPage', api: 'getBillingUrl', url: 'https://billing.example.com' },
    { method: 'openUpgradeProUrl', api: 'getUpgradeProUrl', url: 'https://upgrade.example.com' },
    { method: 'buyCredits', api: 'buyCredits', url: 'https://credits.example.com' },
  ])('should call $api and open external link for $method', async ({ method, api, url }) => {
    jest.spyOn(apiClient, api as keyof typeof apiClient).mockResolvedValue({ url });
    const mockEvent = new MouseEvent('click');
    const externalSpy = jest.spyOn(externalUtils, 'externalLink').mockImplementation(() => {});

    await (component as any)[method](mockEvent);

    expect(apiClient[api as keyof typeof apiClient]).toHaveBeenCalledWith();
    expect(externalSpy).toHaveBeenCalledWith(url, mockEvent);
  });

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a66aab and 5e5f55e.

📒 Files selected for processing (1)
  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
{**/__tests__/**/*.ts,**/*.{spec,test}.ts}

📄 CodeRabbit inference engine (.github/instructions/app-testing.instructions.md)

{**/__tests__/**/*.ts,**/*.{spec,test}.ts}: Use Jest as the testing framework for all tests
Organize tests next to the code under test: use a tests folder or .test.ts/.spec.ts files alongside sources
Use clear, descriptive test names explaining what is being verified
Mock dependencies with Jest to isolate the unit under test
Leverage TypeScript types in tests; define interfaces/types for expected data shapes

Files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
**/*.ts

📄 CodeRabbit inference engine (.github/instructions/app-testing.instructions.md)

Follow project code style using ESLint and Prettier

Files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
packages/altair-app/src/app/modules/altair/components/**/*.spec.ts

📄 CodeRabbit inference engine (.github/instructions/app-testing.instructions.md)

packages/altair-app/src/app/modules/altair/components/**/*.spec.ts: Only write tests for component business logic; do not test UI libraries (e.g., ng-zorro, Angular Material)
Test component business logic and methods
Test event emissions using wrapper.emitted()
Test state management and property changes of components
Test component lifecycle behavior
Always cover edge cases (null, rapid calls, invalid inputs) in component tests
Verify method return values and side effects in components
Test component interactions with services using mocks
Do not test UI library component props (e.g., nz-modal, nz-button)
Do not test template rendering details
Do not test third-party library behavior
Do not test Angular framework internals
Do not test CSS styling or visual appearance
Access component under test via wrapper.componentInstance for properties and methods
Use wrapper.emitted() to assert emitted events
Focus on asserting state changes in response to actions
Always include tests for error and edge conditions
Avoid fragile emission index tracking across multiple actions in a single test; isolate scenarios per it block

Files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
packages/altair-app/**

📄 CodeRabbit inference engine (.github/instructions/main.instructions.md)

Implement and modify the main frontend (Angular) in packages/altair-app

Files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
🧠 Learnings (15)
📓 Common learnings
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Always cover edge cases (null, rapid calls, invalid inputs) in component tests
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test component interactions with services using mocks
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Prefer unit tests; add integration tests for inter-component flows and E2E if applicable
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test component business logic and methods
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test state management and property changes of components

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test component interactions with services using mocks

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test component lifecycle behavior

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Focus on asserting state changes in response to actions

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test component business logic and methods

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Verify method return values and side effects in components

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Always cover edge cases (null, rapid calls, invalid inputs) in component tests

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Always include tests for error and edge conditions

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Only write tests for component business logic; do not test UI libraries (e.g., ng-zorro, Angular Material)

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Avoid fragile emission index tracking across multiple actions in a single test; isolate scenarios per it block

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Access component under test via wrapper.componentInstance for properties and methods

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Do not test Angular framework internals

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:57.402Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/main.instructions.md:0-0
Timestamp: 2025-09-24T19:40:57.402Z
Learning: Ensure changes are covered by appropriate tests (unit, integration, e2e); the project primarily uses Jest

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
📚 Learning: 2025-09-24T19:40:17.875Z
Learnt from: CR
PR: altair-graphql/altair#0
File: .github/instructions/app-testing.instructions.md:0-0
Timestamp: 2025-09-24T19:40:17.875Z
Learning: Applies to packages/altair-app/src/app/modules/altair/components/**/*.spec.ts : Test event emissions using wrapper.emitted()

Applied to files:

  • packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
🧬 Code graph analysis (1)
packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts (2)
packages/altair-app/src/testing/wrapper/index.ts (1)
  • component (33-35)
packages/altair-app/src/app/modules/altair/services/api/api.service.ts (1)
  • apiClient (15-17)
🪛 Biome (2.1.2)
packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts

[error] 30-30: Disallow duplicate setup and teardown hooks.

Disallow beforeEach duplicacy inside the describe function.

(lint/suspicious/noDuplicateTestHooks)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (9)
packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts (9)

5-5: LGTM: good use of the custom mount wrapper.

Mounting via the shared testing utilities keeps the spec concise and consistent.


9-10: LGTM: dependencies are correctly imported for spying.

Spying on apiClient and externalUtils at module level is appropriate here.


36-38: LGTM: verifies default state (showDialog).

Solid state assertion aligned with business logic.


40-42: LGTM: verifies default account state.

Covers the initial undefined case.


52-56: LGTM: emits on submitLogin.

Directly testing the method emission matches the guidelines to focus on component logic.


58-69: LGTM: billing flow happy path covered.

Mocks the URL fetch and asserts externalLink invocation with correct args.

Consider adding a failure-path test (mockRejectedValue) to ensure no unhandled rejections if getBillingUrl fails.


70-81: LGTM: upgrade flow happy path covered.

Appropriate spy/assertions.

Similarly, consider a rejection-path test for getUpgradeProUrl.


82-93: LGTM: credits purchase (URL present) covered.

Validates both api call and external navigation.


94-103: LGTM: credits purchase (empty URL) edge case covered.

Good guard against accidental navigation on empty URLs.

Comment on lines +30 to +31
beforeEach(() => jest.clearAllMocks());

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix duplicate test hook (Biome: noDuplicateTestHooks).

Two beforeEach hooks in the same describe block violate the linter. Move mock clearing to an afterEach or merge it into the first beforeEach.

Apply this diff:

-  beforeEach(() => jest.clearAllMocks());
+  afterEach(() => {
+    jest.clearAllMocks();
+  });

Additionally, consider avoiding a second component instantiation. Use the wrapper’s instance instead of TestBed.createComponent to reduce flakiness:

// replace:
fixture = TestBed.createComponent(AccountDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();

// with:
component = wrapper.component.componentInstance;
🧰 Tools
🪛 Biome (2.1.2)

[error] 30-30: Disallow duplicate setup and teardown hooks.

Disallow beforeEach duplicacy inside the describe function.

(lint/suspicious/noDuplicateTestHooks)

🤖 Prompt for AI Agents
In
packages/altair-app/src/app/modules/altair/components/account-dialog/account-dialog.component.spec.ts
around lines 30-31, there are two beforeEach hooks causing the
noDuplicateTestHooks lint error; move the jest.clearAllMocks() call into an
afterEach (or merge it into the existing beforeEach) to remove the duplicate
hook, and replace the second component instantiation by using the wrapper’s
component instance instead of calling TestBed.createComponent again (i.e., set
the component from wrapper.component.componentInstance and remove
fixture.detectChanges()/recreation to avoid flakiness).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant