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