Files
raucao 2cb54813b9 Add weekly and daily wallpaper rotation
Rotate through photos from enabled feeds with a persisted shuffle-bag queue. Weekly changes at local Monday midnight and daily at local midnight; Off keeps the selected photo. Legacy configs migrate to the weekly default, and Rotation now sits above Feeds in the Photos settings.
2026-11-08 22:25:59 +04:00

188 lines
5.6 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import SettingsPhotosSection from 'dashtab/components/settings/global-settings/sections/photos';
import FakePhotos from 'dashtab/tests/helpers/fake-photos';
const PHOTO_CACHE = {
async thumbUrl() {
return null;
},
async originalUrl() {
return null;
},
async prefetchThumb() {
return null;
},
async prefetchOriginal() {
return null;
},
};
function photo(id, title, thumbUrl) {
return {
id,
title,
alt: title,
thumbUrl,
url: thumbUrl.replace('/thumb', '/full'),
attributed: true,
creator: { name: 'Creator Name' },
};
}
module('Integration | Component | settings/photos', function (hooks) {
setupRenderingTest(hooks);
function setup(context) {
const photos = new FakePhotos();
photos.feeds = [
{
id: 'dt:nature',
title: 'Nature',
description: 'Landscapes and forests.',
photos: [
photo(
'nature-1',
'Winding road',
'https://blossom.example/thumb-1.jpg'
),
photo(
'nature-2',
'Awakening trees',
'https://blossom.example/thumb-2.jpg'
),
],
},
{
id: 'dt:city-nights',
title: 'City Nights',
description: 'After-dark city scenes.',
photos: [
photo(
'city-1',
'Train at night',
'https://blossom.example/thumb-3.jpg'
),
],
},
];
photos.enabledFeedIds = ['dt:nature'];
photos.currentPhotoId = 'nature-1';
context.owner.register('service:photos', photos, {
instantiate: false,
});
context.owner.register('service:photo-cache', PHOTO_CACHE, {
instantiate: false,
});
return photos;
}
test('shows Nature enabled and City Nights disabled by default', async function (assert) {
setup(this);
await render(<template><SettingsPhotosSection /></template>);
assert.dom('[data-test-rotation]').exists();
assert.dom('[data-test-feeds-header]').hasText('Feeds');
const rotation = this.element.querySelector('[data-test-rotation]');
const feedsHeader = this.element.querySelector('[data-test-feeds-header]');
assert.true(
Boolean(
rotation.compareDocumentPosition(feedsHeader) &
Node.DOCUMENT_POSITION_FOLLOWING
),
'Rotation appears before Feeds'
);
assert.dom('[data-test-photo-feed="dt:nature"]').exists();
assert.dom('[data-test-photo-feed="dt:city-nights"]').exists();
assert.dom('[data-test-photo-feed-toggle="dt:nature"]').isChecked();
assert.dom('[data-test-photo-feed-toggle="dt:city-nights"]').isNotChecked();
assert.dom('[data-test-photo-grid="dt:nature"]').exists();
assert.dom('[data-test-photo-grid="dt:nature"]').hasClass('grid-cols-4');
assert.dom('[data-test-photo-grid="dt:city-nights"]').doesNotExist();
const feedOrder = [
...this.element.querySelectorAll('[data-test-photo-feed]'),
].map((element) => element.getAttribute('data-test-photo-feed'));
assert.deepEqual(feedOrder, ['dt:nature', 'dt:city-nights']);
assert.dom('[data-test-rotation-next]').exists();
const rotationNext = this.element.querySelector(
'[data-test-rotation-next]'
);
assert.true(
Boolean(
feedsHeader.compareDocumentPosition(rotationNext) &
Node.DOCUMENT_POSITION_FOLLOWING
),
'next-change line appears after the Feeds header'
);
assert.true(
Boolean(
this.element
.querySelector('[data-test-photo-feed="dt:city-nights"]')
.compareDocumentPosition(rotationNext) &
Node.DOCUMENT_POSITION_FOLLOWING
),
'next-change line appears at the bottom of the section'
);
});
test('hides the next-change line when rotation is off', async function (assert) {
const photos = setup(this);
photos.rotation = 'off';
await render(<template><SettingsPhotosSection /></template>);
assert.dom('[data-test-rotation-next]').doesNotExist();
});
test('does not render attribution text in Settings', async function (assert) {
setup(this);
await render(<template><SettingsPhotosSection /></template>);
assert.notOk(this.element.textContent.includes('Photo by'));
assert.notOk(this.element.textContent.includes('Unsplash'));
assert.dom('[data-test-wallpaper-credit]').doesNotExist();
});
test('enabling City Nights reveals its grid', async function (assert) {
const photos = setup(this);
await render(<template><SettingsPhotosSection /></template>);
await click('[data-test-photo-feed-toggle="dt:city-nights"]');
assert.deepEqual(photos.calls.setFeedEnabled, [['dt:city-nights', true]]);
assert.true(photos.isFeedEnabled('dt:city-nights'));
assert.dom('[data-test-photo-grid="dt:city-nights"]').exists();
});
test('clicking a photo selects it immediately', async function (assert) {
const photos = setup(this);
await render(<template><SettingsPhotosSection /></template>);
assert.dom('[data-test-use-now]').doesNotExist();
await click('[data-test-photo="nature-2"]');
assert.deepEqual(photos.calls.setCurrentPhoto, ['nature-2']);
assert.strictEqual(photos.currentPhotoId, 'nature-2');
assert
.dom('[data-test-photo="nature-2"]')
.hasAttribute('aria-pressed', 'true');
assert
.dom('[data-test-photo="nature-1"]')
.hasAttribute('aria-pressed', 'false');
assert
.dom('[data-test-photo="nature-2"] [aria-label="Current wallpaper"]')
.exists();
});
});