From c08538423dc42bda6399e1ef90981e0f13c0f212 Mon Sep 17 00:00:00 2001 From: kseniakukushkina_c098 Date: Thu, 19 Dec 2024 13:41:39 +0300 Subject: [PATCH 1/4] PatternLockXTS --- .../pages/components/PatternLockPage.ets | 28 +++++++++++++++-- .../ets/test/components/PatternLock.test.ets | 31 ++++++++++++++----- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets index c4cfedfa01..d2df3b37ed 100644 --- a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets +++ b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets @@ -13,19 +13,24 @@ * limitations under the License. */ -import { redCustomTheme } from '../../themes/CustomTheme'; +import { brownCustomTheme, redCustomTheme } from '../../themes/CustomTheme'; import { CustomTheme } from '@ohos.arkui.theme'; export const patternLockThemeProperty: string = 'PatternLockThemeProperty'; +export const patternLockThemeSetProperty: string = 'PatternLockThemeSetProperty'; + export class PatternLockKeys { public static readonly patternLockSystem: string = `PatternLock_System`; + public static readonly patternLockSystemCustomAttrs: string = `PatternLock_System_CustomAttrs`; public static readonly patternLockWithTheme: string = `PatternLock_WithTheme`; + public static readonly patternLockWithThemeCustomAttrs: string = `PatternLock_WithTheme_CustomAttrs`; } @Entry @Component struct PatternLockPage { @StorageLink(patternLockThemeProperty) localTheme: CustomTheme | undefined = redCustomTheme; + @StorageLink(patternLockThemeSetProperty) themeSet: boolean = true patternLockController: PatternLockController = new PatternLockController(); timeZoneOffset: number = 1; @@ -33,9 +38,26 @@ struct PatternLockPage { Column() { PatternLock(this.patternLockController ) .key(PatternLockKeys.patternLockSystem) + + PatternLock(this.patternLockController) + .regularColor(brownCustomTheme.colors?.compBackgroundNeutral) + .selectedColor(brownCustomTheme.colors?.compBackgroundNeutral) + .activeColor(brownCustomTheme.colors?.compBackgroundNeutral) + .pathColor(brownCustomTheme.colors?.compDivider) + .key(PatternLockKeys.patternLockSystemCustomAttrs) + WithTheme({ theme: this.localTheme }) { - PatternLock(this.patternLockController ) - .key(PatternLockKeys.patternLockWithTheme) + Column() { + PatternLock(this.patternLockController) + .key(PatternLockKeys.patternLockWithTheme) + + PatternLock(this.patternLockController) + .regularColor(brownCustomTheme.colors?.compBackgroundNeutral) + .selectedColor(brownCustomTheme.colors?.compBackgroundNeutral) + .activeColor(brownCustomTheme.colors?.compBackgroundNeutral) + .pathColor(brownCustomTheme.colors?.compDivider) + .key(PatternLockKeys.patternLockWithThemeCustomAttrs) + } } } .width('100%') diff --git a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets index ccd32945bf..3112e55c16 100644 --- a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets +++ b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets @@ -15,19 +15,37 @@ import { afterAll, beforeAll, beforeEach, describe, it, expect } from '@ohos/hypium'; import router from '@ohos.router'; import { colorValuesKey } from '../../MainAbility/pages/index/index'; -import { PatternLockKeys, patternLockThemeProperty } from '../../MainAbility/pages/components/PatternLockPage'; -import { greenCustomTheme, redCustomTheme } from '../../MainAbility/themes/CustomTheme'; +import { PatternLockKeys, patternLockThemeProperty, patternLockThemeSetProperty } from '../../MainAbility/pages/components/PatternLockPage'; +import { brownCustomTheme, greenCustomTheme, redCustomTheme } from '../../MainAbility/themes/CustomTheme'; import { frameTime, sleep } from '../Utils'; import { CustomTheme, Theme } from '@ohos.arkui.theme'; +const EMPTY_CHECK: string = 'emptyCheck'; +const EMPTY_ATTR: string = 'emptyAttr'; + export default function patternLockThemeTest() { const SUITE: string = `patternLockThemeTest`; - const emptyCheck = 'emptyCheck'; - const emptyAttr = 'emptyAttr'; - let localTheme: CustomTheme | undefined; - let changeTheme: boolean = false; + let colorValues: Map | undefined = new Map(); + const patternLockKeys: string[] = [ + PatternLockKeys.patternLockSystem, + PatternLockKeys.patternLockSystemCustomAttrs, + PatternLockKeys.patternLockWithTheme, + PatternLockKeys.patternLockWithThemeCustomAttrs + ] + + // themes for each testcase + const themes: (CustomTheme | undefined)[] = [ + redCustomTheme, + redCustomTheme, + greenCustomTheme, + undefined + ] + + // testcase index: starting with -1 to get 0 in 1st testcase + let index: number = -1; + describe(SUITE, () => { beforeAll(async () => { try { @@ -37,7 +55,6 @@ export default function patternLockThemeTest() { const pages: router.RouterState = router.getState(); if (pages?.name !== `PatternLockPage`) { await router.pushUrl(options).then(() => { - localTheme = AppStorage.get(patternLockThemeProperty); console.info(`${SUITE} router.pushUrl success`); }); } -- Gitee From 6cfe9d77b2c9872592f31aa1dc8b39c68b9ef5b2 Mon Sep 17 00:00:00 2001 From: kseniakukushkina_c098 Date: Fri, 20 Dec 2024 06:34:48 +0000 Subject: [PATCH 2/4] PatternLock test updated --- .../ets/test/components/PatternLock.test.ets | 134 ++++++++++-------- 1 file changed, 71 insertions(+), 63 deletions(-) diff --git a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets index 3112e55c16..644733ff95 100644 --- a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets +++ b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets @@ -64,18 +64,18 @@ export default function patternLockThemeTest() { } }); - beforeEach(() => { - if (!changeTheme) { - return; - } - if ((AppStorage.get(patternLockThemeProperty) as Theme)?.colors?.fontEmphasize - == redCustomTheme?.colors?.fontEmphasize) { - AppStorage.setOrCreate(patternLockThemeProperty, greenCustomTheme); + beforeEach( async () => { + // setting preconditions for each testcase + index = index + 1 + // if theme is empty + if (themes[index] === undefined) { + // sending themeSet=false to PatternLockPage to use withTheme(undefined) + AppStorage.setOrCreate(patternLockThemeSetProperty, false) } else { - AppStorage.setOrCreate(patternLockThemeProperty, redCustomTheme); + // sending theme=current theme to PatternLockPage to use withTheme(current theme) + AppStorage.setOrCreate(patternLockThemeProperty, themes[index] ?? redCustomTheme) + AppStorage.setOrCreate(patternLockThemeSetProperty, true) } - localTheme = AppStorage.get(patternLockThemeProperty); - changeTheme = false; }); afterAll(() => { @@ -97,23 +97,10 @@ export default function patternLockThemeTest() { it(`ActsPatternLockThemeColors_0100`, 0, () => { const CASE: string = `ActsPatternLockThemeColors_0100`; console.info(`${SUITE} ${CASE} START`); - const patternLockJSON = getInspectorByKey(PatternLockKeys.patternLockSystem); - const attrsPatternLock = (JSON.parse(patternLockJSON)?.$attrs as PatternLockAttribute); - const regularColor: string = attrsPatternLock?.regularColor?.toString().toUpperCase() ?? emptyAttr; - const checkRegularColor: string = colorValues?.get(`compBackgroundNeutral`)?.toString().toUpperCase() - ?? emptyCheck; - expect(regularColor).assertEqual(checkRegularColor); - const activeColor: string = attrsPatternLock?.activeColor?.toString().toUpperCase() ?? emptyAttr; - const checkActiveColor: string = colorValues?.get(`compBackgroundNeutral`)?.toString().toUpperCase() - ?? emptyCheck; - expect(activeColor, checkActiveColor); - const selectedColor: string = attrsPatternLock?.selectedColor?.toString().toUpperCase(); - const checkSelectedColor: string = colorValues?.get(`compBackgroundNeutral`)?.toString().toUpperCase() - ?? emptyCheck; - expect(selectedColor, checkSelectedColor); - const pathColor: string = attrsPatternLock?.pathColor?.toString().toUpperCase(); - const checkPathColor: string = colorValues?.get(`compDivider`)?.toString().toUpperCase() ?? emptyCheck; - expect(pathColor).assertEqual(checkPathColor); + patternLockKeys.forEach((key) => { + if (key.search(`WithTheme`) > 0) return + checkWithTheme(key, undefined, key.search(`CustomAttrs`) > 0, colorValues) + }) console.info(`${SUITE} ${CASE} END`); }); /** @@ -128,24 +115,10 @@ export default function patternLockThemeTest() { const CASE: string = `ActsPatternLockThemeColors_0200`; console.info(`${SUITE} ${CASE} START`); await sleep(frameTime); - const patternLockJSON = getInspectorByKey(PatternLockKeys.patternLockWithTheme); - const attrsPatternLock = (JSON.parse(patternLockJSON)?.$attrs as PatternLockAttribute); - const regularColor: string = attrsPatternLock?.regularColor?.toString().toUpperCase() ?? emptyAttr;; - const checkRegularColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(regularColor).assertEqual(checkRegularColor); - const activeColor: string = attrsPatternLock?.activeColor?.toString().toUpperCase() ?? emptyAttr; - const checkActiveColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(activeColor).assertEqual(checkActiveColor); - const selectedColor: string = attrsPatternLock?.selectedColor?.toString().toUpperCase() ?? emptyAttr; - const checkSelectedColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(selectedColor).assertEqual(checkSelectedColor); - const pathColor: string = attrsPatternLock?.pathColor?.toString().toUpperCase() ?? emptyAttr; - const checkPathColor: string = localTheme?.colors?.compDivider?.toString().toUpperCase() ?? emptyCheck; - expect(pathColor).assertEqual(checkPathColor); - changeTheme = true; + patternLockKeys.forEach((key) => { + if (key.search(`System`) > 0) return + checkWithTheme(key, themes[index], key.search(`CustomAttrs`) > 0, colorValues) + }) console.info(`${SUITE} ${CASE} END`); }); @@ -162,25 +135,60 @@ export default function patternLockThemeTest() { const CASE: string = `ActsPatternLockThemeColors_0300`; console.info(`${SUITE} ${CASE} START`); await sleep(frameTime); - const patternLockJSON = getInspectorByKey(PatternLockKeys.patternLockWithTheme); - const attrsPatternLock = (JSON.parse(patternLockJSON)?.$attrs as PatternLockAttribute); - const regularColor: string = attrsPatternLock?.regularColor?.toString().toUpperCase() ?? emptyAttr;; - const checkRegularColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(regularColor).assertEqual(checkRegularColor); - const activeColor: string = attrsPatternLock?.activeColor?.toString().toUpperCase() ?? emptyAttr; - const checkActiveColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(activeColor).assertEqual(checkActiveColor); - const selectedColor: string = attrsPatternLock?.selectedColor?.toString().toUpperCase() ?? emptyAttr; - const checkSelectedColor: string = localTheme?.colors?.compBackgroundNeutral?.toString().toUpperCase() - ?? emptyCheck; - expect(selectedColor).assertEqual(checkSelectedColor); - const pathColor: string = attrsPatternLock?.pathColor?.toString().toUpperCase() ?? emptyAttr; - const checkPathColor: string = localTheme?.colors?.compDivider?.toString().toUpperCase() ?? emptyCheck; - expect(pathColor).assertEqual(checkPathColor); - changeTheme = true; + patternLockKeys.forEach((key) => { + if (key.search(`System`) > 0) return + checkWithTheme(key, themes[index], key.search(`CustomAttrs`) > 0, colorValues) + }) + console.info(`${SUITE} ${CASE} END`); + }); + + /** + * @tc.number : ActsPatternLockThemeColors_0400 + * @tc.name : ActsPatternLockThemeColors_0400 + * @tc.desc : Check system colors values of PatternLock component + * after resetting the theme + * @tc.level : Level 2 + * @tc.size : MediumTest + * @tc.type : Function + */ + it(`ActsPatternLockThemeColors_0400`, 0, async () => { + const CASE: string = `ActsPatternLockThemeColors_0400`; + console.info(`${SUITE} ${CASE} START`); + await sleep(frameTime); + patternLockKeys.forEach((key) => { + checkWithTheme(key, undefined, key.search(`CustomAttrs`) > 0, colorValues) + }) console.info(`${SUITE} ${CASE} END`); }); + }); +} + +function checkWithTheme(key: string, localTheme: CustomTheme | undefined, customAttrs: boolean, colorValues: Map | undefined) { + const patternLockJSON = getInspectorByKey(PatternLockKeys.patternLockWithTheme) + console.warn(`KKK ` + key) + const attrsPatternLock = (JSON.parse(patternLockJSON)?.$attrs as PatternLockAttribute) + const regularColor = attrsPatternLock?.regularColor?.toString().toUpperCase() ?? EMPTY_ATTR + const checkRegularColor: string = (customAttrs ? brownCustomTheme : localTheme)?.colors?.compBackgroundNeutral?.toString() + ?? colorValues?.get('compBackgroundNeutral') + ?? EMPTY_CHECK + expect(regularColor).assertEqual(checkRegularColor) + + const activeColor = attrsPatternLock?.activeColor?.toString().toUpperCase() ?? EMPTY_ATTR + const checkActiveColor: string = (customAttrs ? brownCustomTheme : localTheme)?.colors?.compBackgroundNeutral?.toString() + ?? colorValues?.get('compBackgroundNeutral') + ?? EMPTY_CHECK + expect(activeColor).assertEqual(checkActiveColor) + + const selectedColor = attrsPatternLock?.selectedColor?.toString().toUpperCase() ?? EMPTY_ATTR + const checkSelectedColor: string = (customAttrs ? brownCustomTheme : localTheme)?.colors?.compBackgroundNeutral?.toString() + ?? colorValues?.get('compBackgroundNeutral') + ?? EMPTY_CHECK + expect(selectedColor).assertEqual(checkSelectedColor) + + const pathColor = attrsPatternLock?.pathColor?.toString().toUpperCase() ?? EMPTY_ATTR + const checkPathColor: string = (customAttrs ? brownCustomTheme : localTheme)?.colors?.compDivider?.toString() + ?? colorValues?.get('compDivider') + ?? EMPTY_CHECK + expect(pathColor).assertEqual(checkPathColor) } \ No newline at end of file -- Gitee From 0c946842d5f92f8db0ac56cc0e69394850351bb1 Mon Sep 17 00:00:00 2001 From: kseniakukushkina_c098 Date: Fri, 20 Dec 2024 07:13:03 +0000 Subject: [PATCH 3/4] test fix --- .../entry/src/main/ets/test/components/PatternLock.test.ets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets index 644733ff95..b0413198c5 100644 --- a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets +++ b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/test/components/PatternLock.test.ets @@ -165,8 +165,7 @@ export default function patternLockThemeTest() { } function checkWithTheme(key: string, localTheme: CustomTheme | undefined, customAttrs: boolean, colorValues: Map | undefined) { - const patternLockJSON = getInspectorByKey(PatternLockKeys.patternLockWithTheme) - console.warn(`KKK ` + key) + const patternLockJSON = getInspectorByKey(key) const attrsPatternLock = (JSON.parse(patternLockJSON)?.$attrs as PatternLockAttribute) const regularColor = attrsPatternLock?.regularColor?.toString().toUpperCase() ?? EMPTY_ATTR const checkRegularColor: string = (customAttrs ? brownCustomTheme : localTheme)?.colors?.compBackgroundNeutral?.toString() -- Gitee From 76299105e8bdc4d93f51846e4763d2d98bc99b56 Mon Sep 17 00:00:00 2001 From: kseniakukushkina_c098 Date: Fri, 20 Dec 2024 07:13:57 +0000 Subject: [PATCH 4/4] page fix --- .../ets/MainAbility/pages/components/PatternLockPage.ets | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets index d2df3b37ed..9c387d45b9 100644 --- a/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets +++ b/arkui/ace_ets_module_ui/ace_ets_module_theme/ace_ets_module_theme_hvigor/entry/src/main/ets/MainAbility/pages/components/PatternLockPage.ets @@ -32,11 +32,10 @@ struct PatternLockPage { @StorageLink(patternLockThemeProperty) localTheme: CustomTheme | undefined = redCustomTheme; @StorageLink(patternLockThemeSetProperty) themeSet: boolean = true patternLockController: PatternLockController = new PatternLockController(); - timeZoneOffset: number = 1; build() { Column() { - PatternLock(this.patternLockController ) + PatternLock(this.patternLockController) .key(PatternLockKeys.patternLockSystem) PatternLock(this.patternLockController) @@ -46,7 +45,7 @@ struct PatternLockPage { .pathColor(brownCustomTheme.colors?.compDivider) .key(PatternLockKeys.patternLockSystemCustomAttrs) - WithTheme({ theme: this.localTheme }) { + WithTheme({ theme: this.themeSet ? this.localTheme : undefined }) { Column() { PatternLock(this.patternLockController) .key(PatternLockKeys.patternLockWithTheme) -- Gitee