1e484b35bSopenharmony_ci/*
2e484b35bSopenharmony_ci * Licensed to the Apache Software Foundation (ASF) under one
3e484b35bSopenharmony_ci * or more contributor license agreements.  See the NOTICE file
4e484b35bSopenharmony_ci * distributed with this work for additional information
5e484b35bSopenharmony_ci * regarding copyright ownership.  The ASF licenses this file
6e484b35bSopenharmony_ci * to you under the Apache License, Version 2.0 (the
7e484b35bSopenharmony_ci * "License"); you may not use this file except in compliance
8e484b35bSopenharmony_ci * with the License.  You may obtain a copy of the License at
9e484b35bSopenharmony_ci *
10e484b35bSopenharmony_ci *   http://www.apache.org/licenses/LICENSE-2.0
11e484b35bSopenharmony_ci *
12e484b35bSopenharmony_ci * Unless required by applicable law or agreed to in writing,
13e484b35bSopenharmony_ci * software distributed under the License is distributed on an
14e484b35bSopenharmony_ci * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15e484b35bSopenharmony_ci * KIND, either express or implied.  See the License for the
16e484b35bSopenharmony_ci * specific language governing permissions and limitations
17e484b35bSopenharmony_ci * under the License.
18e484b35bSopenharmony_ci */
19e484b35bSopenharmony_ci
20e484b35bSopenharmony_ciimport chai from 'chai';
21e484b35bSopenharmony_ciimport {
22e484b35bSopenharmony_ci  before,
23e484b35bSopenharmony_ci  after,
24e484b35bSopenharmony_ci  describe,
25e484b35bSopenharmony_ci  it
26e484b35bSopenharmony_ci} from 'mocha';
27e484b35bSopenharmony_ciimport {
28e484b35bSopenharmony_ci  fakeLog,
29e484b35bSopenharmony_ci  fakeLogRestore
30e484b35bSopenharmony_ci} from '../../fakeLog';
31e484b35bSopenharmony_ciimport { initFramework } from '../../../runtime/preparation/init';
32e484b35bSopenharmony_ciimport framework from '../../../runtime/preparation/methods';
33e484b35bSopenharmony_ciimport { receiveTasks } from '../../../runtime/main/manage/event/bridge';
34e484b35bSopenharmony_ci
35e484b35bSopenharmony_ciconst expect = chai.expect;
36e484b35bSopenharmony_ci
37e484b35bSopenharmony_cidescribe('receiveTasks', () => {
38e484b35bSopenharmony_ci  fakeLog();
39e484b35bSopenharmony_ci
40e484b35bSopenharmony_ci  const instanceId = Date.now() + '';
41e484b35bSopenharmony_ci  const options = {
42e484b35bSopenharmony_ci    orientation: 'portrait',
43e484b35bSopenharmony_ci    'device-type': 'phone',
44e484b35bSopenharmony_ci    resolution: '3.0',
45e484b35bSopenharmony_ci    'aspect-ratio': 'string',
46e484b35bSopenharmony_ci    'device-width': '1176',
47e484b35bSopenharmony_ci    'device-height': '2400',
48e484b35bSopenharmony_ci    'round-screen': false,
49e484b35bSopenharmony_ci    width: '0',
50e484b35bSopenharmony_ci    height: '0',
51e484b35bSopenharmony_ci    isInit: true,
52e484b35bSopenharmony_ci    pcPreview: 'disable',
53e484b35bSopenharmony_ci    'dark-mode': 'false',
54e484b35bSopenharmony_ci    appInstanceId: '10002',
55e484b35bSopenharmony_ci    packageName: 'com.example.helloworld',
56e484b35bSopenharmony_ci    resourcesConfiguration: [],
57e484b35bSopenharmony_ci    i18n: {
58e484b35bSopenharmony_ci      resources: [
59e484b35bSopenharmony_ci        {'strings': {'hello': 'hello', 'world': 'world'},
60e484b35bSopenharmony_ci          'Files': {}},
61e484b35bSopenharmony_ci        {'strings': {'hello': 'Hello', 'world': 'World'},
62e484b35bSopenharmony_ci          'Files': {}}
63e484b35bSopenharmony_ci      ]
64e484b35bSopenharmony_ci    },
65e484b35bSopenharmony_ci    language: 'zh_CN',
66e484b35bSopenharmony_ci    appCreate: true,
67e484b35bSopenharmony_ci    appCode: '',
68e484b35bSopenharmony_ci    bundleUrl: ''
69e484b35bSopenharmony_ci  };
70e484b35bSopenharmony_ci  const code: string = `
71e484b35bSopenharmony_ci      $app_define$('@app-component/index', [],
72e484b35bSopenharmony_ci        function($app_require$, $app_exports$, $app_module$) {
73e484b35bSopenharmony_ci          $app_module$.exports = {
74e484b35bSopenharmony_ci            data: {},
75e484b35bSopenharmony_ci          }
76e484b35bSopenharmony_ci          $app_module$.exports.template = {
77e484b35bSopenharmony_ci            'type': 'div',
78e484b35bSopenharmony_ci            'attr': {},
79e484b35bSopenharmony_ci            'children': [
80e484b35bSopenharmony_ci              {
81e484b35bSopenharmony_ci                'type': 'text',
82e484b35bSopenharmony_ci                'attr': {
83e484b35bSopenharmony_ci                  'value': 'This is the index page.'
84e484b35bSopenharmony_ci                },
85e484b35bSopenharmony_ci                'classList': [
86e484b35bSopenharmony_ci                  'title'
87e484b35bSopenharmony_ci                ],
88e484b35bSopenharmony_ci                "events": {
89e484b35bSopenharmony_ci                  "click": '1'
90e484b35bSopenharmony_ci                },
91e484b35bSopenharmony_ci              }
92e484b35bSopenharmony_ci            ]
93e484b35bSopenharmony_ci          }
94e484b35bSopenharmony_ci        })
95e484b35bSopenharmony_ci
96e484b35bSopenharmony_ci      $app_bootstrap$('@app-component/index',undefined,undefined)
97e484b35bSopenharmony_ci    `;
98e484b35bSopenharmony_ci
99e484b35bSopenharmony_ci  before(() => {
100e484b35bSopenharmony_ci    initFramework();
101e484b35bSopenharmony_ci    framework.createInstance(instanceId, code, options, null);
102e484b35bSopenharmony_ci  });
103e484b35bSopenharmony_ci
104e484b35bSopenharmony_ci  after(() => {
105e484b35bSopenharmony_ci    framework.destroyInstance(instanceId);
106e484b35bSopenharmony_ci  });
107e484b35bSopenharmony_ci
108e484b35bSopenharmony_ci  it('normal check of tasks', () => {
109e484b35bSopenharmony_ci    expect(receiveTasks).to.be.an.instanceof(Function);
110e484b35bSopenharmony_ci    const test1 = receiveTasks('invalid id', undefined);
111e484b35bSopenharmony_ci    expect(test1).to.be.an.instanceof(Error);
112e484b35bSopenharmony_ci
113e484b35bSopenharmony_ci    // @ts-ignore
114e484b35bSopenharmony_ci    const test2 = receiveTasks(instanceId, {});
115e484b35bSopenharmony_ci    expect(test2).to.be.an.instanceof(Error);
116e484b35bSopenharmony_ci    const test3 = receiveTasks('invalid id', [{
117e484b35bSopenharmony_ci      method: 'whatever',
118e484b35bSopenharmony_ci      args: []
119e484b35bSopenharmony_ci    }]);
120e484b35bSopenharmony_ci    expect(test3).to.be.an.instanceof(Error);
121e484b35bSopenharmony_ci  });
122e484b35bSopenharmony_ci
123e484b35bSopenharmony_ci  fakeLogRestore();
124e484b35bSopenharmony_ci});
125