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 {
16  chartClockDataSql,
17  chartClockDataSqlMem,
18  clockDataReceiver
19} from '../../../../src/trace/database/data-trafic/ClockDataReceiver';
20
21describe('ClockDataReceiver Test', () => {
22  let data;
23  let proc;
24  beforeEach(() => {
25    data = {
26      id: 'bfcedc13-f545-434e-9914-c7823f1a6c17',
27      name: 4,
28      action: 'exec-proto',
29      params: {
30        clockName: 'cluster0_temp',
31        sqlType: 'clockFrequency',
32        startNS: 0,
33        endNS: 9427688540,
34        totalNS: 9427688540,
35        recordStartNS: 4049847357191,
36        recordEndNS: 4059275045731,
37        t: 1703747964987,
38        width: 491,
39        trafic: 2,
40      }
41    };
42    proc = jest.fn((sql) => [
43      {ClockData: {filterId: 89, startNs: 197364063, type: 'measure', value: 48000, dur: 230475000, px: 11}},
44      {ClockData: {filterId: 0, startNs: 197364063, type: 'measure', value: 48000, dur: 230475000, px: 11}},
45    ]);
46  });
47  it('ClockDataReceiverTest01 ', function () {
48    const args = {
49      recordStartNS: 1000,
50      endNS: 3000,
51      startNS: 2000,
52      width: 10,
53      sqlType: 'clockFrequency'
54    };
55    expect(chartClockDataSql(args)).toBeTruthy();
56    expect(chartClockDataSqlMem(args)).toBeTruthy();
57  });
58  it('ClockDataReceiverTest02 ', function () {
59    const args = {
60      recordStartNS: 1000,
61      endNS: 3000,
62      startNS: 2000,
63      width: 10,
64      sqlType: 'screenState'
65    };
66    expect(chartClockDataSql(args)).toBeTruthy();
67    expect(chartClockDataSqlMem(args)).toBeTruthy();
68  });
69  it('hiSysEventDataReceiverTest03 ', function () {
70    const args = {
71      recordStartNS: 1000,
72      endNS: 3000,
73      startNS: 2000,
74      width: 10,
75      sqlType: 'clockState'
76    };
77    expect(chartClockDataSql(args)).toBeTruthy();
78    expect(chartClockDataSqlMem(args)).toBeTruthy();
79  });
80  it('hiSysEventDataReceiverTest04', () => {
81    const mockPostMessage = jest.fn();
82    global.postMessage = mockPostMessage;
83    clockDataReceiver(data,proc);
84    expect(mockPostMessage).toHaveBeenCalledTimes(1);
85  });
86});