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 c4cfedfa016f5f26116e496821fed1bb95f2ec80..9c387d45b926fe1ed8adc55f63d5fd13b3e126e8 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,29 +13,50 @@ * 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; build() { Column() { - PatternLock(this.patternLockController ) + PatternLock(this.patternLockController) .key(PatternLockKeys.patternLockSystem) - WithTheme({ theme: this.localTheme }) { - 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.patternLockSystemCustomAttrs) + + WithTheme({ theme: this.themeSet ? this.localTheme : undefined }) { + 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 ccd32945bfc4c63787b9d65b5ce593889168550d..b0413198c50fd5d1d1cf123a3f0ad513bf1fb43d 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`); }); } @@ -47,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(() => { @@ -80,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`); }); /** @@ -111,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`); }); @@ -145,25 +135,59 @@ 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(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