Render the calendar service's error in the widget instead of the empty state, and clear a stale error at the start of each successful refresh cycle.
162 lines
4.4 KiB
Plaintext
162 lines
4.4 KiB
Plaintext
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
|
import { render } from '@ember/test-helpers';
|
|
import UpcomingEvents from 'dashtab/components/upcoming-events';
|
|
import { timeParts } from 'dashtab/utils/time-format';
|
|
|
|
function registerServices(owner, calendar, timeFormat = '24h') {
|
|
owner.register('service:calendar', calendar, { instantiate: false });
|
|
owner.register(
|
|
'service:clock',
|
|
{ time: new Date(), timeFormat },
|
|
{ instantiate: false }
|
|
);
|
|
}
|
|
|
|
module('Integration | Component | upcoming-events', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test('renders nothing while no calendar is enabled', async function (assert) {
|
|
registerServices(this.owner, {
|
|
enabled: false,
|
|
events: { today: [], days: [] },
|
|
});
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert.dom('[data-test-upcoming-events]').doesNotExist();
|
|
});
|
|
|
|
test('renders today and the upcoming days with events', async function (assert) {
|
|
registerServices(this.owner, {
|
|
enabled: true,
|
|
events: {
|
|
today: [
|
|
{
|
|
id: 'e1',
|
|
name: 'Standup',
|
|
startTime: '2026-08-03T09:00:00',
|
|
allDay: false,
|
|
},
|
|
],
|
|
days: [
|
|
{
|
|
key: '2026-08-04',
|
|
date: new Date(2026, 7, 4),
|
|
events: [
|
|
{
|
|
id: 'e2',
|
|
name: 'Lunch',
|
|
startTime: '2026-08-04T12:00:00',
|
|
allDay: false,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert.dom('[data-test-upcoming-events]').exists();
|
|
assert.dom().containsText('Today');
|
|
assert.dom().containsText('Standup');
|
|
assert.dom().containsText('Lunch');
|
|
});
|
|
|
|
test('shows an empty state when enabled but nothing is upcoming', async function (assert) {
|
|
registerServices(this.owner, {
|
|
enabled: true,
|
|
events: { today: [], days: [] },
|
|
});
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert.dom().containsText('No upcoming events');
|
|
});
|
|
|
|
test('shows the calendar error instead of the empty state', async function (assert) {
|
|
registerServices(this.owner, {
|
|
enabled: true,
|
|
error: 'Unable to reach the Sockethub server',
|
|
events: { today: [], days: [] },
|
|
});
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert
|
|
.dom('[data-test-upcoming-events]')
|
|
.containsText('Unable to reach the Sockethub server');
|
|
assert.dom().doesNotContainText('No upcoming events');
|
|
});
|
|
|
|
test('labels all-day events', async function (assert) {
|
|
registerServices(this.owner, {
|
|
enabled: true,
|
|
events: {
|
|
today: [
|
|
{
|
|
id: 'e1',
|
|
name: 'Holiday',
|
|
startTime: '2026-08-03',
|
|
allDay: true,
|
|
},
|
|
],
|
|
days: [],
|
|
},
|
|
});
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert.dom().containsText('All day');
|
|
});
|
|
|
|
test('formats event times with the clock preference', async function (assert) {
|
|
const start = new Date(2026, 7, 3, 13, 5);
|
|
const event = {
|
|
id: 'e1',
|
|
name: 'Review',
|
|
startTime: start.toISOString(),
|
|
allDay: false,
|
|
};
|
|
|
|
registerServices(
|
|
this.owner,
|
|
{ enabled: true, events: { today: [event], days: [] } },
|
|
'24h'
|
|
);
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
assert
|
|
.dom('[data-test-upcoming-events]')
|
|
.containsText(timeParts(start, '24h').time);
|
|
assert.dom('[data-test-upcoming-events] .w-14').exists();
|
|
assert.dom('[data-test-upcoming-events] .w-20').doesNotExist();
|
|
});
|
|
|
|
test('uses the 12-hour preference when selected', async function (assert) {
|
|
const start = new Date(2026, 7, 3, 13, 5);
|
|
const event = {
|
|
id: 'e1',
|
|
name: 'Review',
|
|
startTime: start.toISOString(),
|
|
allDay: false,
|
|
};
|
|
|
|
registerServices(
|
|
this.owner,
|
|
{ enabled: true, events: { today: [event], days: [] } },
|
|
'12h'
|
|
);
|
|
|
|
await render(<template><UpcomingEvents /></template>);
|
|
|
|
const { period } = timeParts(start, '12h');
|
|
assert.ok(period.length > 0);
|
|
assert.dom('[data-test-upcoming-events]').containsText(period);
|
|
assert.dom('[data-test-upcoming-events] .w-20').exists();
|
|
assert.dom('[data-test-upcoming-events] .w-14').doesNotExist();
|
|
});
|
|
});
|