• 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
59    it(' SpAllocations set  attrValue2', function () {
60        let spEle = document.querySelector("#sp") as SpAllocations
61        spEle.processId.value ="3"
62        spEle.unwindEL.value = "1121"
63        spEle.shareMemory!.value = "222"
64        spEle.shareMemoryUnit.value = "KB"
65        spEle.filterMemory.value = "111"
66        spEle.filterMemoryUnit.value = "KB"
67        expect(spEle.pid).toEqual(undefined)
68        expect(spEle.unwind).toEqual(1121)
69        expect(spEle.shared).toEqual(222)
70        expect(spEle.filter).toEqual(111)
71    });
72
73    it(' SpAllocations set  attrValue03', function () {
74        let spEle =  new SpAllocations();
75        spEle.processId.value ="3"
76        spEle.unwindEL.value = "1121"
77        spEle.shareMemory.value = "222"
78        spEle.filterMemory.value = "111"
79        expect(spEle.pid).toEqual(undefined)
80        expect(spEle.unwind).toEqual(1121)
81        expect(spEle.shared).toEqual(222)
82        expect(spEle.filter).toEqual(111)
83    });
84
85    it('SpAllocations test04', function () {
86        let spEle = document.querySelector("#sp") as SpAllocations;
87        expect(spEle.initHtml()).toMatchInlineSnapshot(`
88"
89        <style>
90        :host{
91            display: block;
92            width: 100%;
93            height: 100%;
94            border-radius: 0px 16px 16px 0px;
95        }
96        .root {
97            display: grid;
98            grid-template-columns: repeat(2, 1fr);
99            grid-template-rows: min-content 1fr min-content;
100            padding-top: 45px;
101            margin-left: 40px;
102            width: 90%;
103            border-radius: 0px 16px 16px 0px;
104        }
105        .title {
106            grid-column: span 2 / auto;
107        }
108
109        .font-style{
110            font-family: Helvetica-Bold;
111            font-size: 1em;
112            color: var(--dark-color1,#000000);
113            line-height: 28px;
114            font-weight: 700;
115        }
116        .inner-font-style {
117            font-family: Helvetica,serif;
118            font-size: 1em;
119            color: var(--dark-color1,#000000);
120            text-align: left;
121            line-height: 20px;
122            font-weight: 400;
123        }
124        input {
125           width: 72%;
126           height: 25px;
127           border:0;
128           outline:none;
129           border-radius: 16px;
130           text-indent:2%
131        }
132        input::-webkit-input-placeholder{
133            color:var(--bark-prompt,#999999);
134        }
135        .select {
136            height: 30px;
137            border:0;
138            border-radius: 3px;
139            outline:none;
140            border: 1px solid var(--dark-border,#B3B3B3);
141            width: 60px;
142            background-color:var(--dark-background5, #FFFFFF)
143            font-family: Helvetica;
144            font-size: 14px;
145            color:var(--dark-color,#212121)
146            text-align: center;
147            line-height: 16px;
148            font-weight: 400;
149            border-radius: 16px;
150        }
151        .application{
152           display: flex;
153           flex-direction: column;
154           grid-gap: 15px;
155           margin-top: 40px;
156        }
157        .switchstyle{
158           margin-top: 40px;
159           display: flex;
160        }
161        #fp-unwind {
162          display:flex;
163          width:25%;
164          margin-top: 3px;
165        }
166        .inputstyle{
167            background: var(--dark-background5,#FFFFFF);
168            border: 1px solid var(--dark-background5,#999999);
169            font-family: Helvetica;
170            font-size: 14px;
171            color: var(--dark-color1,#212121);
172            text-align: left;
173            line-height: 16px;
174            font-weight: 400;
175        }
176        .inputstyle::-webkit-input-placeholder {
177           background: var(--dark-background5,#FFFFFF);
178        }
179        #one_mb{
180            background-color:var(--dark-background5, #FFFFFF)
181        }
182        #one_kb{
183            background-color:var(--dark-background5, #FFFFFF)
184        }
185        #two_mb{
186            background-color:var(--dark-background5, #FFFFFF)
187        }
188        #two_kb{
189            background-color:var(--dark-background5, #FFFFFF)
190        }
191        .processSelect {
192          border-radius: 15px;
193          width: 84%;
194        }
195        </style>
196        <div class=\\"root\\">
197          <div class = \\"title\\">
198            <span class=\\"font-style\\">Native Memory</span>
199          </div>
200          <div class=\\"application\\">
201             <span class=\\"inner-font-style\\">ProcessId or ProcessName :</span>
202             <lit-allocation-select show-search class=\\"processSelect\\" rounded default-value=\\"\\" id=\\"pid\\" placement=\\"bottom\\" title=\\"process\\" placeholder=\\"please select process\\">
203             </lit-allocation-select>
204          </div>
205          <div class=\\"application\\">
206            <span class=\\"inner-font-style\\" >Max unwind level :</span>
207            <input id= \\"unwind\\"  class=\\"inputstyle\\" type=\\"text\\" placeholder=\\"Enter the Max Unwind Level\\" oninput=\\"if(this.value > 30) this.value = '30'\\" onkeyup=\\"this.value=this.value.replace(/\\\\D/g,'')\\" value=\\"10\\">
208          </div>
209          <div class=\\"application\\">
210            <span class=\\"inner-font-style\\">Shared Memory Size (One page equals 4 KB) :</span>
211            <div>
212              <input id = \\"shareMemory\\" class=\\"inputstyle\\" type=\\"text\\" placeholder=\\"Enter the Shared Memory Size\\" oninput=\\"if(this.value > 2147483647) this.value = ''\\" onkeyup=\\"this.value=this.value.replace(/\\\\D/g,'')\\" value=\\"16384\\">
213              <span>Page</span>
214            </div>
215          </div>
216          <div class=\\"application\\">
217            <span class=\\"inner-font-style\\" >Filter Memory Size :</span>
218            <div>
219                <input id = \\"filterSized\\" class=\\"inputstyle\\" type=\\"text\\" placeholder=\\"Enter the Filter Memory Size\\" oninput=\\"if(this.value > 65535) this.value = ''\\" onkeyup=\\"this.value=this.value.replace(/\\\\\\\\D/g,'')\\" value=\\"4096\\">
220                 <span>Byte</span>
221            </div>
222          </div>
223          <div class=\\"switchstyle\\">
224              <span class=\\"inner-font-style\\" id=\\"fp-unwind\\">Use Fp Unwind :</span>
225              <lit-switch id=\\"use_fp_unwind\\" title=\\"fp unwind\\" checked=\\"true\\"></lit-switch>
226          </div>
227        </div>
228        "
229`);
230    });
231
232    it('SpAllocations test05', function () {
233        let spAllocations = document.querySelector("#sp") as SpAllocations;
234        expect(spAllocations.appProcess).toBe("3")
235    });
236
237    it('SpAllocations test06', function () {
238        let spAllocations = document.querySelector("#sp") as SpAllocations;
239        expect(spAllocations.convertToValue("0","MB")).toBe(0);
240    });
241
242    it('SpAllocations test07', function () {
243        let spAllocations = document.querySelector("#sp") as SpAllocations;
244        expect(spAllocations.convertToValue("1","KB")).toBe(16384);
245    });
246
247    it('SpAllocations test08', function () {
248        let spAllocations = document.querySelector("#sp") as SpAllocations;
249        expect(spAllocations.convertToValue("1","")).toBe(0);
250    });
251    it('SpAllocations test09', function () {
252        let spAllocations = document.querySelector("#sp") as SpAllocations;
253        expect(spAllocations.fp_unwind).toBeTruthy()
254    });
255})