Files
2026-10-05 12:15:15 +02:00

85 lines
2.2 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import SiteLinks from 'dashtab/components/site-links';
class FakeSitesService {
@tracked groups = [];
}
class FakeNotificationsService {
stateFor(site) {
return { status: 'ready', unreadCount: site.unreadCount ?? 0, items: [] };
}
}
module('Integration | Component | site-links', function (hooks) {
setupRenderingTest(hooks);
test('it renders nothing when there are no connected sites', async function (assert) {
const sites = new FakeSitesService();
this.owner.register('service:sites', sites, { instantiate: false });
this.owner.register(
'service:notifications',
new FakeNotificationsService(),
{
instantiate: false,
}
);
await render(<template><SiteLinks /></template>);
assert.dom('[data-test-site-links]').doesNotExist();
});
test('it renders a group per site group', async function (assert) {
const sites = new FakeSitesService();
sites.groups = [
{
id: 'discourse',
label: 'Discourse',
items: [
{
id: 'discourse-abc',
type: 'discourse',
label: 'forum.example.com',
href: 'https://forum.example.com',
unreadCount: 3,
},
],
},
{
id: 'code-forge',
label: 'Code Forges',
items: [
{
id: 'github',
type: 'github',
label: 'GitHub',
href: 'https://github.com/notifications',
unreadCount: 0,
},
],
},
];
this.owner.register('service:sites', sites, { instantiate: false });
this.owner.register(
'service:notifications',
new FakeNotificationsService(),
{
instantiate: false,
}
);
await render(<template><SiteLinks /></template>);
assert.dom('[data-test-site-links]').exists();
assert.dom('[data-group="discourse"]').exists();
assert.dom('[data-group="code-forge"]').exists();
assert.dom('a').exists({ count: 2 });
assert.dom('[data-test-site-links-count]').hasText('3');
});
});