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 describe, 24e484b35bSopenharmony_ci it 25e484b35bSopenharmony_ci} from 'mocha'; 26e484b35bSopenharmony_ciimport { 27e484b35bSopenharmony_ci fakeLog, 28e484b35bSopenharmony_ci fakeLogRestore 29e484b35bSopenharmony_ci} from '../../fakeLog'; 30e484b35bSopenharmony_ciimport Document from '../../../runtime/vdom/Document'; 31e484b35bSopenharmony_ciimport { 32e484b35bSopenharmony_ci defineFn, 33e484b35bSopenharmony_ci bootstrap 34e484b35bSopenharmony_ci} from '../../../runtime/main/app/bundle'; 35e484b35bSopenharmony_ci 36e484b35bSopenharmony_ciconst expect = chai.expect; 37e484b35bSopenharmony_ci 38e484b35bSopenharmony_cidescribe('use defineFn/bootstrap', () => { 39e484b35bSopenharmony_ci fakeLog(); 40e484b35bSopenharmony_ci 41e484b35bSopenharmony_ci let doc: Document; 42e484b35bSopenharmony_ci const options = { 43e484b35bSopenharmony_ci orientation: 'portrait', 44e484b35bSopenharmony_ci 'device-type': 'phone', 45e484b35bSopenharmony_ci resolution: '3.0', 46e484b35bSopenharmony_ci 'aspect-ratio': 'string', 47e484b35bSopenharmony_ci 'device-width': '1176', 48e484b35bSopenharmony_ci 'device-height': '2400', 49e484b35bSopenharmony_ci width: '0', 50e484b35bSopenharmony_ci height: '0', 51e484b35bSopenharmony_ci isInit: true, 52e484b35bSopenharmony_ci appInstanceId: '10002', 53e484b35bSopenharmony_ci packageName: 'com.example.test' 54e484b35bSopenharmony_ci }; 55e484b35bSopenharmony_ci const componentTemplate = { 56e484b35bSopenharmony_ci type: 'div', 57e484b35bSopenharmony_ci children: [{ 58e484b35bSopenharmony_ci type: 'text', 59e484b35bSopenharmony_ci attr: { 60e484b35bSopenharmony_ci value: 'value' 61e484b35bSopenharmony_ci } 62e484b35bSopenharmony_ci }] 63e484b35bSopenharmony_ci }; 64e484b35bSopenharmony_ci const page = { doc, customComponentMap: {}, options }; 65e484b35bSopenharmony_ci 66e484b35bSopenharmony_ci before(() => { 67e484b35bSopenharmony_ci const id = Date.now() + ''; 68e484b35bSopenharmony_ci const url = "" 69e484b35bSopenharmony_ci doc = new Document(id, url); 70e484b35bSopenharmony_ci }); 71e484b35bSopenharmony_ci 72e484b35bSopenharmony_ci describe('defineFn', () => { 73e484b35bSopenharmony_ci it('application with factory and deps', () => { 74e484b35bSopenharmony_ci // @ts-ignore 75e484b35bSopenharmony_ci defineFn(page, options.packageName, '@app-application/a', [], (require, exports, module) => { 76e484b35bSopenharmony_ci module.exports = { 77e484b35bSopenharmony_ci template: componentTemplate 78e484b35bSopenharmony_ci } 79e484b35bSopenharmony_ci }); 80e484b35bSopenharmony_ci expect(page.customComponentMap['a'].template).eql(componentTemplate); 81e484b35bSopenharmony_ci }); 82e484b35bSopenharmony_ci }); 83e484b35bSopenharmony_ci 84e484b35bSopenharmony_ci describe('bootstrap', () => { 85e484b35bSopenharmony_ci 86e484b35bSopenharmony_ci before(() => { 87e484b35bSopenharmony_ci // @ts-ignore 88e484b35bSopenharmony_ci defineFn(page, options.packageName, '@app-application/main', [], (require, exports, module) => { 89e484b35bSopenharmony_ci module.exports = { 90e484b35bSopenharmony_ci template: componentTemplate, 91e484b35bSopenharmony_ci } 92e484b35bSopenharmony_ci }); 93e484b35bSopenharmony_ci }); 94e484b35bSopenharmony_ci 95e484b35bSopenharmony_ci it('not an application', () => { 96e484b35bSopenharmony_ci // @ts-ignore 97e484b35bSopenharmony_ci const result = bootstrap(page, options.packageName, '@app-module/dom', undefined, undefined); 98e484b35bSopenharmony_ci expect(result).instanceof(Error); 99e484b35bSopenharmony_ci }); 100e484b35bSopenharmony_ci 101e484b35bSopenharmony_ci it('an application', () => { 102e484b35bSopenharmony_ci // @ts-ignore 103e484b35bSopenharmony_ci const result = bootstrap(page, options.packageName, '@app-application/dom', undefined, undefined); 104e484b35bSopenharmony_ci expect(result).not.instanceof(Error); 105e484b35bSopenharmony_ci }); 106e484b35bSopenharmony_ci }); 107e484b35bSopenharmony_ci 108e484b35bSopenharmony_ci fakeLogRestore(); 109e484b35bSopenharmony_ci}); 110