fix(typecheck): type Grove dialog state (#1521)

This commit is contained in:
chioarub
2026-06-09 08:18:04 +08:00
committed by GitHub
parent 8527a04e9b
commit f726685ff0
2 changed files with 110 additions and 4 deletions
+4 -4
View File
@@ -141,15 +141,15 @@ function PostGracePeriodContentBody() {
}
return t6;
}
export function GroveDialog(t0) {
export function GroveDialog(t0: Props) {
const $ = _c(34);
const {
showIfAlreadyViewed,
location,
onDone
} = t0;
const [shouldShowDialog, setShouldShowDialog] = useState(null);
const [groveConfig, setGroveConfig] = useState(null);
const [shouldShowDialog, setShouldShowDialog] = useState<boolean | null>(null);
const [groveConfig, setGroveConfig] = useState<GroveConfig | null>(null);
let t1;
let t2;
if ($[0] !== location || $[1] !== onDone || $[2] !== showIfAlreadyViewed) {
@@ -354,7 +354,7 @@ type PrivacySettingsDialogProps = {
domainExcluded?: boolean;
onDone(): void;
};
export function PrivacySettingsDialog(t0) {
export function PrivacySettingsDialog(t0: PrivacySettingsDialogProps) {
const $ = _c(17);
const {
settings,
+106
View File
@@ -0,0 +1,106 @@
import { describe, expect, test } from 'bun:test'
import {
calculateShouldShowGrove,
type AccountSettings,
type ApiResult,
type GroveConfig,
} from './grove.js'
const DAY_MS = 24 * 60 * 60 * 1000
function settings(
overrides: Partial<AccountSettings> = {},
): ApiResult<AccountSettings> {
return {
success: true,
data: {
grove_enabled: null,
grove_notice_viewed_at: null,
...overrides,
},
}
}
function config(overrides: Partial<GroveConfig> = {}): ApiResult<GroveConfig> {
return {
success: true,
data: {
grove_enabled: true,
domain_excluded: false,
notice_is_grace_period: true,
notice_reminder_frequency: null,
...overrides,
},
}
}
describe('calculateShouldShowGrove', () => {
test('hides the dialog when either Grove API call failed', () => {
expect(calculateShouldShowGrove({ success: false }, config(), false)).toBe(
false,
)
expect(calculateShouldShowGrove(settings(), { success: false }, false)).toBe(
false,
)
})
test('hides the dialog after the user has already chosen either setting', () => {
expect(
calculateShouldShowGrove(
settings({ grove_enabled: true }),
config(),
false,
),
).toBe(false)
expect(
calculateShouldShowGrove(
settings({ grove_enabled: false }),
config(),
false,
),
).toBe(false)
})
test('uses reminder frequency during the grace period', () => {
const recentlyViewed = new Date(Date.now() - 6 * DAY_MS).toISOString()
const reminderExpired = new Date(Date.now() - 8 * DAY_MS).toISOString()
const weeklyReminderConfig = config({ notice_reminder_frequency: 7 })
expect(
calculateShouldShowGrove(
settings({ grove_notice_viewed_at: recentlyViewed }),
weeklyReminderConfig,
false,
),
).toBe(false)
expect(
calculateShouldShowGrove(
settings({ grove_notice_viewed_at: reminderExpired }),
weeklyReminderConfig,
false,
),
).toBe(true)
})
test('can force display for settings even after the notice was already viewed', () => {
expect(
calculateShouldShowGrove(
settings({ grove_notice_viewed_at: new Date().toISOString() }),
config(),
true,
),
).toBe(true)
})
test('shows the post-grace dialog until the user makes a choice', () => {
expect(
calculateShouldShowGrove(
settings({ grove_notice_viewed_at: new Date().toISOString() }),
config({ notice_is_grace_period: false }),
false,
),
).toBe(true)
})
})