From b39073f96b40f34c50961e481c4b1c1c88e3adcd Mon Sep 17 00:00:00 2001 From: kseniakukushkina_c098 Date: Fri, 6 Dec 2024 19:00:11 +0300 Subject: [PATCH] TextArea XTS --- .../ets/pages/components/TextAreaPage.ets | 97 +++++++++++ .../xts/entry/src/main/ets/test/List.test.ets | 2 + .../ets/test/components/TextArea.test.ets | 155 ++++++++++++++++++ .../resources/base/profile/main_pages.json | 1 + 4 files changed, 255 insertions(+) create mode 100644 tests/xts/entry/src/main/ets/pages/components/TextAreaPage.ets create mode 100644 tests/xts/entry/src/main/ets/test/components/TextArea.test.ets diff --git a/tests/xts/entry/src/main/ets/pages/components/TextAreaPage.ets b/tests/xts/entry/src/main/ets/pages/components/TextAreaPage.ets new file mode 100644 index 0000000..fd5a348 --- /dev/null +++ b/tests/xts/entry/src/main/ets/pages/components/TextAreaPage.ets @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2024 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 { storage } from '../../entryability/EntryAbility' +import { redCustomTheme, brownCustomTheme } from '../../themes/CustomTheme' +import { CustomTheme } from '@ohos.arkui.theme' + +export const textAreaThemeProperty: string = `TextAreaThemeProperty` +export const textAreaThemeSetProperty: string = `TextAreaThemeSetProperty` + +export class TextAreaKeys { + static readonly textAreaDefaultSystem = 'TextArea_Default_System' + static readonly textAreaInlineSystem = `TextArea_Inline_System` + static readonly textAreaDefaultSystemCustomAttrs = 'TextArea_Default_System_CustomAttrs' + static readonly textAreaInlineSystemCustomAttrs = `TextArea_Inline_System_CustomAttrs` + static readonly textAreaDefaultWithTheme = `TextArea_Default_WithTheme` + static readonly textAreaInlineWithTheme = `TextArea_Inline_WithTheme` + static readonly textAreaDefaultWithThemeCustomAttrs = `TextArea_Default_WithTheme_CustomAttrs` + static readonly textAreaInlineWithThemeCustomAttrs = `TextArea_Inline_WithTheme_CustomAttrs` +} +@Entry(storage) +@Component +struct TextAreaPage { + @LocalStorageLink(textAreaThemeProperty) localTheme: CustomTheme | undefined = redCustomTheme + @LocalStorageLink(textAreaThemeSetProperty) themeSet: boolean = true + + build() { + Column() { + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.DEFAULT) + .key(TextAreaKeys.textAreaDefaultSystem) + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.INLINE) + .key(TextAreaKeys.textAreaInlineSystem) + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.DEFAULT) + .fontColor(brownCustomTheme.colors?.fontPrimary) + .backgroundColor(brownCustomTheme.colors?.compBackgroundTertiary) + .placeholderColor(brownCustomTheme.colors?.fontSecondary) + .caretColor(brownCustomTheme.colors?.brand) + .key(TextAreaKeys.textAreaDefaultSystemCustomAttrs) + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.INLINE) + .fontColor(brownCustomTheme.colors?.fontPrimary) + .backgroundColor(brownCustomTheme.colors?.compBackgroundTertiary) + .placeholderColor(brownCustomTheme.colors?.fontSecondary) + .caretColor(brownCustomTheme.colors?.brand) + .key(TextAreaKeys.textAreaInlineSystemCustomAttrs) + WithTheme({ theme: this.themeSet ? this.localTheme : undefined }) { + Column() { + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.DEFAULT) + .key(TextAreaKeys.textAreaDefaultWithTheme) + + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.INLINE) + .key(TextAreaKeys.textAreaInlineWithTheme) + + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.DEFAULT) + .fontColor(brownCustomTheme.colors?.fontPrimary) + .backgroundColor(brownCustomTheme.colors?.compBackgroundTertiary) + .placeholderColor(brownCustomTheme.colors?.fontSecondary) + .caretColor(brownCustomTheme.colors?.brand) + .key(TextAreaKeys.textAreaDefaultWithThemeCustomAttrs) + + TextArea({ placeholder: 'Type text here' }) + .margin({ left: '20vp', right: '20vp', top: '10vp' }) + .style(TextContentStyle.INLINE) + .fontColor(brownCustomTheme.colors?.fontPrimary) + .backgroundColor(brownCustomTheme.colors?.compBackgroundTertiary) + .placeholderColor(brownCustomTheme.colors?.fontSecondary) + .caretColor(brownCustomTheme.colors?.brand) + .key(TextAreaKeys.textAreaInlineWithThemeCustomAttrs) + }.width('100%') + } + } + } +} \ No newline at end of file diff --git a/tests/xts/entry/src/main/ets/test/List.test.ets b/tests/xts/entry/src/main/ets/test/List.test.ets index c3cde96..ddab819 100644 --- a/tests/xts/entry/src/main/ets/test/List.test.ets +++ b/tests/xts/entry/src/main/ets/test/List.test.ets @@ -40,6 +40,7 @@ import searchThemeTest from './components/Search.test' import selectThemeTest from './components/Select.test' import sliderThemeTest from './components/Slider.test' import swiperThemeTest from './components/Swiper.test' +import textAreaThemeTest from './components/TextArea.test' import textThemeTest from './components/Text.test' import textClockThemeTest from './components/TextClock.test' import textInputThemeTest from './components/TextInput.test' @@ -77,6 +78,7 @@ export default function testsuite() { selectThemeTest() sliderThemeTest() swiperThemeTest() + textAreaThemeTest() textThemeTest() textClockThemeTest() textInputThemeTest() diff --git a/tests/xts/entry/src/main/ets/test/components/TextArea.test.ets b/tests/xts/entry/src/main/ets/test/components/TextArea.test.ets new file mode 100644 index 0000000..acae242 --- /dev/null +++ b/tests/xts/entry/src/main/ets/test/components/TextArea.test.ets @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2024 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 { afterAll, beforeAll, beforeEach, describe, it } from '@ohos/hypium' +import router from '@ohos.router' +import { textAreaThemeProperty, textAreaThemeSetProperty, TextAreaKeys } from '../../pages/components/TextAreaPage' +import { storage } from '../../entryability/EntryAbility' +import { brownCustomTheme, greenCustomTheme, redCustomTheme } from '../../themes/CustomTheme' +import { checkValue, frameTime, sleep } from '../Utils' +import { Theme, CustomTheme } from '@ohos.arkui.theme' +import { colorValues } from '../../pages/Index' + +export default function textAreaThemeTest() { + const SUITE: string = `TextAreaThemeTest` + + const textAreaKeys: string [] = [ + TextAreaKeys.textAreaDefaultSystem, + TextAreaKeys.textAreaInlineSystem, + TextAreaKeys.textAreaDefaultSystemCustomAttrs, + TextAreaKeys.textAreaInlineSystemCustomAttrs, + TextAreaKeys.textAreaDefaultWithTheme, + TextAreaKeys.textAreaInlineWithTheme, + TextAreaKeys.textAreaDefaultWithThemeCustomAttrs, + TextAreaKeys.textAreaInlineWithThemeCustomAttrs + ] + let localTheme: CustomTheme | undefined + let changeTheme: boolean = false + let themeSet: boolean | undefined = true + + describe(SUITE, () => { + beforeAll(async () => { + try { + const options: router.RouterOptions = { + url: `pages/components/TextAreaPage`, + } + const pages: router.RouterState = router.getState() + if (pages?.name !== `TextAreaPage`) { + await router.pushUrl(options).then(() => { + localTheme = storage.get(textAreaThemeProperty) + themeSet = storage.get(textAreaThemeSetProperty) + console.info(`${SUITE} router.pushUrl success`) + }) + } + } catch (err) { + console.error(`${SUITE} beforeAll error:` + JSON.stringify(err)) + } + }) + + beforeEach(() => { + if (changeTheme) { + if ((storage.get(textAreaThemeProperty) as Theme)?.colors?.fontEmphasize + == redCustomTheme?.colors?.fontEmphasize) { + storage.setOrCreate(textAreaThemeProperty, greenCustomTheme) + } else { + storage.setOrCreate(textAreaThemeProperty, redCustomTheme) + } + changeTheme = false + } + if (themeSet) { + storage.setOrCreate(textAreaThemeSetProperty, true) + } else { + storage.setOrCreate(textAreaThemeSetProperty, false) + } + + localTheme = storage.get(textAreaThemeSetProperty) ? storage.get(textAreaThemeProperty) : undefined + }) + + afterAll(() => { + try { + router.back() + } catch (err) { + console.error(`${SUITE} afterAll error:` + JSON.stringify(err)) + } + }) + /** + * system theme + */ + it(`ActsTextAreaThemeColors_0100`, 0, () => { + const CASE: string = `ActsTextAreaThemeColors_0100` + console.info(`${SUITE} ${CASE} START`) + textAreaKeys.forEach((key) => { + if (key.search(`WithTheme`) > 0) return + checkWithTheme(checkValue, undefined, key, key.search(`CustomAttrs`) > 0) + }) + console.info(`${SUITE} ${CASE} END`) + }) + + /** + * custom theme + */ + it(`ActsTextAreaThemeColors_0200`, 0, () => { + const CASE: string = `ActsTextAreaThemeColors_0200` + console.info(`${SUITE} ${CASE} START`) + textAreaKeys.forEach((key) => { + if (key.search(`System`) > 0) return + checkWithTheme(checkValue, localTheme, key, key.search(`CustomAttrs`) > 0) + }) + changeTheme = true + console.info(`${SUITE} ${CASE} END`) + }) + + /** + * after change theme + */ + it(`ActsTextAreaThemeColors_0300`, 0, async () => { + const CASE: string = `ActsTextAreaThemeColors_0300` + console.info(`${SUITE} ${CASE} START`) + await sleep(frameTime) + textAreaKeys.forEach((key) => { + if (key.search(`System`) > 0) return + checkWithTheme(checkValue, localTheme, key, key.search(`CustomAttrs`) > 0) + }) + themeSet = false + console.info(`${SUITE} ${CASE} END`) + }) + + /** + * after reset theme + */ + it(`ActsTextAreaThemeColors_0400`, 0, async () => { + const CASE: string = `ActsTextAreaThemeColors_0400` + console.info(`${SUITE} ${CASE} START`) + await sleep(frameTime) + textAreaKeys.forEach((key) => { + checkWithTheme(checkValue, undefined, key, key.search(`CustomAttrs`) > 0) + }) + themeSet = true + console.info(`${SUITE} ${CASE} END`) + }) + }) +} + +function checkWithTheme(checkValue: Function, localTheme: CustomTheme | undefined, key : string, customAttrs: boolean) { + const TextAreaJSON = getInspectorByKey(key) + const attrsTextArea: TextAreaAttribute = JSON.parse(TextAreaJSON)?.$attrs + const fontColor: ResourceColor = attrsTextArea?.fontColor?.toString() + checkValue(fontColor, (customAttrs ? brownCustomTheme : localTheme)?.colors?.fontPrimary ?? colorValues?.get(`fontPrimary`)) + const placeholderColor: ResourceColor = attrsTextArea?.placeholderColor?.toString() + checkValue(placeholderColor, (customAttrs ? brownCustomTheme : localTheme)?.colors?.fontSecondary ?? colorValues?.get(`fontSecondary`)) + const caretColor: ResourceColor = attrsTextArea?.caretColor?.toString() + checkValue(caretColor, (customAttrs ? brownCustomTheme : localTheme)?.colors?.brand ?? colorValues?.get(`brand`)) + const backgroundColor: ResourceColor = attrsTextArea?.backgroundColor?.toString() + checkValue(backgroundColor, (customAttrs ? brownCustomTheme : localTheme)?.colors?.compBackgroundTertiary ?? colorValues?.get(`compBackgroundTertiary`)) +} \ No newline at end of file diff --git a/tests/xts/entry/src/main/resources/base/profile/main_pages.json b/tests/xts/entry/src/main/resources/base/profile/main_pages.json index ad9b43f..c34937b 100644 --- a/tests/xts/entry/src/main/resources/base/profile/main_pages.json +++ b/tests/xts/entry/src/main/resources/base/profile/main_pages.json @@ -28,6 +28,7 @@ "pages/components/SliderPage", "pages/components/SwiperPage", "pages/components/TextPage", + "pages/components/TextAreaPage", "pages/components/TextClockPage", "pages/components/TextInputPage", "pages/components/TextPickerPage", -- Gitee