-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathmessages.spec.ts
More file actions
69 lines (61 loc) · 1.72 KB
/
messages.spec.ts
File metadata and controls
69 lines (61 loc) · 1.72 KB
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
import { describe, it, beforeEach, expect } from 'vitest';
import { setActivePinia, createPinia } from 'pinia';
import { MessageType, useMessageStore } from '@/src/store/messages';
describe('Message store', () => {
beforeEach(() => {
setActivePinia(createPinia());
});
it('supports adding, accessing, and deleting messages', () => {
const messageStore = useMessageStore();
const innerError = new Error('inner error');
const ids = [
messageStore.addError('an error', { error: innerError }),
messageStore.addWarning('warning'),
messageStore.addInfo('info'),
messageStore.addInfo('loading', {
details: 'Loading files',
persist: true,
}),
];
const expected = [
{
type: MessageType.Error,
title: 'an error',
options: {
details: innerError.stack ?? String(innerError),
persist: false,
},
},
{
type: MessageType.Warning,
title: 'warning',
options: {
persist: false,
},
},
{
type: MessageType.Info,
title: 'info',
options: {
persist: false,
},
},
{
type: MessageType.Info,
title: 'loading',
options: {
details: 'Loading files',
persist: true,
},
},
].map((ex, i) => ({ ...ex, id: String(i + 1) }));
expect(messageStore.messages).to.have.length(4);
ids.forEach((id, index) => {
expect(messageStore.byID[id]).toMatchObject(expected[index]);
});
messageStore.clearOne(ids[1]);
expect(messageStore.byID).to.not.have.property(ids[1]);
messageStore.clearAll();
expect(messageStore.messages).to.be.empty;
});
});