• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 chai from 'chai';
17import {
18  describe,
19  it,
20} from 'mocha';
21import {
22  fakeLog,
23  fakeLogRestore
24} from '../../fakeLog';
25import dpi from '../../../runtime/main/extend/dpi';
26
27const expect = chai.expect;
28
29describe('api of dpi', () => {
30  fakeLog();
31
32  const dpiOptions = {
33    images: [
34      {
35        'image': {
36          'wearable': 'common/wearable.png',
37          'computer': 'image/computer.jpg',
38          'object': {
39            'image0': 'common/wearable.png',
40            'image1': 'image/computer.jpg'
41          },
42          'array': [
43            'common/wearable.png',
44            'image/computer.jpg'
45          ]
46        }
47      }
48    ]
49  };
50
51  const Dpi = dpi.dpi.create(0).instance.dpi;
52  const dpiInstance = new Dpi(dpiOptions);
53
54  describe('dpi', () => {
55    it('$r(path)', () => {
56      expect(dpiInstance.$r).to.be.an.instanceof(Function);
57      expect(dpiInstance.$r('image.wearable')).eql('common/wearable.png');
58      expect(dpiInstance.$r('image.com')).eql('image.com');
59      expect(dpiInstance.$r('image.object')).eql({
60        'image0': 'common/wearable.png',
61        'image1': 'image/computer.jpg'
62      });
63      expect(dpiInstance.$r('image.array')[0]).eql('common/wearable.png');
64      expect(dpiInstance.$r(null)).to.be.undefined;
65      expect(dpiInstance.$r(undefined)).to.be.undefined;
66    });
67
68    // @ts-ignore
69    expect(dpiInstance.$r(1)).to.be.undefined;
70  });
71
72  fakeLogRestore();
73});
74