• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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
16// @ts-ignore
17import { SpAllocations } from '../../../../dist/trace/component/setting/SpAllocations.js';
18
19describe('SpAllocations Test', () => {
20  beforeAll(() => {
21    document.body.innerHTML = `
22            <sp-allocations id = "sp"><sp-allocations>
23        `;
24  });
25
26  it(' SpAllocations get Default attrValue', function () {
27    let spEle = document.querySelector('#sp') as SpAllocations;
28    spEle.unwindEL = jest.fn(() => true);
29    spEle.unwindEL.value = jest.fn(() => true);
30    spEle.shareMemory = jest.fn(() => true);
31    spEle.shareMemory.value = jest.fn(() => true);
32    spEle.shareMemoryUnit = jest.fn(() => true);
33    spEle.shareMemoryUnit.value = jest.fn(() => true);
34    spEle.filterMemory = jest.fn(() => true);
35    spEle.filterMemory.value = jest.fn(() => true);
36    spEle.filterMemoryUnit = jest.fn(() => true);
37    spEle.filterMemoryUnit.value = jest.fn(() => true);
38    expect(spEle.pid).toEqual(undefined);
39    expect(spEle.unwind).toBeNaN();
40    expect(spEle.shared).toBe(16384);
41    expect(spEle.filter).toBeNaN();
42  });
43
44  it(' SpAllocations set  attrValue', function () {
45    let spEle = document.querySelector('#sp') as SpAllocations;
46    spEle.processId.value = '2';
47    spEle.unwindEL.value = '111';
48    spEle.shareMemory.value = '222';
49    spEle.shareMemoryUnit.value = 'MB';
50    spEle.filterMemory.value = '111';
51    spEle.filterMemoryUnit.value = 'MB';
52    expect(spEle.pid).toEqual(undefined);
53    expect(spEle.unwind).toEqual(111);
54    expect(spEle.shared).toEqual(222);
55    expect(spEle.filter).toEqual(111);
56  });
57
58  it(' SpAllocations set  attrValue2', function () {
59    let spEle = document.querySelector('#sp') as SpAllocations;
60    spEle.processId.value = '3';
61    spEle.unwindEL.value = '1121';
62    spEle.shareMemory!.value = '222';
63    spEle.shareMemoryUnit.value = 'KB';
64    spEle.filterMemory.value = '111';
65    spEle.filterMemoryUnit.value = 'KB';
66    expect(spEle.pid).toEqual(undefined);
67    expect(spEle.unwind).toEqual(1121);
68    expect(spEle.shared).toEqual(222);
69    expect(spEle.filter).toEqual(111);
70  });
71
72  it(' SpAllocations set  attrValue03', function () {
73    let spEle = new SpAllocations();
74    spEle.processId.value = '3';
75    spEle.unwindEL.value = '1121';
76    spEle.shareMemory.value = '222';
77    spEle.filterMemory.value = '111';
78    expect(spEle.pid).toEqual(undefined);
79    expect(spEle.unwind).toEqual(1121);
80    expect(spEle.shared).toEqual(222);
81    expect(spEle.filter).toEqual(111);
82  });
83
84  it('SpAllocations test05', function () {
85    let spAllocations = document.querySelector('#sp') as SpAllocations;
86    expect(spAllocations.appProcess).toBe('3');
87  });
88
89  it('SpAllocations test06', function () {
90    let spAllocations = document.querySelector('#sp') as SpAllocations;
91    expect(spAllocations.convertToValue('0', 'MB')).toBe(0);
92  });
93
94  it('SpAllocations test07', function () {
95    let spAllocations = document.querySelector('#sp') as SpAllocations;
96    expect(spAllocations.convertToValue('1', 'KB')).toBe(16384);
97  });
98
99  it('SpAllocations test08', function () {
100    let spAllocations = document.querySelector('#sp') as SpAllocations;
101    expect(spAllocations.convertToValue('1', '')).toBe(0);
102  });
103  it('SpAllocations test09', function () {
104    let spAllocations = document.querySelector('#sp') as SpAllocations;
105    expect(spAllocations.fp_unwind).toBeTruthy();
106  });
107});
108