OhosMatrix4Jsunit.test.ets 6.7 KB
Newer Older
Z
zhangrao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// @ts-nocheck
/**
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils';

export default function ohosMatrix4Jsunit() {
  describe('appInfoTest', function () {
    beforeEach(async function (done) {
      console.info("ohosMatrix4 beforeEach start");
      let options = {
        uri: 'pages/ohosMatrix4',
      }
      try {
        router.clear();
        let pages = router.getState();
        console.info("get ohosMatrix4 state pages:" + JSON.stringify(pages));
        if (!("ohosMatrix4 " == pages.name)) {
          console.info("get ohosMatrix4  state pages.name:" + JSON.stringify(pages.name));
          let result = await router.push(options);
          await Utils.sleep(2000);
          console.info("push ohosMatrix4  page result:" + JSON.stringify(result));
        }
      } catch (err) {
        console.error("push ohosMatrix4  page error:" + err);
      }
      done()
    });

    afterEach(async function () {
L
modify  
luffy505 已提交
45 46
      router.clear();
      await Utils.sleep(2000);
Z
zhangrao 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
      console.info("OhosMatrix4 each called");
    });

    it('test_OhosMatrix4_001', 0, async function (done) {
      console.info('[test_OhosMatrix4_001] START');
      await Utils.sleep(1000);
      let strJson = getInspectorByKey('rotate7');
      let obj = JSON.parse(strJson);
      console.info("[test_OhosMatrix4_001] component strJson:" + JSON.stringify(obj));
      expect(obj.$type).assertEqual('Image');
      expect(obj.$attrs.transform.type)
        .assertEqual('matrix')
      expect(obj.$attrs.transform.matrix)
      .assertNotNull;
      done();
    });

    it('test_OhosMatrix4_002', 0, async function (done) {
      console.info('[test_OhosMatrix4_002] START');
      await Utils.sleep(1000);
      let strJson = getInspectorByKey('rotate8');
      let obj = JSON.parse(strJson);
      console.info("[test_OhosMatrix4_001] component strJson:" + JSON.stringify(obj));
      expect(obj.$type).assertEqual('Image');
      expect(obj.$attrs.transform.type)
        .assertEqual('matrix')
      expect(obj.$attrs.transform.matrix)
        .assertEqual('5.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,-200.000000,0.000000,0.000000,1.000000,')
      done();
    });

    it('test_OhosMatrix4_003', 0, async function (done) {
      console.info('[test_OhosMatrix4_003] START');
      await Utils.sleep(1000);
      let strJson = getInspectorByKey('rotate9');
      let obj = JSON.parse(strJson);
      console.info("[test_OhosMatrix4_003] component strJson:" + JSON.stringify(obj));
      expect(obj.$type).assertEqual('Image');
      expect(obj.$attrs.transform.type)
        .assertEqual('matrix')
      expect(obj.$attrs.transform.matrix)
        .assertEqual('1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,100.000000,200.000000,30.000000,1.000000,')
      done();
    });

    it('test_OhosMatrix4_004', 0, async function (done) {
      console.info('[test_OhosMatrix4_004] START');
      await Utils.sleep(1000);
      let scaleValue = {
        x: 1, y: 1
      }
      try {
        var eventData = {
          data: {
            "scaleValue": JSON.stringify(scaleValue)
          }
        }
        var innerEvent = {
Z
zhangrao 已提交
105
          eventId: 140,
Z
zhangrao 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
          priority: events_emitter.EventPriority.LOW
        }
        console.info("[test_OhosMatrix4_004] start to publish emit");
        events_emitter.emit(innerEvent, eventData);
      } catch (err) {
        console.log("[test_OhosMatrix4_004] change component data error: " + err.message);
      }
      await Utils.sleep(2000);
      let strJsonNew = getInspectorByKey('rotate3');
      let objNew = JSON.parse(strJsonNew);
      console.info("[test_OhosMatrix4_004] component objNew is: " + JSON.stringify(objNew));
      expect(objNew.$attrs.scale.x).assertEqual('1.000000');
      expect(objNew.$attrs.scale.y).assertEqual('1.000000');
      done();
    });

    it('test_OhosMatrix4_005', 0, async function (done) {
      await Utils.sleep(1000)
      var callback = (eventData) => {
        console.info("[test_OhosMatrix4_005] get event state result is: " + JSON.stringify(eventData));
        expect(eventData.data.matrix1).assertEqual("[100, 10]")
      }
      var innerEvent = {
Z
zhangrao 已提交
129
        eventId: 141,
Z
zhangrao 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        priority: events_emitter.EventPriority.LOW
      }
      try {
        events_emitter.on(innerEvent, callback)
      } catch (err) {
        console.info("[test_OhosMatrix4_005] on events_emitter err : " + JSON.stringify(err));
      }
      console.info('[test_OhosMatrix4_005] sendEventByKey ' + JSON.stringify(sendEventByKey('rotate5', 10, "")));
      await Utils.sleep(1000)
      console.info('[test_OhosMatrix4_005] testSendTouchEvent END');
      done();
    });

    it('test_OhosMatrix4_006', 0, async function (done) {
      console.info('[test_OhosMatrix4_006] START');
      await Utils.sleep(1000);
      let matrix2 = {
        x: 400
      }
      let matrix3 = {
        x: 2
      }
      try {
        var eventData = {
          data: {
            "matrix2": JSON.stringify(matrix2),
            "matrix3": JSON.stringify(matrix3)
          }
        }
        var innerEvent = {
Z
zhangrao 已提交
160
          eventId: 140,
Z
zhangrao 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
          priority: events_emitter.EventPriority.LOW
        }
        console.info("[test_OhosMatrix4_006] start to publish emit");
        events_emitter.emit(innerEvent, eventData);
      } catch (err) {
        console.log("[test_OhosMatrix4_006] change component data error: " + err.message);
      }
      await Utils.sleep(2000);
      let strJsonNew = getInspectorByKey('rotate6');
      let objNew = JSON.parse(strJsonNew);
      console.info("[test_OhosMatrix4_006] component objNew is: " + JSON.stringify(objNew));
      expect(JSON.stringify(objNew.$attrs.transform)).assertEqual('{}');
      done();
    });
  })
}