-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathActor.test.ts
More file actions
86 lines (66 loc) · 2.64 KB
/
Copy pathActor.test.ts
File metadata and controls
86 lines (66 loc) · 2.64 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @vitest-environment jsdom
*/
import { vi, describe, it, expect } from 'vitest';
import { TRIGGER_LABEL } from '../../../src/constants';
import { getFeedback } from '../../../src/core/getFeedback';
import { buildFeedbackIntegration } from '../../../src/core/integration';
import { mockSdk } from '../mockSdk';
describe('Actor', () => {
it('renders the actor button', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: vi.fn(),
});
const configuredIntegration = feedbackIntegration({});
mockSdk({
sentryOptions: {
integrations: [configuredIntegration],
},
});
const feedback = getFeedback();
expect(feedback).toBeDefined();
const actorComponent = feedback!.createWidget();
expect(actorComponent.el).toBeInstanceOf(HTMLButtonElement);
expect(actorComponent.el.textContent).toBe(TRIGGER_LABEL);
});
it('renders the correct aria label for the button', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: vi.fn(),
});
const configuredIntegration = feedbackIntegration({});
mockSdk({
sentryOptions: {
integrations: [configuredIntegration],
},
});
const feedback = getFeedback();
expect(feedback).toBeDefined();
// aria label is the same as trigger label when the trigger label isn't empty
const actorDefault = feedback!.createWidget({ triggerLabel: 'Button' });
expect(actorDefault.el.textContent).toBe('Button');
expect(actorDefault.el.ariaLabel).toBe('Button');
// aria label is default text when trigger label is empty and aria isn't configured
const actorIcon = feedback!.createWidget({ triggerLabel: '' });
expect(actorIcon.el.textContent).toBe('');
expect(actorIcon.el.ariaLabel).toBe(TRIGGER_LABEL);
// aria label is the triggerAriaLabel if it's configured
const actorAria = feedback!.createWidget({ triggerLabel: 'Button', triggerAriaLabel: 'Aria' });
expect(actorAria.el.textContent).toBe('Button');
expect(actorAria.el.ariaLabel).toBe('Aria');
});
it('does not throw if removeFromDom() is called when it is not mounted', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: vi.fn(),
});
const configuredIntegration = feedbackIntegration({});
mockSdk({
sentryOptions: {
integrations: [configuredIntegration],
},
});
const feedback = getFeedback();
const actorComponent = feedback!.createWidget();
expect(() => actorComponent.removeFromDom()).not.toThrowError();
expect(() => actorComponent.removeFromDom()).not.toThrowError();
});
});