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 */ 15import { SpStatisticsHttpUtil } from '../../src/statistics/util/SpStatisticsHttpUtil'; 16 17SpStatisticsHttpUtil.initStatisticsServerConfig = jest.fn(() => true); 18SpStatisticsHttpUtil.addUserVisitAction = jest.fn(() => true); 19 20const intersectionObserverMock = () => ({ 21 observe: () => null, 22}); 23window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock); 24import { SpApplication } from '../../src/trace/SpApplication'; 25import { Theme } from '../../src/trace/component/trace/base/CustomThemeColor'; 26import { LongTraceDBUtils } from '../../src/trace/database/LongTraceDBUtils'; 27// @ts-ignore 28window.ResizeObserver = 29 window.ResizeObserver || 30 jest.fn().mockImplementation(() => ({ 31 disconnect: jest.fn(), 32 observe: jest.fn(), 33 unobserve: jest.fn(), 34 })); 35 36describe('spApplication Test', () => { 37 LongTraceDBUtils.getInstance().indexedDBHelp = jest.fn(() => {}); 38 LongTraceDBUtils.getInstance().indexedDBHelp.open = jest.fn(() => {}); 39 LongTraceDBUtils.getInstance().createDBAndTable = jest.fn(() => { 40 return { 41 then: Function, 42 }; 43 }); 44 document.body.innerHTML = '<sp-application id="sss"></sp-application>'; 45 let spApplication = document.querySelector('#sss') as SpApplication; 46 it('spApplicationTest01', function () { 47 spApplication.dark = true; 48 expect(SpApplication.name).toEqual('SpApplication'); 49 }); 50 51 it('spApplicationTest02', function () { 52 spApplication.dark = false; 53 expect(spApplication.dark).toBeFalsy(); 54 }); 55 56 it('spApplicationTest03', function () { 57 spApplication.server = true; 58 expect(spApplication.server).toBeTruthy(); 59 }); 60 61 it('spApplicationTest04', function () { 62 spApplication.server = false; 63 expect(spApplication.server).toBeFalsy(); 64 }); 65 66 it('spApplicationTest05', function () { 67 spApplication.querySql = true; 68 expect(spApplication.querySql).toBeTruthy(); 69 }); 70 71 it('spApplicationTest06', function () { 72 spApplication.querySql = false; 73 expect(spApplication.querySql).toBeFalsy(); 74 }); 75 76 it('spApplicationTest07', function () { 77 spApplication.search = true; 78 expect(spApplication.search).toBeTruthy(); 79 }); 80 81 it('spApplicationTest08', function () { 82 spApplication.search = false; 83 expect(spApplication.search).toBeFalsy(); 84 }); 85 86 it('spApplicationTest09', function () { 87 expect(spApplication.removeSkinListener([])).toBeUndefined(); 88 }); 89 90 it('spApplicationTest10', function () { 91 expect(spApplication.freshMenuDisable(true)).toBeUndefined(); 92 }); 93 94 it('spApplicationTest11', function () { 95 expect(spApplication.addSkinListener()).toBeUndefined(); 96 }); 97 98 it('spApplicationTest12', function () { 99 expect(spApplication.removeSkinListener()).toBeUndefined(); 100 }); 101 102 it('spApplicationTest13', function () { 103 spApplication.dispatchEvent(new Event('dragleave')); 104 }); 105 106 it('spApplicationTest14', function () { 107 spApplication.dispatchEvent(new Event('drop')); 108 spApplication.removeSkinListener = jest.fn(() => undefined); 109 expect(spApplication.removeSkinListener({})).toBeUndefined(); 110 }); 111 112 it('spApplicationTest15', function () { 113 spApplication.dark = false; 114 expect(spApplication.dark).toBeFalsy(); 115 }); 116 117 it('spApplicationTest16', function () { 118 spApplication.querySql = false; 119 expect(spApplication.querySql).toBeFalsy(); 120 }); 121 122 it('spApplicationTest17', function () { 123 expect(spApplication.initHtml()).not.toBeUndefined(); 124 }); 125 126 it('spApplicationTest18', function () { 127 const mockFn = jest.fn(); 128 SpStatisticsHttpUtil.initStatisticsServerConfig = mockFn; 129 SpStatisticsHttpUtil.addUserVisitAction = mockFn; 130 LongTraceDBUtils.getInstance().createDBAndTable().then = mockFn; 131 expect(spApplication.initPlugin()).toBeUndefined(); 132 spApplication.initPlugin(); 133 expect(mockFn).toHaveBeenCalled(); 134 }); 135 136 it('spApplicationTest19', function () { 137 expect(spApplication.initElements()).toBeUndefined(); 138 }); 139 140 it('spApplicationTest20', function () { 141 expect(spApplication.getFileTypeAndPages('aa_gg', false, [100, 200, 300])).not.toBeUndefined(); 142 expect(spApplication.getFileTypeAndPages('aa_gg', true, [100, 200, 300])).not.toBeUndefined(); 143 }); 144 145 it('spApplicationTest21', function () { 146 let str = 'aaa'; 147 let buffer = new ArrayBuffer(str.length * 2); 148 expect(spApplication.longTraceFileReadMessagePush(100, false, 1, 100, 20, 'i', buffer)).toBeUndefined(); 149 expect(spApplication.longTraceFileReadMessagePush(1, true, 1, 100, 20, 'i', buffer)).toBeUndefined(); 150 }); 151 152 it('spApplicationTest22', function () { 153 spApplication.longTraceTypeMessageMap = null; 154 expect(spApplication.longTraceFileReadMessageHandler(2, 'sss')).toBeUndefined(); 155 }); 156 157 it('spApplicationTest23', function () { 158 spApplication.longTraceTypeMessageMap!.set(2, [ 159 { 160 startIndex: 1, 161 endIndex: 2, 162 size: 5, 163 fileType: 's', 164 }, 165 ]); 166 expect(spApplication.longTraceFileReadMessageHandler(2, 'sss')).toBeUndefined(); 167 }); 168 169 it('spApplicationTest24', function () { 170 spApplication.longTraceTypeMessageMap!.set(2, [ 171 { 172 startIndex: 1, 173 endIndex: 2, 174 size: 5, 175 fileType: 's', 176 }, 177 ]); 178 expect(spApplication.longTraceFileReadMessageHandler(1, 'sss')).toBeUndefined(); 179 }); 180 181 it('spApplicationTest25', function () { 182 expect(spApplication.changeTheme(Theme.DARK)).toBeUndefined(); 183 }); 184 185 it('spApplicationTest26', function () { 186 expect(spApplication.changeTheme(Theme.DARK, ['#00ff00'])).toBeUndefined(); 187 }); 188 189 it('spApplicationTest27', function () { 190 expect(spApplication.changeTheme(Theme.LIGHT, ['#00ff00'])).toBeUndefined(); 191 }); 192 193 it('spApplicationTest28', function () { 194 expect(spApplication.freshMenuDisable(true)).toBeUndefined(); 195 }); 196 197 it('spApplicationTest29', function () { 198 spApplication.initElements(); 199 expect(spApplication.freshMenuDisable(false)).toBeUndefined(); 200 }); 201}); 202