• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 fs from 'fs';
17import path from 'path';
18import {describe, expect, test} from '@jest/globals';
19import { generateClassDeclaration } from '../generate/generateClassDeclaration';
20import { createSourceFile, ScriptTarget } from 'typescript';
21import { getDefaultExportClassDeclaration } from '../declaration-node/sourceFileElementsAssemply';
22
23describe('generateClassDeclaration.ts file test', (): void => {
24  test('Test the generateClassDeclaration function', (): void => {
25    const filePath = path.join(__dirname, './api/@ohos.accessibility.GesturePath.d.ts');
26    const code = fs.readFileSync(filePath);
27    const sourceFile = createSourceFile(filePath, code.toString(), ScriptTarget.Latest);
28    const defaultExportClass = getDefaultExportClassDeclaration(sourceFile);
29    const mockApi = 'import { GesturePoint } from \'./ohos_accessibility_GesturePoint\'';
30    const result = generateClassDeclaration('', defaultExportClass[0], false, 'global', '', sourceFile, false, mockApi);
31    const expectedResult = `export const GesturePath = class GesturePath {constructor() { console.warn('The GesturePath.constructor interface in the Previewer is a mocked implementation and may behave differently than on a real device.');
32this.points = [];
33this.durationTime = 0;
34}
35};
36      if (!global.GesturePath) {
37        global.GesturePath = GesturePath;
38
39      }
40    `;
41    expect(result).toBe(expectedResult);
42  });
43});
44