-
Notifications
You must be signed in to change notification settings - Fork 461
/
dot-announcements.store.spec.ts
94 lines (82 loc) · 3.26 KB
/
dot-announcements.store.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator';
import { of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { SiteService, SiteServiceMock } from '@dotcms/dotcms-js';
import { Announcement, AnnouncementsStore } from './dot-announcements.store';
describe('AnnouncementsStore', () => {
let spectator: SpectatorService<AnnouncementsStore>;
const siteServiceMock = new SiteServiceMock();
const createService = createServiceFactory({
service: AnnouncementsStore,
imports: [HttpClientTestingModule],
providers: [
{
provide: SiteService,
useValue: siteServiceMock
},
mockProvider(HttpClient, {
get: jasmine.createSpy('get').and.returnValue(
of({
entity: [
{
title: 'Test Announcement',
type: 'announcement',
announcementDateAsISO8601: '2024-01-31T17:51',
identifier: 'test-announcement-id',
inode: '123',
url: 'https://www.example.com'
}
]
})
)
})
]
});
beforeEach(() => {
spectator = createService();
});
it('should fetch announcements', (done) => {
const mockAnnouncements: Announcement[] = [
{
title: 'Test Announcement',
type: 'announcement',
announcementDateAsISO8601: '2024-01-31T17:51',
identifier: 'test-announcement-id',
inode: '123',
url: 'https://www.example.com?utm_source=platform&utm_medium=announcement&utm_campaign=demo.dotcms.com'
}
];
spectator.service.load();
spectator.service.state$.subscribe((state) => {
expect(state.announcements).toEqual(mockAnnouncements);
done();
});
});
it('should not mark announcements as unread when there are no new announcements', (done) => {
localStorage.removeItem('dotAnnouncementsData');
spectator.service.load();
spectator.service.markAnnouncementsAsRead();
spectator.service.state$.subscribe((state) => {
expect(state.showUnreadAnnouncement).toBe(false);
done();
});
});
it('should mark announcements as unread', (done) => {
localStorage.removeItem('dotAnnouncementsData');
spectator.service.load();
spectator.service.state$.subscribe((state) => {
expect(state.showUnreadAnnouncement).toBe(true);
done();
});
});
it('should update the url when the site changes', (done) => {
spectator.service.load();
spectator.service.state$.subscribe((state) => {
expect(state.announcements[0].url).toBe(
'https://www.example.com?utm_source=platform&utm_medium=announcement&utm_campaign=demo.dotcms.com'
);
done();
});
});
});