import {
  beforeSetup,
  generateNetworkResult,
  intercept,
  intoMenu,
  successIntercept,
  validatePut,
  validateTableList,
  validateTableSearch,
} from './utils';

const basicData = {
  id: '29',
  name: '上架入库',
  url: '1',
  pId: '0',
  idCode: null,
  type: 'PDA',
  page: 0,
  limit: 0,
  orderBy: '1',
  menu: null,
  img: '',
  modifyUser: 'admin',
  modifyTime: '2023-03-22 10:57:34',
  pid: '0',
};

const TABLE_NAME = 'menu_table';

describe('pda菜单', function () {
  beforeEach(function () {
    beforeSetup();
    intoMenu('系统设置', 'PDA菜单管理');
  });

  beforeEach(function () {
    intercept('/menu/getPage', function ({search, reply}) {
      generateNetworkResult({
        search,
        reply,
        basicData,
        title: 'url',
        skipCondition(name) {
          return name === 'pId' || name === 'type';
        },
      });
    });

    successIntercept(['/menu/addMenu', '/menu/updateMenu', '/menu/delMenu']);
  });

  it('table', function () {
    validateTableList(TABLE_NAME);

    validateTableSearch(TABLE_NAME, ['menuName', 'modifyUser'], {
      toolId: 'pda_menu_filter',
      url: '/menu/getPage',
    });
  });

  it('operation', function () {
    const {validateAdd, validateEdit} = validatePut('menu_modal', TABLE_NAME, {
      label: 'PDA菜单',
    });

    validateAdd([
      'menuID',
      'menuName',
      {id: 'menuOrderBy', type: 'field', value: '2'},
    ]);
    validateEdit([
      {id: 'menuID', type: 'field', value: basicData.url},
      {id: 'menuName', type: 'field', value: basicData.name},
      {id: 'menuOrderBy', type: 'field', value: basicData.orderBy},
    ]);
  });
});
