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