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
16import { SpRecordSetting } from '../../../../src/trace/component/setting/SpRecordSetting';
17describe('SpRecordSetting Test', () => {
18  beforeAll(() => {
19    document.body.innerHTML = `
20            <record-setting id = "setting"><sp-allocations>
21        `;
22  });
23  it('new SpRecordSetting', function () {
24    expect(new SpRecordSetting()).not.toBeNull();
25  });
26
27  it(' SpAllocations get Default attrValue', function () {
28    let spEle = document.querySelector('#setting') as SpRecordSetting;
29    expect(spEle.recordMod).toBeTruthy();
30    expect(spEle.bufferSize).toEqual(64);
31    expect(spEle.maxDur).toEqual(30);
32  });
33
34  it(' SpRecordSettingTest04', function () {
35    let spEle = document.querySelector('#setting') as SpRecordSetting;
36    expect(spEle.resetValue()).toBeUndefined();
37  });
38  it('SpRecordSettingTest05', function (){
39    let spEle = document.querySelector('#setting') as SpRecordSetting;
40    let maxFileSizeEl = null;
41    expect(spEle.longTraceSingleFileMaxSize).toEqual(200);
42  })
43  it('SpRecordSettingTest06', function (){
44    let spEle = document.querySelector('#setting') as SpRecordSetting;
45    spEle.radioBox = null;
46    expect(spEle.recordMod).toBeFalsy();
47  })
48  it('SpRecordSettingTest07', function (){
49    let spEle = document.querySelector('#setting') as SpRecordSetting;
50    spEle.outputPath = spEle.shadowRoot?.querySelector('#trace_path') as HTMLInputElement;
51    spEle.outputPath.value = ''
52    expect(spEle.longOutPath).toEqual('/data/local/tmp/long_trace/');
53  })
54  it('SpRecordSettingTest08', function (){
55    let spEle = document.querySelector('#setting') as SpRecordSetting;
56    spEle.outputPath = undefined
57    expect(spEle.longOutPath).toEqual('/data/local/tmp/long_trace/');
58  })
59  it('SpRecordSettingTest09', function (){
60    let spEle = document.querySelector('#setting') as SpRecordSetting;
61    spEle.outputPath = spEle.shadowRoot?.querySelector('#trace_path') as HTMLInputElement;
62    spEle.outputPath.value = 'long_trace'
63    expect(spEle.longOutPath).toEqual('/data/local/tmp/long_trace/');
64  })
65  it('SpRecordSettingTest10', function (){
66    let spEle = document.querySelector('#setting') as SpRecordSetting;
67    spEle.outputPath = spEle.shadowRoot?.querySelector('#trace_path') as HTMLInputElement;
68    spEle.outputPath.value = 'long'
69    expect(spEle.longOutPath).toEqual(`/data/local/tmp/long/`);
70  })
71  it('SpRecordSettingTest11', function (){
72    let spEle = document.querySelector('#setting') as SpRecordSetting;
73    spEle.isRecordTemplate = undefined;
74    spEle.outputPath = undefined;
75    expect(spEle.output).toEqual('/data/local/tmp/hiprofiler_data.htrace');
76  })
77  it('SpRecordSettingTest12', function (){
78    let spEle = document.querySelector('#setting') as SpRecordSetting;
79    spEle.isRecordTemplate = true;
80    spEle.outputPath = undefined;
81    expect(spEle.output).toEqual('/data/local/tmp/hiprofiler_data.htrace');
82  })
83  it('SpRecordSettingTest13', function (){
84    let spEle = document.querySelector('#setting') as SpRecordSetting;
85    spEle.isRecordTemplate = true;
86    spEle.outputPath = spEle.shadowRoot?.querySelector('#trace_path') as HTMLInputElement;
87    spEle.outputPath.value = '1111'
88    expect(spEle.output).toEqual(`/data/local/tmp/1111`);
89  })
90  it('SpRecordSettingTest14', function (){
91    let spEle = document.querySelector('#setting') as SpRecordSetting;
92    spEle.bufferNumber = undefined;
93    expect(spEle.bufferSize).toEqual(64);
94  })
95  it('SpRecordSettingTest15', function () {
96    let spEle = document.querySelector('#setting') as SpRecordSetting;
97    spEle.bufferNumber = spEle.shadowRoot.querySelector('.buffer-size') as HTMLElement;
98    let parentElement = spEle.memoryBufferSlider!.parentNode as Element;
99    let bufferInput = spEle.shadowRoot.querySelector('.memory_buffer_result') as HTMLInputElement;
100    let htmlInputElement = spEle.memoryBufferSlider!.shadowRoot.querySelector('#slider') as HTMLInputElement;
101    bufferInput.value = '60';
102    bufferInput.dispatchEvent(new Event('input'));
103    expect(spEle.memoryBufferSlider.percent).toEqual(bufferInput.value);
104    expect(htmlInputElement.value).toEqual(bufferInput.value);
105    expect(spEle.memoryBufferSlider.sliderStyle).toEqual({
106      minRange: 4,
107      maxRange: 512,
108      defaultValue: bufferInput.value,
109      resultUnit: 'MB',
110      stepSize: 2,
111      lineColor: 'var(--dark-color3,#46B1E3)',
112      buttonColor: '#999999',
113    });
114    expect(parentElement.getAttribute('percent')).toEqual(bufferInput.value);
115  });
116});
117