Hide redeemed reset cards from the account menu
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron';
|
||||
|
||||
test.describe('Account reset-card wallet', () => {
|
||||
test('redeems an available card and refreshes the authoritative point balance', async ({ launchElectronApp }) => {
|
||||
test('hides a redeemed card and refreshes the authoritative point balance', async ({ launchElectronApp }, testInfo) => {
|
||||
const app = await launchElectronApp({ skipSetup: true });
|
||||
try {
|
||||
const page = await getStableWindow(app);
|
||||
@@ -108,7 +108,10 @@ test.describe('Account reset-card wallet', () => {
|
||||
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('可使用');
|
||||
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('有效期至 2099-09-15');
|
||||
await page.getByTestId('sidebar-reset-card-redeem-card-e2e').click();
|
||||
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('已使用');
|
||||
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toHaveCount(0);
|
||||
await expect(page.getByTestId('sidebar-reset-cards-drawer')).toContainText('暂无未使用的重置卡。');
|
||||
await expect(page.getByTestId('sidebar-reset-card-available-count')).toHaveCount(0);
|
||||
await page.screenshot({ path: testInfo.outputPath('used-reset-card-hidden.png') });
|
||||
|
||||
await page.getByTestId('sidebar-account-usage-menuitem').click();
|
||||
await expect(page.getByTestId('sidebar-weekly-token-points')).toContainText('500 / 500 点');
|
||||
|
||||
@@ -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