Skip to content

Improve settings test coverage for tauri-app #1730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 12, 2025

Conversation

hardingjam
Copy link
Contributor

@hardingjam hardingjam commented May 5, 2025

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Tests
    • Replaced the previous settings test suite with a new, comprehensive test file.
    • Enhanced coverage for reactive store behaviors related to accounts, networks, orderbooks, and subgraphs.
    • Validated synchronization, filtering, resetting, and edge cases in settings-related state management.
    • Improved test isolation and robustness for settings features.

@hardingjam hardingjam added this to the Test coverage, tech debt milestone May 5, 2025
@hardingjam hardingjam self-assigned this May 5, 2025
@hardingjam hardingjam added Tauri Tauri app test test code labels May 5, 2025
@hardingjam hardingjam marked this pull request as ready for review May 5, 2025 13:41
Copy link
Contributor

coderabbitai bot commented May 5, 2025

"""

Walkthrough

The previous test suite for settings-related stores was removed and replaced with a new comprehensive test file. The new tests cover synchronization and reset behaviors of multiple reactive stores related to settings, including accounts, networks, orderbooks, subgraphs, and derived store outputs. Edge cases and utility functions are also tested.

Changes

File(s) Change Summary
tauri-app/src/lib/test/settings.test.ts Deleted the entire legacy test suite for settings-related stores, removing all previous tests and setup.
tauri-app/src/tests/settings.test.ts Added a new comprehensive test suite covering reactive settings stores, derived stores, synchronization, resets, edge cases, and utility functions.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant SettingsStore
    participant DerivedStores
    participant UtilityFunctions

    Test->>SettingsStore: Update/reset settings (accounts, networks, orderbooks, subgraphs)
    SettingsStore-->>DerivedStores: Propagate changes to activeAccountsItems, activeSubgraphs, activeNetworkRef, activeOrderbookRef
    Test->>UtilityFunctions: Call resetActiveNetworkRef/resetActiveOrderbookRef
    UtilityFunctions-->>SettingsStore: Update active references based on available data
    Test->>DerivedStores: Check outputs (subgraphUrl, hasRequiredSettings, filtered orderbooks, accounts)
    Test->>SettingsStore: Simulate edge cases (invalid JSON, extra accounts)
    SettingsStore-->>DerivedStores: Cleanup and state consistency
Loading

Possibly related issues

Possibly related PRs

  • Fix blank page bug on tauri app #1749: Both PRs focus on the test suite for the settings store; the related PR removes an older test block, while this PR adds comprehensive new tests, showing direct evolution in test coverage for the same area.

Suggested reviewers

  • findolor
  • hardingjam
    """

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hardingjam hardingjam linked an issue May 5, 2025 that may be closed by this pull request
@hardingjam hardingjam requested a review from hardyjosh May 5, 2025 14:02
@findolor
Copy link
Collaborator

findolor commented May 7, 2025

@hardingjam I think we should move the tests from settings into it's own file. This is an issue I've fixed today with this PR #1749

I was getting blank page in tauri app becase vitest dependency is used in the prod build and that was causing problems. Moving the tests to a dedicated file fixed the issue so I think we can do the same here

@hardingjam
Copy link
Contributor Author

@hardingjam I think we should move the tests from settings into it's own file. This is an issue I've fixed today with this PR #1749

I was getting blank page in tauri app becase vitest dependency is used in the prod build and that was causing problems. Moving the tests to a dedicated file fixed the issue so I think we can do the same here

Updated the PR with your separate test file

Copy link
Contributor

@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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d55d422 and 3d87d75.

📒 Files selected for processing (1)
  • tauri-app/src/lib/test/settings.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tauri-app/src/lib/test/settings.test.ts (1)
tauri-app/src/lib/stores/settings.ts (15)
  • settings (26-37)
  • activeAccountsItems (101-112)
  • activeSubgraphs (127-138)
  • activeNetworkRef (43-43)
  • activeOrderbookRef (65-65)
  • resetActiveNetworkRef (231-239)
  • activeNetworkOrderbooks (66-75)
  • resetActiveOrderbookRef (219-228)
  • hasRequiredSettings (93-97)
  • subgraphUrl (83-87)
  • accounts (100-100)
  • activeAccounts (113-121)
  • activeOrderStatus (241-253)
  • hideZeroBalanceVaults (255-266)
  • orderHash (268-273)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (2)
tauri-app/src/lib/test/settings.test.ts (2)

364-380: cachedWritableStore touches localStorage – use a stub in pure-node runs

Vitest’s default “node” environment has no localStorage, so this test will throw unless:

  1. the project forces jsdom, or
  2. cachedWritableStore falls back internally.

If condition 1 is not guaranteed, explicitly stub:

import { beforeAll } from 'vitest';

beforeAll(() => {
  globalThis.localStorage ??= new (require('node-localstorage').LocalStorage)('./.tmp');
});

(or mock the API).

Prevents brittle CI failures when env changes.


400-423: 👍 Robust invalid-JSON parsing test

Nicely isolates the scenario with a dedicated key and custom (de)serializer; verifies graceful fallback.

Comment on lines 24 to 26
beforeEach(() => {
// Reset all store values
settings.set(undefined);
activeAccountsItems.set({});
activeSubgraphs.set({});

// Then set our initial test values
settings.set(mockConfigSource);
activeAccountsItems.set({
name_one: 'address_one',
name_two: 'address_two',
});
activeSubgraphs.set({
mainnet: 'https://api.thegraph.com/subgraphs/name/mainnet',
});

// Verify initial state
expect(get(settings)).toEqual(mockConfigSource);
expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
name_two: 'address_two',
});
expect(get(activeSubgraphs)).toEqual({
mainnet: 'https://api.thegraph.com/subgraphs/name/mainnet',
});
});

test('should remove account if that account is removed', () => {
// Test removing an account
const newSettings = {
...mockConfigSource,
accounts: {
name_one: 'address_one',
},
};

// Update settings - this should trigger the subscription
settings.set(newSettings);

// Check the expected result
expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
});
});

test('should remove account if the value is different', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: 'address_one',
name_two: 'new_value',
},
};

settings.set(newSettings);

expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
});
});

test('should update active subgraphs when subgraph value changes', () => {
const newSettings = {
...mockConfigSource,
subgraphs: {
mainnet: 'new value',
},
};

settings.set(newSettings);

expect(get(activeSubgraphs)).toEqual({});
});

test('should update active subgraphs when subgraph removed', () => {
const newSettings = {
...mockConfigSource,
subgraphs: {
testnet: 'testnet',
},
};

settings.set(newSettings);

expect(get(activeSubgraphs)).toEqual({});
});

test('should reset active subgraphs when subgraphs are undefined', () => {
const newSettings = {
...mockConfigSource,
subgraphs: undefined,
};

settings.set(newSettings);

expect(get(activeSubgraphs)).toEqual({});
});
});
const { test, expect } = import.meta.vitest;

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Conditional import is safe but duplicate destructuring guard can simplify

const { test, expect } = import.meta.vitest; is executed only when the block runs, so it is safe.
However, a shorter pattern is:

const { test, expect } = import.meta.vitest!;

…which avoids the extra if indent while keeping type-safety.
Optional refactor only.

Comment on lines 28 to 55
// Reset store values before each test to prevent state leakage
beforeEach(() => {
settings.set(undefined);
activeAccountsItems.set({});
activeSubgraphs.set({});
activeNetworkRef.set(undefined);
activeOrderbookRef.set(undefined);

settings.set(mockConfigSource);
activeAccountsItems.set({
name_one: 'address_one',
name_two: 'address_two'
});
activeSubgraphs.set({
mainnet: 'https://api.thegraph.com/subgraphs/name/mainnet'
});

// Verify initial state
expect(get(settings)).toEqual(mockConfigSource);
expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
name_two: 'address_two'
});
expect(get(activeSubgraphs)).toEqual({
mainnet: 'https://api.thegraph.com/subgraphs/name/mainnet'
});
});

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Repeated store-reset boilerplate – extract helper for clarity

Nearly identical beforeEach blocks reset the same set of stores across multiple describes.
Extracting a small utility avoids drift between suites and shortens tests:

function resetAllStores() {
  settings.set(undefined);
  activeAccountsItems.set({});
  activeSubgraphs.set({});
  activeNetworkRef.set(undefined);
  activeOrderbookRef.set(undefined);
}

Then call beforeEach(resetAllStores) everywhere.

Comment on lines 1 to 17
import {
settings,
activeAccountsItems,
activeSubgraphs,
activeNetworkRef,
activeOrderbookRef,
resetActiveNetworkRef,
resetActiveOrderbookRef,
activeNetworkOrderbooks,
hasRequiredSettings,
subgraphUrl,
accounts,
activeAccounts,
activeOrderStatus,
hideZeroBalanceVaults,
orderHash
} from '$lib/stores/settings';
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

⚠️ Potential issue

🛑 Tests live inside the production source tree – please move them out of src/

Placing *.test.ts files under src/lib means Vite / Tauri will still discover and transpile them for the production bundle.
A very similar arrangement already caused a blank white page in PR #1749 when the Vitest runtime crept into the app.
Even though the test body is wrapped in if (import.meta.vitest), the file itself (and therefore its dependencies) is still part of the module graph.

Action:

-tauri-app/src/lib/test/settings.test.ts
+tauri-app/tests/settings.test.ts       # or e2e/, __tests__/, etc.

and ensure vitest.config.ts includes the new folder.

This keeps the production bundle clean and avoids accidental leakage of test-only deps.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import {
settings,
activeAccountsItems,
activeSubgraphs,
activeNetworkRef,
activeOrderbookRef,
resetActiveNetworkRef,
resetActiveOrderbookRef,
activeNetworkOrderbooks,
hasRequiredSettings,
subgraphUrl,
accounts,
activeAccounts,
activeOrderStatus,
hideZeroBalanceVaults,
orderHash
} from '$lib/stores/settings';
- tauri-app/src/lib/test/settings.test.ts
+ tauri-app/tests/settings.test.ts

Comment on lines 175 to 189
test('resetActiveNetworkRef should set first available network', async () => {
settings.set(mockConfigSource);

await resetActiveNetworkRef();

expect(get(activeNetworkRef)).toBe('mainnet');
});

test('resetActiveNetworkRef should set undefined when no networks', async () => {
const emptySettings = { ...mockConfigSource, networks: {} };
settings.set(emptySettings);

await resetActiveNetworkRef();

expect(get(activeNetworkRef)).toBeUndefined();
Copy link
Contributor

@coderabbitai coderabbitai bot May 9, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

awaiting a synchronous function needlessly slows the suite

resetActiveNetworkRef() currently performs only synchronous store.set() calls (no awaited I/O).
Removing async/await:

-test('resetActiveNetworkRef should set first available network', async () => {
-  settings.set(mockConfigSource);
-  await resetActiveNetworkRef();
+test('resetActiveNetworkRef should set first available network', () => {
+  settings.set(mockConfigSource);
+  resetActiveNetworkRef();

…makes intent clearer and shaves a tick off each test.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('resetActiveNetworkRef should set first available network', async () => {
settings.set(mockConfigSource);
await resetActiveNetworkRef();
expect(get(activeNetworkRef)).toBe('mainnet');
});
test('resetActiveNetworkRef should set undefined when no networks', async () => {
const emptySettings = { ...mockConfigSource, networks: {} };
settings.set(emptySettings);
await resetActiveNetworkRef();
expect(get(activeNetworkRef)).toBeUndefined();
test('resetActiveNetworkRef should set first available network', () => {
settings.set(mockConfigSource);
resetActiveNetworkRef();
expect(get(activeNetworkRef)).toBe('mainnet');
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

@hardingjam Thank you for implementing the change! Removing the unnecessary async/await will help make the tests more efficient and clearer. Good work!

🐰✨


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@hardyjosh hardyjosh enabled auto-merge May 11, 2025 09:40
Copy link
Contributor

@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

♻️ Duplicate comments (2)
tauri-app/src/lib/test/settings.test.ts (2)

19-26: Tests still live under src/ – move them out of the production bundle

Keeping *.test.ts inside tauri-app/src means Vite / Tauri will include the file (and its vitest dependency) in the production graph.
PR #1749 showed this leads to a blank page at runtime.

Please relocate to something like tauri-app/tests/settings.test.ts and update vitest.config.ts include paths.


29-35: Extract a shared “resetStores” helper to avoid duplicated boilerplate

The beforeEach blocks across suites manually reset the same set of stores.
Centralising this logic will keep future additions in sync and make the tests shorter:

function resetAllStores() {
  settings.set(undefined);
  activeNetworkRef.set(undefined);
  activeOrderbookRef.set(undefined);
  activeAccountsItems.set({});
  activeSubgraphs.set({});
}

beforeEach(resetAllStores);

Also applies to: 140-147, 300-304

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42341c7 and ff0ac8f.

📒 Files selected for processing (1)
  • tauri-app/src/lib/test/settings.test.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
tauri-app/src/lib/test/settings.test.ts (1)
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1749
File: tauri-app/src/lib/test/settings.test.ts:8-111
Timestamp: 2025-05-07T06:58:32.478Z
Learning: In the rain.orderbook project, stores like `activeAccountsItems` and `activeSubgraphs` are derived stores that should not be directly updated, as their values are derived from the `settings` store.
🧬 Code Graph Analysis (1)
tauri-app/src/lib/test/settings.test.ts (3)
tauri-app/src/lib/stores/settings.ts (11)
  • settings (26-37)
  • activeAccountsItems (101-112)
  • activeNetworkRef (43-43)
  • activeOrderbookRef (65-65)
  • resetActiveNetworkRef (231-239)
  • activeNetworkOrderbooks (66-75)
  • resetActiveOrderbookRef (219-228)
  • hasRequiredSettings (93-97)
  • subgraphUrl (83-87)
  • accounts (100-100)
  • activeAccounts (113-121)
tauri-app/src/lib/__tests__/matchers.ts (1)
  • expect (5-5)
packages/ui-components/src/lib/index.ts (1)
  • ConfigSource (71-71)
🪛 ESLint
tauri-app/src/lib/test/settings.test.ts

[error] 14-14: 'activeOrderStatus' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 15-15: 'hideZeroBalanceVaults' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


[error] 16-16: 'orderHash' is defined but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: git-clean

@hardingjam hardingjam requested a review from hardyjosh May 12, 2025 08:05
Copy link
Contributor

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1712b16 and 2c1a378.

📒 Files selected for processing (2)
  • tauri-app/src/__tests__/settings.test.ts (1 hunks)
  • tauri-app/src/lib/test/settings.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • tauri-app/src/lib/test/settings.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: Deploy-Preview
  • GitHub Check: git-clean
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
🔇 Additional comments (12)
tauri-app/src/__tests__/settings.test.ts (12)

1-20: Well-structured imports and dependencies

The import section is clean and properly organized, importing all necessary stores and testing utilities.


21-48: Good test setup with proper isolation

The beforeEach hook correctly resets all stores and initializes them with mock data, ensuring proper test isolation. The initial state verification is a good practice to confirm the test setup worked as expected.


50-66: Test covers account removal behavior

This test correctly verifies that accounts are removed from activeAccountsItems when they are removed from the settings store.


84-130: Good coverage of edge cases for account and subgraph stores

These tests thoroughly cover important scenarios including undefined accounts, subgraph value changes, subgraph removal, and undefined subgraphs.


133-142: Proper store reset in beforeEach

The beforeEach hook correctly resets all stores to ensure test isolation.


200-226: Good test for network-specific orderbook filtering

This test correctly sets up multiple orderbooks on different networks and verifies that only orderbooks for the active network are included in the filtered results.


228-252: Well-structured test for complex interaction

This test effectively verifies the important behavior of resetting the orderbook when switching to a network that doesn't support the current orderbook.


278-291: Good coverage of hasRequiredSettings store

The tests verify both positive and negative cases for the hasRequiredSettings derived store.


293-344: Comprehensive testing of derived stores

This suite thoroughly tests the behavior of derived stores (subgraphUrl, accounts, activeAccounts) under various conditions, including edge cases like empty or undefined inputs.


347-370: Excellent testing of JSON parse error handling

This test creates a local store with intentionally invalid JSON serialization to test the error handling in the cachedWritableStore. This is a valuable test that verifies the robustness of the storage mechanism.


372-388: Good edge case testing for account synchronization

This test verifies that accounts in activeAccountsItems that don't exist in settings.accounts are properly removed when the settings store changes. This is an important edge case to prevent stale data.


1-389: Well-organized and comprehensive test coverage

The test file provides excellent coverage of settings-related functionality, with proper test isolation through beforeEach hooks and comprehensive testing of edge cases. The organization into logical test suites makes the code easy to understand and maintain.

Moving these tests to a dedicated tests directory (as mentioned in the PR comments) is a good practice that aligns with the recommendation to separate test files from production code to prevent issues with the vitest dependency being included in production builds.

Comment on lines +169 to +176
test('resetActiveNetworkRef should set first available network', async () => {
settings.set(mockConfigSource);

resetActiveNetworkRef();

expect(get(activeNetworkRef)).toBe('mainnet');
});

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider combining async/await usage with expectations

These tests are marked as async but don't use await within the test body. Either remove the async keyword or ensure there's a reason for the asynchronous test.

-  test('resetActiveNetworkRef should set first available network', async () => {
+  test('resetActiveNetworkRef should set first available network', () => {
-  test('resetActiveNetworkRef should set undefined when no networks', async () => {
+  test('resetActiveNetworkRef should set undefined when no networks', () => {

Also applies to: 177-184

Comment on lines +68 to +82
test('should remove account if the value is different', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: 'address_one',
name_two: 'new_value',
},
};

settings.set(newSettings);

expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider more descriptive test name

While the test logic is correct, the test name "should remove account if the value is different" could be more specific about what "different" means in this context. Consider renaming to "should remove account if the address value changes in settings".

-  test('should remove account if the value is different', () => {
+  test('should remove account if the address value changes in settings', () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('should remove account if the value is different', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: 'address_one',
name_two: 'new_value',
},
};
settings.set(newSettings);
expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
});
});
test('should remove account if the address value changes in settings', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: 'address_one',
name_two: 'new_value',
},
};
settings.set(newSettings);
expect(get(activeAccountsItems)).toEqual({
name_one: 'address_one',
});
});

@hardyjosh hardyjosh merged commit 42f62e2 into main May 12, 2025
17 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 13, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tauri Tauri app test test code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve test coverage for tauri-app/src/lib/stores/settings.ts
3 participants