mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 10:01:29 -07:00
Disable tips after 10 runs (#17101)
This commit is contained in:
47
packages/cli/src/ui/hooks/useTips.test.ts
Normal file
47
packages/cli/src/ui/hooks/useTips.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
renderHookWithProviders,
|
||||
persistentStateMock,
|
||||
} from '../../test-utils/render.js';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { useTips } from './useTips.js';
|
||||
|
||||
describe('useTips()', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return false and call set(1) if state is undefined', () => {
|
||||
const { result } = renderHookWithProviders(() => useTips());
|
||||
|
||||
expect(result.current.showTips).toBe(true);
|
||||
|
||||
expect(persistentStateMock.set).toHaveBeenCalledWith('tipsShown', 1);
|
||||
expect(persistentStateMock.get('tipsShown')).toBe(1);
|
||||
});
|
||||
|
||||
it('should return false and call set(6) if state is 5', () => {
|
||||
persistentStateMock.setData({ tipsShown: 5 });
|
||||
|
||||
const { result } = renderHookWithProviders(() => useTips());
|
||||
|
||||
expect(result.current.showTips).toBe(true);
|
||||
|
||||
expect(persistentStateMock.get('tipsShown')).toBe(6);
|
||||
});
|
||||
|
||||
it('should return true if state is 10', () => {
|
||||
persistentStateMock.setData({ tipsShown: 10 });
|
||||
|
||||
const { result } = renderHookWithProviders(() => useTips());
|
||||
|
||||
expect(result.current.showTips).toBe(false);
|
||||
expect(persistentStateMock.set).not.toHaveBeenCalled();
|
||||
expect(persistentStateMock.get('tipsShown')).toBe(10);
|
||||
});
|
||||
});
|
||||
26
packages/cli/src/ui/hooks/useTips.ts
Normal file
26
packages/cli/src/ui/hooks/useTips.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { persistentState } from '../../utils/persistentState.js';
|
||||
|
||||
interface UseTipsResult {
|
||||
showTips: boolean;
|
||||
}
|
||||
|
||||
export function useTips(): UseTipsResult {
|
||||
const [tipsCount] = useState(() => persistentState.get('tipsShown') ?? 0);
|
||||
|
||||
const showTips = tipsCount < 10;
|
||||
|
||||
useEffect(() => {
|
||||
if (showTips) {
|
||||
persistentState.set('tipsShown', tipsCount + 1);
|
||||
}
|
||||
}, [tipsCount, showTips]);
|
||||
|
||||
return { showTips };
|
||||
}
|
||||
Reference in New Issue
Block a user