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 17import { 18 frameAnimationReceiver, 19 frameDynamicReceiver, 20 frameSpacingReceiver 21} from '../../../../src/trace/database/data-trafic/FrameDynamicEffectReceiver'; 22 23describe('FrameDynamicEffectReceiver Test', () => { 24 let data = { 25 action: "exec-proto", 26 id: "1", 27 name: 18, 28 params: { 29 recordStartNS: 4049847357191, 30 recordEndNS: 4059275045731, 31 startNS: 0, 32 t: 1703474011224, 33 width: 1407, 34 trafic: 3 35 } 36 }; 37 let animationData = [{ 38 frameAnimationData: { 39 depth: 0, 40 dur: 79379165, 41 endTs: 1451353646, 42 name: "H:APP_LIST_FLING, com.tencent.mm", 43 startTs: 1371974481 44 } 45 }] 46 let dynamicData = [{ 47 frameDynamicData: { 48 alpha: "0.08", 49 appName: "WindowScene_mm37", 50 height: "1119", 51 ts: 179994792, 52 width: "543", 53 x: "513", 54 y: "1017" 55 } 56 }, { 57 frameDynamicData: { 58 alpha: "0.26", 59 appName: "WindowScene_mm37", 60 height: "1293", 61 ts: 196844792, 62 width: "627", 63 x: "459", 64 y: "938" 65 } 66 }] 67 let frameSpacingData = [{ 68 frameSpacingData: { 69 currentFrameHeight: "1119", 70 currentFrameWidth: "543", 71 currentTs: 179994792, 72 frameSpacingResult: 0, 73 nameId: "WindowScene_mm37", 74 preFrameHeight: 0, 75 preFrameWidth: 0, 76 preTs: 0, 77 preX: 0, 78 preY: 0, 79 x: "513", 80 y: "1017" 81 } 82 }] 83 it('FrameDynamicEffectReceiverTest01', function () { 84 const mockCallback = jest.fn(() => animationData); 85 const mockPostMessage = jest.fn(); 86 (self as unknown as Worker).postMessage = mockPostMessage; 87 frameAnimationReceiver(data, mockCallback); 88 expect(mockCallback).toHaveBeenCalled(); 89 }); 90 91 it('FrameDynamicEffectReceiverTest02', function () { 92 const mockCallback = jest.fn(() => dynamicData); 93 const mockPostMessage = jest.fn(); 94 (self as unknown as Worker).postMessage = mockPostMessage; 95 frameDynamicReceiver(data, mockCallback); 96 expect(mockCallback).toHaveBeenCalled(); 97 }); 98 it('FrameDynamicEffectReceiverTest03', function () { 99 let mockCallback = jest.fn(() => frameSpacingData); 100 (self as unknown as Worker).postMessage = jest.fn(); 101 frameSpacingReceiver(data, mockCallback); 102 expect(mockCallback).toHaveBeenCalled(); 103 }); 104});