Files
raucao d846735b1e Crossfade the wallpaper only on intentional changes
Use a new bundled image for both the welcome screen and the dashboard
fallback, and crossfade into the first feed photo only when arriving from
the welcome screen or when the wallpaper changes after the first paint (a
live rotation or a manual pick). A plain open shows the resolved photo
outright, with no transition.

- wallpaper.gjs: three layers (bundled base, last settled photo, current
  photo). The current photo fades in on load and the previous one stays
  beneath for a crossfade; the photo layer renders only from the cached
  displayUrl, so a change fades instead of flashing the bundled base.
  Reduced motion settles instantly.
- photos.js: keep the last-known-good wallpaper on a cache miss or fetch
  error; add a one-shot timer that rotates at the day/week boundary while
  the dashboard stays open; expose animateEntry for the welcome entry.
- routes/index.js: set photos.animateEntry from the transition origin. A
  strict-mode route template's `this` is not the controller, so a
  controller property never reached the component.
- config/nostr.js: alias the welcome and fallback URLs to one image.

Tests and docs updated.
2026-11-10 15:18:13 +04:00

179 lines
5.5 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, settled, triggerEvent } from '@ember/test-helpers';
import Wallpaper from 'dashtab/components/wallpaper';
import FakePhotos from 'dashtab/tests/helpers/fake-photos';
module('Integration | Component | wallpaper', function (hooks) {
setupRenderingTest(hooks);
function registerPhotos(context, overrides = {}) {
const photos = new FakePhotos();
Object.assign(photos, overrides);
context.owner.register('service:photos', photos, {
instantiate: false,
});
return photos;
}
test('renders the current wallpaper object URL and not the thumbnail', async function (assert) {
registerPhotos(this, {
currentWallpaper: {
url: 'https://blossom.example/full.jpg',
thumbUrl: 'https://blossom.example/thumb.jpg',
displayUrl: 'blob:cached-full',
},
});
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').hasAttribute('src', 'blob:cached-full');
assert.notOk(
this.element
.querySelector('[data-test-wallpaper]')
.getAttribute('src')
.includes('thumb')
);
assert.dom('[data-test-wallpaper-container]').exists();
});
test('shows only the bundled fallback while the cache warms', async function (assert) {
registerPhotos(this, {
currentWallpaper: {
url: 'https://blossom.example/full.jpg',
thumbUrl: 'https://blossom.example/thumb.jpg',
displayUrl: null,
},
});
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').doesNotExist();
assert.dom('[data-test-wallpaper-base]').doesNotExist();
assert.dom('[data-test-wallpaper-container] img').exists({ count: 1 });
});
test('accepts a route-specific photo for the welcome screen', async function (assert) {
registerPhotos(this);
this.welcomePhoto = {
url: '/img/wallpapers/welcome.jpg',
displayUrl: '/img/wallpapers/welcome.jpg',
alt: '',
};
await render(
<template><Wallpaper @photo={{this.welcomePhoto}} /></template>
);
assert
.dom('[data-test-wallpaper]')
.hasAttribute('src', '/img/wallpapers/welcome.jpg');
});
test('renders only the fallback when no wallpaper is selected', async function (assert) {
registerPhotos(this, { currentWallpaper: null });
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').doesNotExist();
assert.dom('[data-test-wallpaper-container] img').exists({ count: 1 });
});
test('shows the first photo outright on a plain open', async function (assert) {
registerPhotos(this, {
currentWallpaper: {
url: 'https://blossom.example/full.jpg',
displayUrl: 'blob:cached-full',
},
});
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').hasClass('opacity-100');
assert.dom('[data-test-wallpaper-base]').doesNotExist();
await triggerEvent('[data-test-wallpaper]', 'load');
assert
.dom('[data-test-wallpaper-base]')
.hasAttribute('src', 'blob:cached-full');
});
test('crossfades the first photo in when arriving from the welcome screen', async function (assert) {
registerPhotos(this, {
animateEntry: true,
currentWallpaper: {
url: 'https://blossom.example/full.jpg',
displayUrl: 'blob:cached-full',
},
});
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').hasClass('opacity-0');
await triggerEvent('[data-test-wallpaper]', 'load');
assert.dom('[data-test-wallpaper]').hasClass('opacity-100');
});
test('fades in a photo that resolves after mount when arriving from welcome', async function (assert) {
const photos = registerPhotos(this, {
animateEntry: true,
currentWallpaper: null,
});
await render(<template><Wallpaper /></template>);
assert.dom('[data-test-wallpaper]').doesNotExist();
photos.currentWallpaper = {
url: 'https://blossom.example/full.jpg',
displayUrl: 'blob:cached-full',
};
await settled();
assert.dom('[data-test-wallpaper]').hasClass('opacity-0');
await triggerEvent('[data-test-wallpaper]', 'load');
assert.dom('[data-test-wallpaper]').hasClass('opacity-100');
});
test('crossfades between photos, keeping the previous one beneath', async function (assert) {
const photos = registerPhotos(this, {
currentWallpaper: {
url: 'https://blossom.example/a.jpg',
displayUrl: 'blob:a',
},
});
await render(<template><Wallpaper /></template>);
await triggerEvent('[data-test-wallpaper]', 'load');
await triggerEvent('[data-test-wallpaper]', 'transitionend', {
propertyName: 'opacity',
});
assert.dom('[data-test-wallpaper-base]').hasAttribute('src', 'blob:a');
photos.currentWallpaper = {
url: 'https://blossom.example/b.jpg',
displayUrl: 'blob:b',
};
await settled();
assert.dom('[data-test-wallpaper]').hasAttribute('src', 'blob:b');
assert.dom('[data-test-wallpaper]').hasClass('opacity-0');
assert.dom('[data-test-wallpaper-base]').hasAttribute('src', 'blob:a');
await triggerEvent('[data-test-wallpaper]', 'load');
await triggerEvent('[data-test-wallpaper]', 'transitionend', {
propertyName: 'opacity',
});
assert.dom('[data-test-wallpaper]').hasClass('opacity-100');
assert.dom('[data-test-wallpaper-base]').hasAttribute('src', 'blob:b');
});
});