StoreApprove.test.tsx 24.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
import { act, render, screen, fireEvent, waitFor, within } from '@testing-library/react';
import { App, ConfigProvider } from 'antd';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AccessTestProvider } from '@/test/AccessTestProvider';
import type { ApprovalRow } from '@/api';
import StoreApprove from '../index';

const api = vi.hoisted(() => ({
  listScenes: vi.fn(),
  listGoodsCategories: vi.fn(),
  listApprovals: vi.fn(),
  getApproval: vi.fn(),
  passApproval: vi.fn(),
  rejectApproval: vi.fn(),
  batchPassApproval: vi.fn(),
  revokeApproval: vi.fn(),
}));
vi.mock('@/api', () => ({ store: api }));
vi.mock('@/api/modules/auth', () => ({ auth: { info: vi.fn() } }));

const row = {
  listingId: '101',
  storeName: '测试门店',
  merchantNo: 'SQ001',
  businessScene: '售后众筹',
  productCategories: ['太阳膜-原厂'],
  categoryCount: 1,
  costTotal: '1500.00',
  status: 'PENDING',
  statusLabel: '待审批',
  actionable: true,
  submitUserName: '张三',
  submitTime: '2026-10-08T10:00:00',
  pendingHours: 25,
  currentLevel: 1,
  totalLevel: 2,
};
let pending: ApprovalRow[] = [row];
let mine = [
  { ...row, listingId: '202', status: 'REJECTED', statusLabel: '已打回', actionable: false },
];
let detail = {
  ...row,
  costDecoration: '1.00',
  costMonthly: '2.00',
  costLabor: '3.00',
  items: [{ productCategory: '太阳膜-原厂', marketFee1Value: '5', marketFee1Unit: 'RATIO' }],
  approvalLogs: [],
  changeHistory: [],
};

beforeEach(() => {
  vi.resetAllMocks();
  api.listScenes.mockResolvedValue([]);
  api.listGoodsCategories.mockResolvedValue({
    records: [],
    total: 0,
    current: 1,
    size: 20,
    pages: 0,
  });
  pending = [{ ...row }];
  mine = [
    { ...row, listingId: '202', status: 'REJECTED', statusLabel: '已打回', actionable: false },
  ];
  detail = { ...detail, ...row };
  api.getApproval.mockImplementation(async () => ({ ...detail }));
  api.listApprovals.mockImplementation(
    async (tab: string, params: { current: number; size: number; keyword?: string }) => {
      const records =
        tab === 'todo' ? (params.keyword === '不存在' ? [] : pending) : tab === 'mine' ? mine : [];
      return {
        records: records.slice((params.current - 1) * params.size, params.current * params.size),
        total: records.length,
        current: params.current,
        size: params.size,
        pages: Math.ceil(records.length / params.size),
      };
    },
  );
});

function mount(permCodes = ['store:approve:view', 'store:approve:pass', 'store:approve:reject']) {
  const client = new QueryClient({
    defaultOptions: { queries: { retry: false, staleTime: 30_000 }, mutations: { retry: false } },
  });
  const page = (nextPermCodes: string[]) => (
    <ConfigProvider button={{ autoInsertSpace: false }}>
      <App>
        <QueryClientProvider client={client}>
          <AccessTestProvider permCodes={nextPermCodes}>
            <StoreApprove />
          </AccessTestProvider>
        </QueryClientProvider>
      </App>
    </ConfigProvider>
  );
  const view = render(page(permCodes));
  return { client, ...view, setPermissions: (next: string[]) => view.rerender(page(next)) };
}

// rc-util 在 test 环境把所有 aria-labelledby ID 固定为 test-id;以弹窗内确认按钮定位。
function actionDialog(confirmLabel: string) {
  const dialog = screen
    .getAllByRole('dialog')
    .find((element) => within(element).queryByRole('button', { name: confirmLabel }));
  if (!dialog) throw new Error(`未找到确认弹窗:${confirmLabel}`);
  return dialog;
}

describe('门店审批页面', () => {
  it.each(['handleOpinion', 'rejectReason'] as const)(
    '我已办的长意见支持换行省略和悬停查看全文(%s)',
    async (source) => {
      const opinion = '请核对政策。\n' + '产品分类与业务场景需要逐项确认。'.repeat(12) + 'END-OF-OPINION';
      api.listApprovals.mockResolvedValue({
        records: [{ ...row, [source]: opinion }],
        total: 1,
        current: 1,
        size: 10,
        pages: 1,
      });
      mount();
      fireEvent.click(screen.getByRole('tab', { name: /我已办/ }));
      const text = await screen.findByText(opinion, { exact: true, normalizer: (value) => value });
      fireEvent.mouseOver(text);
      const tooltip = await screen.findByRole('tooltip');
      expect(tooltip).toHaveTextContent('END-OF-OPINION');
      expect(tooltip).toHaveTextContent('产品分类与业务场景需要逐项确认。');
      expect(text).toHaveStyle({ whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' });
    },
  );

  it('按原型展示分类摘要、无币种前缀的权威成本、提交时间和停留时长', async () => {
    pending = [
      {
        ...row,
        categoryCount: 6,
        productCategories: ['太阳膜-原厂', '车衣-原厂'],
        costTotal: '90071992547409.91',
        submitTime: '2026-10-09T15:03:37',
        pendingHours: 49,
      },
    ];
    mount();
    await screen.findByText('测试门店');
    expect(screen.getByRole('columnheader', { name: '提交人 / 时间' })).toBeInTheDocument();
    expect(screen.getByText('等 6 个分类')).toBeInTheDocument();
    expect(screen.queryByText('车衣-原厂')).not.toBeInTheDocument();
    expect(screen.getByText('90,071,992,547,409.91')).toBeInTheDocument();
    expect(screen.getByText('10-09 15:03')).toBeInTheDocument();
    expect(screen.getByText('49 小时')).toBeInTheDocument();
  });

  it('使用接口新增的业务场景和产品分类选项,查询提交中文名称', async () => {
    api.listScenes.mockResolvedValue([{ id: 11, name: '新能源车交付' }]);
    api.listGoodsCategories.mockImplementation(async ({ categoryName }) => ({
      records:
        categoryName === '汽车精品'
          ? [{ id: 91, categoryType: 91, categoryName: '汽车精品专属服务', children: [] }]
          : [],
      total: categoryName === '汽车精品' ? 1 : 0,
      current: 1,
      size: 20,
      pages: categoryName === '汽车精品' ? 1 : 0,
    }));
    mount();
    await screen.findByText('测试门店');
    fireEvent.mouseDown(screen.getByLabelText('业务场景'));
    fireEvent.click(
      await screen.findByText('新能源车交付', { selector: '.ant-select-item-option-content' }),
    );
    fireEvent.mouseDown(screen.getByLabelText('产品分类'));
    fireEvent.change(screen.getByLabelText('产品分类'), { target: { value: '汽车精品' } });
    fireEvent.click(
      await screen.findByText('汽车精品专属服务', { selector: '.ant-select-item-option-content' }),
    );
    expect(api.listGoodsCategories).toHaveBeenCalledWith({
      current: 1,
      size: 20,
      categoryName: '汽车精品',
    });
    fireEvent.click(screen.getByRole('button', { name: '查询' }));
    await waitFor(() =>
      expect(api.listApprovals).toHaveBeenCalledWith(
        'todo',
        expect.objectContaining({
          businessScene: '新能源车交付',
          productCategory: '汽车精品专属服务',
        }),
      ),
    );
    expect(screen.queryByText('筛选字典加载失败')).not.toBeInTheDocument();
  });

  it('请求真实待办、展示权威金额,查询和重置作用于服务端', async () => {
    mount();
    expect(await screen.findByText('测试门店')).toBeInTheDocument();
    expect(screen.getByText('1,500')).toBeInTheDocument();
    fireEvent.change(screen.getByLabelText('门店名称 / 商户号'), { target: { value: '不存在' } });
    fireEvent.click(screen.getByRole('button', { name: '查询' }));
    await waitFor(() =>
      expect(api.listApprovals).toHaveBeenCalledWith(
        'todo',
        expect.objectContaining({ keyword: '不存在', current: 1 }),
      ),
    );
    await waitFor(() => expect(screen.queryByText('测试门店')).not.toBeInTheDocument());
    fireEvent.click(screen.getByRole('button', { name: '重置' }));
    expect(await screen.findByText('测试门店')).toBeInTheDocument();
    expect(screen.getByLabelText('门店名称 / 商户号')).toHaveValue('');
  });

  it('商务通过需确认范围,调用正确记录并读取下一节点而非前端直接生效', async () => {
    api.passApproval.mockImplementation(async () => {
      pending = [];
      detail = { ...detail, currentLevel: 2 };
    });
    mount();
    fireEvent.click(await screen.findByRole('button', { name: '审核' }));
    await screen.findByText('优加商务经理');
    fireEvent.click(screen.getByRole('button', { name: '通过' }));
    const modal = actionDialog('确认通过');
    expect(within(modal).getByRole('button', { name: '确认通过' })).toBeDisabled();
    fireEvent.click(within(modal).getByRole('checkbox'));
    fireEvent.click(within(modal).getByRole('button', { name: '确认通过' }));
    await waitFor(() => expect(api.passApproval).toHaveBeenCalledWith('101'));
    await waitFor(() => expect(api.getApproval.mock.calls.length).toBeGreaterThan(1));
    expect(screen.queryByText('门店已生效')).not.toBeInTheDocument();
    fireEvent.click(await screen.findByRole('tab', { name: '审批留痕' }));
    expect(await screen.findByText(/优加财务经理 · 第 2 级审批节点/)).toBeInTheDocument();
    expect(screen.queryByText(/已停留25小时/)).not.toBeInTheDocument();
  });

  it('打回拒绝空白原因,失败保留原因和弹窗', async () => {
    api.rejectApproval.mockRejectedValue(new Error('记录已被其他人处理'));
    mount();
    fireEvent.click(await screen.findByRole('button', { name: '审核' }));
    fireEvent.click(await screen.findByRole('button', { name: '打回' }));
    const modal = actionDialog('确认打回');
    const input = within(modal).getByLabelText('打回原因');
    fireEvent.change(input, { target: { value: '   ' } });
    fireEvent.click(within(modal).getByRole('button', { name: '确认打回' }));
    expect(api.rejectApproval).not.toHaveBeenCalled();
    fireEvent.change(input, { target: { value: '政策不合理' } });
    fireEvent.click(within(modal).getByRole('button', { name: '确认打回' }));
    await waitFor(() => expect(api.rejectApproval).toHaveBeenCalledWith('101', '政策不合理'));
    expect(await screen.findByText('记录已被其他人处理')).toBeInTheDocument();
    expect(within(modal).getByLabelText('打回原因')).toHaveValue('政策不合理');
  });

  it.each([
    { status: 'REJECTED', statusLabel: '已打回' },
    { status: 'REVOKED', statusLabel: '已撤回' },
  ])('我发起的 $status 记录仅可查看,无重新提交入口', async ({ status, statusLabel }) => {
    mine = [{ ...row, listingId: '202', status, statusLabel, actionable: false }];
    detail = { ...detail, ...mine[0] };
    mount();
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    expect(await screen.findByText(statusLabel)).toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '审核' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
    fireEvent.click(screen.getByRole('button', { name: '查看' }));
    await screen.findByText('优加商务经理');
    expect(screen.queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '通过' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '打回' })).not.toBeInTheDocument();
  });

  it('选中记录只调用一次批量接口', async () => {
    api.batchPassApproval.mockResolvedValue(undefined);
    mount();
    await screen.findByText('测试门店');
    expect(screen.getByRole('button', { name: '批量审批' })).toBeDisabled();
    fireEvent.click(screen.getAllByRole('checkbox')[1]);
    fireEvent.click(screen.getByRole('button', { name: '批量审批' }));
    const modal = actionDialog('确认批量通过');
    fireEvent.click(within(modal).getByRole('checkbox'));
    fireEvent.click(within(modal).getByRole('button', { name: '确认批量通过' }));
    await waitFor(() => expect(api.batchPassApproval).toHaveBeenCalledWith(['101']));
    expect(api.batchPassApproval).toHaveBeenCalledTimes(1);
    expect(api.passApproval).not.toHaveBeenCalled();
  });

  it('全选只提交可审核记录,请求期间冻结选择,成功后清空仍在列表中的勾选', async () => {
    pending = [
      row,
      { ...row, listingId: '102', storeName: '可审核乙' },
      { ...row, listingId: '103', storeName: '不可审核', actionable: false },
      { ...row, listingId: '104', storeName: '未授权', actionable: undefined },
      { ...row, listingId: '105', storeName: '已处理', status: 'APPROVED' },
    ];
    let complete!: () => void;
    api.batchPassApproval.mockImplementation(
      () =>
        new Promise<void>((resolve) => {
          complete = resolve;
        }),
    );
    mount();
    await screen.findByText('可审核乙');
    const table = screen.getByRole('table');
    fireEvent.click(within(table).getByRole('checkbox', { name: 'Select all' }));
    for (const name of ['不可审核', '未授权', '已处理']) {
      const checkbox = within(screen.getByRole('row', { name: new RegExp(name) })).getByRole(
        'checkbox',
      );
      expect(checkbox).toBeDisabled();
      expect(checkbox).not.toBeChecked();
    }
    fireEvent.click(screen.getByRole('button', { name: '批量审批' }));
    const modal = actionDialog('确认批量通过');
    expect(within(modal).queryByText('不可审核')).not.toBeInTheDocument();
    fireEvent.click(within(modal).getByRole('checkbox'));
    const confirm = within(modal).getByRole('button', { name: '确认批量通过' });
    fireEvent.click(confirm);
    fireEvent.click(confirm);
    await waitFor(() => expect(api.batchPassApproval).toHaveBeenCalledWith(['101', '102']));
    for (const checkbox of within(table).getAllByRole('checkbox', { hidden: true })) {
      expect(checkbox).toBeDisabled();
    }
    expect(api.batchPassApproval).toHaveBeenCalledTimes(1);
    complete();
    await waitFor(() => expect(screen.getByRole('button', { name: '批量审批' })).toBeDisabled());
    await waitFor(() => expect(screen.getByText(/已选 0 条/)).toBeInTheDocument());
    expect(within(table).getByText('可审核乙')).toBeInTheDocument();
    expect(
      within(screen.getByRole('table')).getByRole('checkbox', { name: 'Select all' }),
    ).not.toBeChecked();
  });

  it.each(['查询', '重置'])('%s后清空选择,不能沿用之前的批量操作范围', async (action) => {
    mount();
    await screen.findByText('测试门店');
    fireEvent.click(screen.getAllByRole('checkbox')[1]);
    expect(screen.getByRole('button', { name: '批量审批' })).toBeEnabled();
    fireEvent.click(screen.getByRole('button', { name: action }));
    await waitFor(() => expect(screen.getByText(/已选 0 条/)).toBeInTheDocument());
    expect(screen.getAllByRole('checkbox')[1]).not.toBeChecked();
    expect(screen.getByRole('button', { name: '批量审批' })).toBeDisabled();
  });

  it('翻页和切换页签后不保留之前的选择', async () => {
    pending = Array.from({ length: 11 }, (_, index) => ({
      ...row,
      listingId: String(index + 1),
      storeName: `门店${index + 1}`,
    }));
    mount();
    await screen.findByText('门店1');
    fireEvent.click(screen.getAllByRole('checkbox')[1]);
    fireEvent.click(screen.getByTitle('2'));
    await screen.findByText('门店11');
    expect(screen.getByText(/已选 0 条/)).toBeInTheDocument();
    expect(screen.getAllByRole('checkbox')[1]).not.toBeChecked();
    fireEvent.click(screen.getAllByRole('checkbox')[1]);
    fireEvent.click(screen.getByRole('tab', { name: /我已办/ }));
    expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
    fireEvent.click(screen.getByRole('tab', { name: /待我审批/ }));
    await screen.findByText('门店1');
    expect(screen.getByText(/已选 0 条/)).toBeInTheDocument();
    expect(screen.getByRole('button', { name: '批量审批' })).toBeDisabled();
  });

  it('仅打回权限保留审核入口,但不显示多选与批量审批', async () => {
    mount(['store:approve:view', 'store:approve:reject']);
    await screen.findByText('测试门店');
    expect(screen.getByRole('button', { name: '审核' })).toBeInTheDocument();
    expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '批量审批' })).not.toBeInTheDocument();
  });

  it('无审批查看权限时不加载业务数据', async () => {
    mount([]);
    expect(screen.getByText('无门店审批访问权限')).toBeInTheDocument();
    expect(api.listApprovals).not.toHaveBeenCalled();
    expect(api.listScenes).not.toHaveBeenCalled();
    expect(api.listGoodsCategories).not.toHaveBeenCalled();
  });

  it('仅有通过权限不能替代页面查看权限,也不加载审批详情', () => {
    mount(['store:approve:pass']);
    expect(screen.getByText('无门店审批访问权限')).toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '审核' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '批量审批' })).not.toBeInTheDocument();
    expect(api.listApprovals).not.toHaveBeenCalled();
    expect(api.getApproval).not.toHaveBeenCalled();
  });

  it('重复查询同一条件仍刷新服务端', async () => {
    mount();
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('button', { name: '查询' }));
    await waitFor(() =>
      expect(api.listApprovals.mock.calls.filter(([tab]) => tab === 'todo')).toHaveLength(2),
    );
    fireEvent.click(screen.getByRole('button', { name: '查询' }));
    await waitFor(() =>
      expect(api.listApprovals.mock.calls.filter(([tab]) => tab === 'todo')).toHaveLength(3),
    );
  });

  it('刷新后已处理的选中记录不再可批量审批', async () => {
    const { client } = mount();
    await screen.findByText('测试门店');
    fireEvent.click(screen.getAllByRole('checkbox')[1]);
    expect(screen.getByRole('button', { name: '批量审批' })).toBeEnabled();
    pending = [{ ...row, actionable: false }];
    await client.invalidateQueries({ queryKey: ['store', 'approvals'] });
    await waitFor(() => expect(screen.getByRole('button', { name: '批量审批' })).toBeDisabled());
    expect(api.batchPassApproval).not.toHaveBeenCalled();
  });

  it('只读查看无通过或打回入口,非本人列表无撤回入口', async () => {
    mount([
      'store:approve:view',
      'store:approve:pass',
      'store:approve:reject',
      'store:approve:submit',
    ]);
    fireEvent.click(await screen.findByRole('button', { name: '查看' }));
    await screen.findByText('优加商务经理');
    expect(screen.queryByRole('button', { name: '通过' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '打回' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
  });

  it('查看加 submit 权限允许本人待办列表撤回,确认后刷新状态与操作区', async () => {
    mine = [
      { ...row, listingId: '202', status: 'PENDING', statusLabel: '待审批', actionable: false },
    ];
    api.revokeApproval.mockImplementation(async () => {
      mine = [{ ...mine[0], status: 'REVOKED', statusLabel: '已撤回' }];
    });
    mount(['store:approve:view', 'store:approve:submit']);
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    fireEvent.click(await screen.findByRole('button', { name: '撤回' }));
    expect(api.revokeApproval).not.toHaveBeenCalled();
    const modal = actionDialog('确认撤回');
    expect(within(modal).getByText(/SQ001/)).toBeInTheDocument();
    fireEvent.click(within(modal).getByRole('button', { name: '确认撤回' }));
    await waitFor(() => expect(api.revokeApproval).toHaveBeenCalledWith('202'));
    expect(await screen.findByRole('cell', { name: '已撤回' })).toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
  });

  it.each([
    { label: '仅查看', permCodes: ['store:approve:view'], location: '列表' },
    { label: '仅查看', permCodes: ['store:approve:view'], location: '详情' },
    {
      label: '查看和重提',
      permCodes: ['store:approve:view', 'store:approve:resubmit'],
      location: '列表',
    },
    {
      label: '查看和重提',
      permCodes: ['store:approve:view', 'store:approve:resubmit'],
      location: '详情',
    },
  ])('$label 权限:本人待办 $location 不显示撤回入口', async ({ permCodes, location }) => {
    mine = [{ ...row, listingId: '202', actionable: false }];
    detail = { ...detail, ...mine[0] };
    mount(permCodes);
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    await screen.findByRole('button', { name: '查看' });
    if (location === '详情') {
      fireEvent.click(screen.getByRole('button', { name: '查看' }));
      const drawer = await screen.findByRole('dialog');
      await within(drawer).findByText('优加商务经理');
      expect(within(drawer).queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
      expect(within(drawer).queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    } else {
      expect(screen.queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
      expect(screen.queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    }
    expect(api.revokeApproval).not.toHaveBeenCalled();
  });

  it('查看加 submit 权限允许本人待审批详情撤回', async () => {
    mine = [{ ...row, listingId: '202', actionable: false }];
    detail = { ...detail, ...mine[0] };
    mount(['store:approve:view', 'store:approve:submit']);
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    fireEvent.click(await screen.findByRole('button', { name: '查看' }));
    const drawer = await screen.findByRole('dialog');
    fireEvent.click(await within(drawer).findByRole('button', { name: '撤回' }));
    fireEvent.click(within(actionDialog('确认撤回')).getByRole('button', { name: '确认撤回' }));
    await waitFor(() => expect(api.revokeApproval).toHaveBeenCalledWith('202'));
  });

  it('拥有 resubmit 权限时已打回记录仍不显示重新提交', async () => {
    detail = { ...detail, ...mine[0] };
    mount(['store:approve:view', 'store:approve:resubmit']);
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    fireEvent.click(await screen.findByRole('button', { name: '查看' }));
    const drawer = await screen.findByRole('dialog');
    await within(drawer).findByText('优加商务经理');
    expect(screen.queryByRole('button', { name: '重新提交' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '撤回' })).not.toBeInTheDocument();
  });

  it('撤回确认打开后收回 submit 权限,不发起撤回请求', async () => {
    mine = [{ ...row, listingId: '202', actionable: false }];
    const { setPermissions } = mount(['store:approve:view', 'store:approve:submit']);
    await screen.findByText('测试门店');
    fireEvent.click(screen.getByRole('tab', { name: /我发起的/ }));
    fireEvent.click(await screen.findByRole('button', { name: '撤回' }));
    expect(
      within(actionDialog('确认撤回')).getByRole('button', { name: '确认撤回' }),
    ).toBeInTheDocument();
    setPermissions(['store:approve:view']);
    expect(screen.queryByRole('button', { name: '撤回', hidden: true })).not.toBeInTheDocument();
    await act(async () => {
      const confirm = screen.queryByRole('button', { name: '确认撤回' });
      if (confirm) fireEvent.click(confirm);
    });
    expect(api.revokeApproval).not.toHaveBeenCalled();
  });

  it('没有处置权限只显示查看,不渲染批量入口和选择框', async () => {
    mount(['store:approve:view']);
    await screen.findByText('测试门店');
    expect(screen.getByRole('button', { name: '查看' })).toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '审核' })).not.toBeInTheDocument();
    expect(screen.queryByRole('button', { name: '批量审批' })).not.toBeInTheDocument();
    expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
  });
});