Add tests for the upcoming events widget
This commit is contained in:
1 parent
e241c95fdb
commit
e7dc274520
1 file changed
+92
@@ -0,0 +1,92 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'dashtab/tests/helpers';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import UpcomingEvents from 'dashtab/components/upcoming-events';
|
||||
|
||||
function registerCalendar(owner, calendar) {
|
||||
owner.register('service:calendar', calendar, { instantiate: false });
|
||||
}
|
||||
|
||||
module('Integration | Component | upcoming-events', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('renders nothing while no calendar is enabled', async function (assert) {
|
||||
registerCalendar(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) {
|
||||
registerCalendar(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) {
|
||||
registerCalendar(this.owner, {
|
||||
enabled: true,
|
||||
events: { today: [], days: [] },
|
||||
});
|
||||
|
||||
await render(<template><UpcomingEvents /></template>);
|
||||
|
||||
assert.dom().containsText('No upcoming events');
|
||||
});
|
||||
|
||||
test('labels all-day events', async function (assert) {
|
||||
registerCalendar(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');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user