Hide redeemed reset cards from the account menu
This commit is contained in:
@@ -241,7 +241,7 @@ describe('Sidebar V2 token point balance', () => {
|
||||
expect(screen.queryByTestId('sidebar-account-upgrade-button')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows available, expired, and redeemed reset cards with explicit dates', async () => {
|
||||
it('shows available and expired reset cards while hiding redeemed cards', async () => {
|
||||
fetchTokenPointBalanceMock.mockResolvedValue(pointBalance());
|
||||
fetchResetCardsMock.mockResolvedValue([
|
||||
resetCard(),
|
||||
@@ -259,14 +259,26 @@ describe('Sidebar V2 token point balance', () => {
|
||||
await waitFor(() => expect(within(drawer).getByText('可使用')).toBeInTheDocument());
|
||||
expect(screen.getByTestId('sidebar-reset-card-available-count')).toHaveTextContent('1');
|
||||
expect(drawer).toHaveTextContent('已过期');
|
||||
expect(drawer).toHaveTextContent('已使用');
|
||||
expect(screen.queryByTestId('sidebar-reset-card-card-redeemed')).not.toBeInTheDocument();
|
||||
expect(drawer).toHaveTextContent('有效期至 2099-09-15');
|
||||
expect(drawer).toHaveTextContent('使用于 2026-09-09');
|
||||
expect(drawer).not.toHaveTextContent('使用于');
|
||||
expect(screen.getByTestId('sidebar-reset-card-redeem-card-1')).toHaveTextContent('立即使用');
|
||||
expect(screen.queryByTestId('sidebar-reset-card-redeem-card-expired')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('redeems one card and refreshes both the card wallet and point balance', async () => {
|
||||
it('shows an empty wallet when all cards were already redeemed', async () => {
|
||||
fetchTokenPointBalanceMock.mockResolvedValue(pointBalance());
|
||||
fetchResetCardsMock.mockResolvedValue([resetCard({ status: 'redeemed', redeemed_at: '2026-09-09T00:00:00Z' })]);
|
||||
|
||||
const drawer = await renderResetCardDrawer();
|
||||
|
||||
await waitFor(() => expect(drawer).toHaveTextContent('暂无未使用的重置卡。'));
|
||||
expect(screen.queryByTestId('sidebar-reset-card-card-1')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('sidebar-reset-card-available-count')).not.toBeInTheDocument();
|
||||
expect(redeemResetCardMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('hides a redeemed card and refreshes both the card wallet and point balance', async () => {
|
||||
const available = resetCard();
|
||||
const redeemed = resetCard({
|
||||
status: 'redeemed',
|
||||
@@ -285,7 +297,9 @@ describe('Sidebar V2 token point balance', () => {
|
||||
fireEvent.click(screen.getByTestId('sidebar-reset-card-redeem-card-1'));
|
||||
|
||||
await waitFor(() => expect(redeemResetCardMock).toHaveBeenCalledWith('access-token', 'card-1'));
|
||||
await waitFor(() => expect(within(drawer).getByText('已使用')).toBeInTheDocument());
|
||||
await waitFor(() => expect(screen.queryByTestId('sidebar-reset-card-card-1')).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(drawer).toHaveTextContent('暂无未使用的重置卡。'));
|
||||
expect(screen.queryByTestId('sidebar-reset-card-available-count')).not.toBeInTheDocument();
|
||||
expect(fetchResetCardsMock.mock.calls.length).toBeGreaterThanOrEqual(2);
|
||||
expect(fetchTokenPointBalanceMock.mock.calls.length).toBeGreaterThan(balanceCallsBeforeRedeem);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user