forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileName.test.js
119 lines (98 loc) · 3.65 KB
/
ProfileName.test.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import * as React from 'react';
import { fireEvent } from '@testing-library/react';
import { Provider } from 'react-redux';
import { render } from 'firefox-profiler/test/fixtures/testing-library';
import { ProfileName } from '../../components/app/ProfileName';
import { storeWithProfile } from '../fixtures/stores';
import { getProfileFromTextSamples } from '../fixtures/profiles/processed-profile';
import { getProfileNameFromUrl } from 'firefox-profiler/selectors';
import { changeProfileName } from 'firefox-profiler/actions/profile-view';
import { withAnalyticsMock } from '../fixtures/mocks/analytics';
describe('ProfileName', function () {
const defaultName = 'Firefox – macOS 10.14';
function setup(profileName?: string) {
const { profile } = getProfileFromTextSamples('A');
Object.assign(profile.meta, {
oscpu: 'Intel Mac OS X 10.14',
platform: 'Macintosh',
toolkit: 'cocoa',
});
const store = storeWithProfile(profile);
if (profileName) {
store.dispatch(changeProfileName(profileName));
}
const renderResult = render(
<Provider store={store}>
<ProfileName />
</Provider>
);
return { ...store, ...renderResult };
}
function nullProfile() {
const { profile } = getProfileFromTextSamples('A');
Object.assign(profile.meta, {
oscpu: '',
platform: '',
toolkit: '',
product: '',
});
const store = storeWithProfile(profile);
const renderResult = render(
<Provider store={store}>
<ProfileName />
</Provider>
);
return { ...store, ...renderResult };
}
it('matches the snapshot', function () {
const { container } = setup();
expect(container).toMatchSnapshot();
});
it('has a default name', function () {
const { getByText } = setup();
expect(getByText(defaultName)).toBeInTheDocument();
});
it('can edit the name', function () {
const { getByText, queryByText, getByDisplayValue, getState } = setup();
const button = getByText(defaultName);
// Test the default state.
expect(getByText(defaultName)).toBeInTheDocument();
expect(getProfileNameFromUrl(getState())).toBe(null);
// Click the button to activate it.
button.click();
const input = getByDisplayValue(defaultName);
expect(queryByText('Custom name')).not.toBeInTheDocument();
// Change the input, and blur it.
fireEvent.change(input, { target: { value: 'Custom name' } });
fireEvent.blur(input);
expect(getByText('Custom name')).toBeInTheDocument();
expect(getProfileNameFromUrl(getState())).toBe('Custom name');
});
it('sends analytics', () => {
withAnalyticsMock(() => {
const { getByText, getByDisplayValue } = setup();
const button = getByText(defaultName);
button.click();
const input = getByDisplayValue(defaultName);
fireEvent.change(input, { target: { value: 'Custom name' } });
fireEvent.blur(input);
expect(self.ga).toHaveBeenCalledWith('send', {
eventAction: 'change profile name',
eventCategory: 'profile',
hitType: 'event',
});
});
});
it('will use a url-provided profile name', function () {
const { getByText } = setup('Custom name from URL');
expect(getByText('Custom name from URL')).toBeInTheDocument();
});
it('shows UnitledProfile when profile has no name', () => {
const { getByText } = nullProfile();
expect(getByText('Untitled profile')).toBeInTheDocument();
});
});