未验证 提交 f2bfe989 编写于 作者: O openharmony_ci 提交者: Gitee

!8190 test:add Tabs_ItemsChange xts_acts testcase

Merge pull request !8190 from 王倩/Tabs_ItemsChange
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 { MessageManager, Callback } from '../../../common/MessageManager';
@Entry
@Component
struct Tabs_itemPadMar {
@State fontColor: string = '#182431';
@State selectedFontColor: string = '#007DFF';
@State dadPadding: number = 0;
@State dadMargin: number = 0;
@State currentIndex: number = 0;
private controller: TabsController = new TabsController();
messageManager:MessageManager = new MessageManager();
onPageShow() {
console.info('Tabs_itemPadMar onPageShow');
globalThis.value = {
name:'messageManager',message:this.messageManager
}
let callback:Callback = (message:any) => {
console.log('message = ' + message.name + "--" + message.value);
if (message.name == 'dadPadding') {
this.dadPadding = message.value;
}
if (message.name == 'dadMargin') {
this.dadMargin = message.value;
}
if (message.name == 'currentIndex') {
this.currentIndex = message.value;
}
}
this.messageManager.registerCallback(callback);
}
@Builder TabBuilder(index: number, name: string) {
Column() {
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(16)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(40)
}.width('100%').height('100%').key('Tabs_itemPadMar_' + name)
}
build() {
Column() {
Tabs({ controller: this.controller, index:this.currentIndex }) {
TabContent() {
Column().width('100%').height('100%').backgroundColor('#00CB87').key("Tabs_itemPadMar_001")
}.tabBar(this.TabBuilder(0, 'green'))
.key("Tabs_itemPadMar_011")
.padding(this.dadPadding)
.margin(this.dadMargin)
TabContent() {
Column().width('100%').height('100%').backgroundColor('#007DFF').key("Tabs_itemPadMar_002")
}.tabBar(this.TabBuilder(1, 'blue')).key("Tabs_itemPadMar_012")
TabContent() {
Column().width('100%').height('100%').backgroundColor('#FFBF00').key("Tabs_itemPadMar_003")
}.tabBar(this.TabBuilder(2, 'yellow')).key("Tabs_itemPadMar_013")
}
.key("Tabs_itemPadMar_01")
.vertical(false)
.barWidth(330)
.barHeight(56)
.animationDuration(400)
.onChange((index: number) => {
this.currentIndex = index
})
.width(330)
.height(300)
.backgroundColor('#F1F3F5')
}.width('100%')
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 { MessageManager, Callback } from '../../../common/MessageManager';
@Entry
@Component
struct Tabs_itemSize {
@State fontColor: string = '#182431';
@State selectedFontColor: string = '#007DFF';
@State dadWeight: number = 200;
@State dadHeight: number = 200;
@State currentIndex: number = 0;
private controller: TabsController = new TabsController();
messageManager:MessageManager = new MessageManager();
onPageShow() {
console.info('Tabs_itemSize onPageShow');
globalThis.value = {
name:'messageManager',message:this.messageManager
}
let callback:Callback = (message:any) => {
console.log('message = ' + message.name + "--" + message.value);
if (message.name == 'dadWeight') {
this.dadWeight = message.value;
}
if (message.name == 'dadHeight') {
this.dadHeight = message.value;
}
if (message.name == 'currentIndex') {
this.currentIndex = message.value;
}
}
this.messageManager.registerCallback(callback);
}
@Builder TabBuilder(index: number, name: string) {
Column() {
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(16)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(40)
}.width('100%').height('100%').key('Tabs_itemSize_' + name)
}
build() {
Column() {
Tabs({ index:this.currentIndex }) {
TabContent() {
Column().width('100%').height('100%').backgroundColor('#00CB87').key("Tabs_itemSize_001")
}.tabBar(this.TabBuilder(0, 'green')).key("Tabs_itemSize_011").width(this.dadWeight).height(this.dadHeight)
TabContent() {
Column().width('100%').height('100%').backgroundColor('#007DFF').key("Tabs_itemSize_002")
}.tabBar(this.TabBuilder(1, 'blue')).key("Tabs_itemSize_012")
TabContent() {
Column().width('100%').height('100%').backgroundColor('#FFBF00').key("Tabs_itemSize_003")
}.tabBar(this.TabBuilder(2, 'yellow')).key("Tabs_itemSize_013")
}
.key("Tabs_itemSize_01")
.vertical(false)
.barWidth(330)
.barHeight(56)
.animationDuration(400)
.onChange((index: number) => {
this.currentIndex = index
})
.width(330)
.height(300)
.backgroundColor('#F1F3F5')
}.width('100%')
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 iSoftStone Information Technology (Group) 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 '@ohos/hypium';
import router from '@ohos.router';
import CommonFunc from '../../../MainAbility/common/Common';
import { UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection,
WindowMode, PointerMatrix, UiDirection, MouseButton } from '@ohos.UiTest';
export default function Tabs_itemSize() {
describe('Tabs_itemSize', function () {
beforeEach(async function (done) {
console.info("Tabs_itemSize beforeEach start");
let options = {
url: "MainAbility/pages/Tabs/Tabs_ItemsChange/Tabs_itemSize",
}
try {
router.clear();
let pages = router.getState();
console.info("get Tabs_itemSize state pages:" + JSON.stringify(pages));
if (!("Tabs_itemSize" == pages.name)) {
console.info("get Tabs_itemSize pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await CommonFunc.sleep(2000);
console.info("push Tabs_itemSize page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push Tabs_itemSize page error " + JSON.stringify(err));
expect().assertFail();
}
console.info("Tabs_itemSize beforeEach end");
done();
});
afterEach(async function () {
await CommonFunc.sleep(2000);
console.info("Tabs_itemSize after each called")
globalThis.value.message.notify({name:'currentIndex', value:0});
});
/**
* @tc.number SUB_ACE_TABS_ITEMSIZE_TEST_0100
* @tc.name testTabsItemSize
* @tc.desc Set width to 200 and height to 200 for TabContent
*/
it('testTabsItemSize', 0, async function (done) {
console.info('[testTabsItemSize] START');
await CommonFunc.sleep(3000);
let strJson = getInspectorByKey('Tabs_itemSize_01');
let obj = JSON.parse(strJson);
console.info(`[testTabsItemSize] type: ${JSON.stringify(obj.$type)}`);
console.info("[testTabsItemSize] barPosition: " + JSON.stringify(obj.$attrs.barPosition));
console.info("[testTabsItemSize] index: " + JSON.stringify(obj.$attrs.index));
console.info("[testTabsItemSize] scrollable: " + JSON.stringify(obj.$attrs.scrollable));
console.info("[testTabsItemSize] barMode: " + JSON.stringify(obj.$attrs.barMode));
expect(obj.$type).assertEqual('Tabs');
expect(obj.$attrs.barPosition).assertEqual("BarPosition.Start");
expect(obj.$attrs.index).assertEqual("0");
expect(obj.$attrs.scrollable).assertEqual(true);
expect(obj.$attrs.barMode).assertEqual('BarMode.Fixed');
let Tabs_itemSize_001 = CommonFunc.getComponentRect('Tabs_itemSize_001');
let Tabs_itemSize_011 = CommonFunc.getComponentRect('Tabs_itemSize_011');
let driver = await Driver.create();
await driver.swipe(Math.round(Tabs_itemSize_011.right - 30),
Math.round(Tabs_itemSize_011.top + ((Tabs_itemSize_011.bottom - Tabs_itemSize_011.top) / 2)),
Math.round(Tabs_itemSize_011.left + 30),
Math.round(Tabs_itemSize_011.top + ((Tabs_itemSize_011.bottom - Tabs_itemSize_011.top) / 2)));
await CommonFunc.sleep(1000);
let Tabs_itemSize_002 = CommonFunc.getComponentRect('Tabs_itemSize_002');
let Tabs_itemSize_012 = CommonFunc.getComponentRect('Tabs_itemSize_012');
await driver.swipe(Math.round(Tabs_itemSize_012.right - 30),
Math.round(Tabs_itemSize_012.top +((Tabs_itemSize_012.bottom - Tabs_itemSize_012.top) / 2)),
Math.round(Tabs_itemSize_012.left + 30),
Math.round(Tabs_itemSize_012.top + ((Tabs_itemSize_012.bottom - Tabs_itemSize_012.top) / 2)));
await CommonFunc.sleep(1000);
let Tabs_itemSize_003 = CommonFunc.getComponentRect('Tabs_itemSize_003');
let Tabs_itemSize_013 = CommonFunc.getComponentRect('Tabs_itemSize_013');
let Tabs_itemSize_01 = CommonFunc.getComponentRect('Tabs_itemSize_01');
let subGreen = CommonFunc.getComponentRect('Tabs_itemSize_green');
let subBlue = CommonFunc.getComponentRect('Tabs_itemSize_blue');
let subYellow = CommonFunc.getComponentRect('Tabs_itemSize_yellow');
console.info(`[testTabsItemSize]Tabs_itemSize_011.left equal Tabs_itemSize_001.left=
${Tabs_itemSize_011.left} === ${Tabs_itemSize_001.left}`);
expect(Tabs_itemSize_011.left).assertEqual(Tabs_itemSize_001.left);
expect(Tabs_itemSize_012.left).assertEqual(Tabs_itemSize_002.left);
expect(Tabs_itemSize_013.left).assertEqual(Tabs_itemSize_003.left);
expect(Tabs_itemSize_011.top).assertEqual(Tabs_itemSize_001.top);
expect(Tabs_itemSize_012.top).assertEqual(Tabs_itemSize_002.top);
expect(Tabs_itemSize_013.top).assertEqual(Tabs_itemSize_003.top);
console.info(`[testTabsItemSize]Tabs_itemSize_011.left equal Tabs_itemSize_01.left=
${Tabs_itemSize_011.left} === ${Tabs_itemSize_01.left}`);
expect(Tabs_itemSize_011.left).assertEqual(Tabs_itemSize_01.left);
expect(Tabs_itemSize_012.left).assertEqual(Tabs_itemSize_01.left);
expect(Tabs_itemSize_013.left).assertEqual(Tabs_itemSize_01.left);
expect(Tabs_itemSize_011.top).assertEqual(subGreen.bottom);
expect(Tabs_itemSize_012.top).assertEqual(subBlue.bottom);
expect(Tabs_itemSize_013.top).assertEqual(subYellow.bottom);
console.info(`[testTabsItemSize]Tabs_itemSize_011.bottom - Tabs_itemSize_011.top=
${Math.round(Tabs_itemSize_011.bottom - Tabs_itemSize_011.top)}`);
expect(Math.round(Tabs_itemSize_011.bottom - Tabs_itemSize_011.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_012.bottom - Tabs_itemSize_012.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_013.bottom - Tabs_itemSize_013.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_011.right - Tabs_itemSize_011.left)).assertEqual(vp2px(330));
expect(Math.round(Tabs_itemSize_012.right - Tabs_itemSize_012.left)).assertEqual(vp2px(330));
expect(Math.round(Tabs_itemSize_013.right - Tabs_itemSize_013.left)).assertEqual(vp2px(330));
console.info(`[testTabsItemSize]Tabs_itemSize_001.bottom - Tabs_itemSize_001.top=
${Math.round(Tabs_itemSize_001.bottom - Tabs_itemSize_001.top)}`);
expect(Math.round(Tabs_itemSize_001.bottom - Tabs_itemSize_001.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_002.bottom - Tabs_itemSize_002.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_003.bottom - Tabs_itemSize_003.top)).assertEqual(vp2px(244));
expect(Math.round(Tabs_itemSize_001.right - Tabs_itemSize_001.left)).assertEqual(vp2px(330));
expect(Math.round(Tabs_itemSize_002.right - Tabs_itemSize_002.left)).assertEqual(vp2px(330));
expect(Math.round(Tabs_itemSize_003.right - Tabs_itemSize_003.left)).assertEqual(vp2px(330));
console.info(`[testTabsItemSize]subGreen.bottom - subGreen.top = ${Math.round(subGreen.bottom - subGreen.top)}`);
expect(Math.round(subGreen.bottom - subGreen.top)).assertEqual(vp2px(56));
expect(Math.round(subBlue.bottom - subBlue.top)).assertEqual(vp2px(56));
expect(Math.round(subYellow.bottom - subYellow.top)).assertEqual(vp2px(56));
expect(Math.round(subGreen.right - subGreen.left)).assertEqual(vp2px(110));
expect(Math.round(subBlue.right - subBlue.left)).assertEqual(vp2px(110));
expect(Math.round(subYellow.right - subYellow.left)).assertEqual(vp2px(110));
console.info('[testTabsItemSize] END');
done();
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册