personalization: hide daily refresh button when album is empty
Only display the Daily Refresh button when the selected album has at
least one image.
BUG=b:275427139
TEST=Manually, browser_tests --gtest_filter="*WallpaperSelected*"
Change-Id: I5f09462803d984bc8cbe0e29b288691c49f4f4da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4405557
Commit-Queue: Jerry Liu <pzliu@google.com>
Reviewed-by: Jason Thai <jasontt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1127346}
diff --git a/ash/webui/personalization_app/resources/js/wallpaper/wallpaper_selected_element.ts b/ash/webui/personalization_app/resources/js/wallpaper/wallpaper_selected_element.ts
index fdbe59f7..76a85132 100644
--- a/ash/webui/personalization_app/resources/js/wallpaper/wallpaper_selected_element.ts
+++ b/ash/webui/personalization_app/resources/js/wallpaper/wallpaper_selected_element.ts
@@ -18,7 +18,7 @@
import {assert} from 'chrome://resources/js/assert_ts.js';
-import {CurrentWallpaper, WallpaperLayout, WallpaperType} from '../../personalization_app.mojom-webui.js';
+import {CurrentWallpaper, GooglePhotosPhoto, WallpaperLayout, WallpaperType} from '../../personalization_app.mojom-webui.js';
import {isGooglePhotosSharedAlbumsEnabled, isPersonalizationJellyEnabled} from '../load_time_booleans.js';
import {Paths} from '../personalization_router_element.js';
import {WithPersonalizationStore} from '../personalization_store.js';
@@ -65,6 +65,8 @@
*/
path: String,
+ photosByAlbumId_: Object,
+
image_: {
type: Object,
observer: 'onImageChanged_',
@@ -116,7 +118,8 @@
showDailyRefreshButton_: {
type: Boolean,
- computed: 'isDailyRefreshable_(path,googlePhotosAlbumId)',
+ computed:
+ 'isDailyRefreshable_(path,googlePhotosAlbumId,photosByAlbumId_)',
},
showRefreshButton_: {
@@ -187,6 +190,8 @@
private centerIcon_: string;
private error_: string;
private googlePhotosSharedAlbumsEnabled_: boolean;
+ private photosByAlbumId_: Record<string, GooglePhotosPhoto[]|null|undefined>|
+ undefined;
override connectedCallback() {
super.connectedCallback();
@@ -199,6 +204,9 @@
state.wallpaper.loading.selected ||
state.wallpaper.loading.refreshWallpaper);
this.watch('dailyRefreshState_', state => state.wallpaper.dailyRefresh);
+ this.watch(
+ 'photosByAlbumId_',
+ state => state.wallpaper.googlePhotos.photosByAlbumId);
this.updateFromStore();
getDailyRefreshState(getWallpaperProvider(), this.getStore());
}
@@ -344,9 +352,14 @@
}
private isDailyRefreshable_(
- path: string, googlePhotosAlbumId: string|undefined) {
+ path: string, googlePhotosAlbumId: string|undefined,
+ photosByAlbumId: Record<string, GooglePhotosPhoto[]|null|undefined>) {
+ const isNonEmptyGooglePhotosAlbum = !!googlePhotosAlbumId &&
+ !!photosByAlbumId &&
+ isNonEmptyArray(photosByAlbumId[googlePhotosAlbumId]);
return path === Paths.COLLECTION_IMAGES ||
- (path === Paths.GOOGLE_PHOTOS_COLLECTION && !!googlePhotosAlbumId);
+ (path === Paths.GOOGLE_PHOTOS_COLLECTION &&
+ isNonEmptyGooglePhotosAlbum);
}
/**
diff --git a/chrome/test/data/webui/chromeos/personalization_app/wallpaper_selected_element_test.ts b/chrome/test/data/webui/chromeos/personalization_app/wallpaper_selected_element_test.ts
index 89994b4b..a0952809 100644
--- a/chrome/test/data/webui/chromeos/personalization_app/wallpaper_selected_element_test.ts
+++ b/chrome/test/data/webui/chromeos/personalization_app/wallpaper_selected_element_test.ts
@@ -229,7 +229,32 @@
});
test(
- 'shows daily refresh option on the google photos album view',
+ 'shows daily refresh option on non-empty google photos album view',
+ async () => {
+ personalizationStore.data.wallpaper.currentSelected =
+ wallpaperProvider.currentWallpaper;
+ personalizationStore.data.wallpaper.loading.selected = false;
+
+ const album_id = 'test_album_id';
+ wallpaperSelectedElement = initElement(WallpaperSelected, {
+ 'path': Paths.GOOGLE_PHOTOS_COLLECTION,
+ 'googlePhotosAlbumId': album_id,
+ });
+ await waitAfterNextRender(wallpaperSelectedElement);
+
+ const dailyRefresh =
+ wallpaperSelectedElement.shadowRoot!.getElementById(
+ dailyRefreshButtonId);
+ assertTrue(!!dailyRefresh);
+
+ const refreshWallpaper =
+ wallpaperSelectedElement.shadowRoot!.getElementById(
+ 'refreshWallpaper');
+ assertTrue(refreshWallpaper!.hidden);
+ });
+
+ test(
+ 'hides daily refresh option on empty google photos album view',
async () => {
personalizationStore.data.wallpaper.currentSelected =
wallpaperProvider.currentWallpaper;
@@ -244,7 +269,7 @@
const dailyRefresh =
wallpaperSelectedElement.shadowRoot!.getElementById(
dailyRefreshButtonId);
- assertTrue(!!dailyRefresh);
+ assertTrue(dailyRefresh!.hidden);
const refreshWallpaper =
wallpaperSelectedElement.shadowRoot!.getElementById(