1/**
2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
17import bundleManager from '@ohos.bundle.bundleManager';
18import BundleInfoModel from '../../../main/ets/model/bundleInfo/BundleInfoModel';
19import { BundleInfoBean } from '../../../main/ets/common/bean/BundleInfoBean';
20import { MenuConfig } from '../../../main/ets/common/bean/MenuConfig';
21import AccessTypedef from '../../../main/ets/common/bean/MenuInfo';
22import Logger from '../../../main/ets/common/utils/Logger';
23import { AutoMenuViewModel } from '../../../main/ets/main/auto_menu/AutoMenuViewModel';
24import { AutoMenuInitIntent, AutoMenuRefreshIntent } from '../../../main/ets/main/auto_menu/AutoMenuIntent';
25import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
26import { ProcessResult } from '../../../main/ets/common/base/BaseViewModel';
27
28const TAG = 'ModelTest';
29
30export default function ModelTest() {
31  describe('ModelTest', () => {
32    // Defines a test suite. Two parameters are supported: test suite name and test suite function.
33    beforeAll(() => {
34      // Presets an action, which is performed only once before all test cases of the test suite start.
35      // This API supports only one parameter: preset action function.
36    })
37    beforeEach(() => {
38      // Presets an action, which is performed before each unit test case starts.
39      // The number of execution times is the same as the number of test cases defined by **it**.
40      // This API supports only one parameter: preset action function.
41    })
42    afterEach(() =>  {
43      // Presets a clear action, which is performed after each unit test case ends.
44      // The number of execution times is the same as the number of test cases defined by **it**.
45      // This API supports only one parameter: clear action function.
46    })
47    afterAll(() =>  {
48      // Presets a clear action, which is performed after all test cases of the test suite end.
49      // This API supports only one parameter: clear action function.
50    })
51
52    it('BundleInfoModelTest_01', 0, async () => {
53      let bundleName: string = 'com.ohos.certmanager'
54      await bundleManager.getApplicationInfo(bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT)
55        .then((data) => {
56          BundleInfoModel.getAllBundleLabelAndIcon([data]).then((value) => {
57            expect(value).not().assertNull()
58          })
59        })
60    })
61    it('BundleInfoModelTest_03', 0, async () => {
62      let bundleName: string = 'com.ohos.certmanager'
63      await bundleManager.getApplicationInfo(bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT)
64        .then((info) => {
65          let bundleInfo: BundleInfoBean = {
66            bundleName: info.name,
67            icon: '',
68            iconId: info.iconId,
69            label: '',
70            labelId: info.labelId,
71            permissionName: '',
72            permissionLabel: '',
73            zhTag: '',
74            indexTag: '',
75            language: '',
76            labelResource: info.labelResource,
77            iconResource: info.iconResource,
78            checkedState: '',
79            checkedStateLabel: ''
80          }
81          BundleInfoModel.updateAppLabelAndIcon(bundleInfo).then(() => {
82          })
83        })
84    })
85    it('BundleInfoModelTest_04', 0, async () => {
86      let bundleName: string = ''
87      await BundleInfoModel.getAllBundleInfoByFunctionAccess().then(data => {
88        expect(data).not().assertNull()
89      })
90    })
91    it('BundleInfoModelTest_05', 0, async () => {
92      let bundleName: string = 'com.ohos.certmanager'
93      await bundleManager.getApplicationInfo(bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT)
94        .then((info) => {
95          let bundleInfo: BundleInfoBean = {
96            bundleName: info.name,
97            icon: '',
98            iconId: info.iconId,
99            label: '',
100            labelId: info.labelId,
101            permissionName: '',
102            permissionLabel: '',
103            zhTag: '',
104            indexTag: '',
105            language: '',
106            labelResource: info.labelResource,
107            iconResource: info.iconResource,
108            checkedState: '',
109            checkedStateLabel: ''
110          }
111          BundleInfoModel.addLocalTag(bundleInfo)
112        })
113    })
114    it('AutoMenuTest_01', 0, async () => {
115      Logger.info(TAG, 'AutoMenuTest_01 is start')
116      let autoMenuViewModel: AutoMenuViewModel = new AutoMenuViewModel();
117      let context: Context = abilityDelegatorRegistry.getAbilityDelegator().getAppContext();
118      let processResult: ProcessResult = await autoMenuViewModel.processIntent(new AutoMenuInitIntent(context.getApplicationContext()))
119      expect(processResult).assertEqual(ProcessResult.SUCCESS)
120      processResult = await autoMenuViewModel.processIntent(new AutoMenuRefreshIntent(context.getApplicationContext()))
121      expect(processResult).assertEqual(ProcessResult.SUCCESS)
122      processResult = await autoMenuViewModel.processIntent(new AutoMenuInitIntent(context.getApplicationContext()))
123      expect(processResult).assertEqual(ProcessResult.SUCCESS)
124      Logger.info(TAG, 'AutoMenuTest_01 is end')
125    })
126  })
127}