云
昨天 704265308b1227dbada5a36b2027b588c062ded2
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
package cn.iocoder.yudao.module.system.controller.admin.auth;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO.MenuVO;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class MobileMenuAdapterTest {
  @Test void qualityAndOutboundRetainOnlyAlreadyAuthorizedVisibleMenus() {
    var root=menu(1L,null,true);
    root.setChildren(List.of(menu(2L,"mes/qc/seedQuality/index",true),menu(3L,"mes/qc/seedQuality/record",true),menu(4L,"wls/productsales/index",true),menu(5L,"mes/qc/iqc/index",true)));
    assertEquals(List.of("/mobile/quality","/mobile/quality-records","/mobile/sales"),MobileMenuAdapter.adapt(List.of(root)).stream().map(MenuVO::getPath).toList());
    root.setVisible(false);assertTrue(MobileMenuAdapter.adapt(List.of(root)).isEmpty());
  }
  @Test void mapsOnlyVisibleAuthorizedSupportedMenusWithoutChangingPcTree() {
    MenuVO bag=menu(2L,"/mes/pro/bagCode/index",true);
    MenuVO stock=menu(3L,"wls/materialstock/index",true);
    MenuVO hidden=menu(4L,null,false);hidden.setChildren(List.of(stock));
    MenuVO unsupported=menu(5L,"system/user/index",true);
    MenuVO root=menu(1L,null,true);root.setChildren(List.of(bag,hidden,unsupported));
    List<MenuVO> result=MobileMenuAdapter.adapt(List.of(root));
    assertEquals(1,result.size());assertEquals(2L,result.get(0).getId());
    assertEquals("/mobile/bags",result.get(0).getPath());
    assertEquals("/mes/pro/bagCode/index",bag.getComponent());
    assertEquals(3,root.getChildren().size());
    assertTrue(MobileMenuAdapter.adapt(null).isEmpty());
  }
  private MenuVO menu(Long id,String component,boolean visible) {
    return MenuVO.builder().id(id).name("menu").component(component).visible(visible).build();
  }
}