123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import ContextSummary from 'sentry/components/events/contextSummary';
- import ContextSummaryGPU from 'sentry/components/events/contextSummary/contextSummaryGPU';
- import ContextSummaryOS from 'sentry/components/events/contextSummary/contextSummaryOS';
- import ContextSummaryUser from 'sentry/components/events/contextSummary/contextSummaryUser';
- import {FILTER_MASK} from 'sentry/constants';
- const CONTEXT_USER = {
- email: 'mail@example.org',
- id: '1',
- };
- const CONTEXT_DEVICE = {
- arch: 'x86',
- family: 'iOS',
- model: 'iPhone10,5',
- type: 'device',
- };
- const CONTEXT_OS = {
- kernel_version: '17.5.0',
- version: '10.13.4',
- type: 'os',
- build: '17E199',
- name: 'Mac OS X',
- };
- const CONTEXT_OS_SERVER = {
- kernel_version: '4.3.0',
- version: '4.3.0',
- type: 'os',
- build: '123123123',
- name: 'Linux',
- };
- const CONTEXT_RUNTIME = {
- version: '1.7.13',
- type: 'runtime',
- name: 'Electron',
- };
- const CONTEXT_BROWSER = {
- version: '65.0.3325',
- name: 'Chrome',
- };
- describe('ContextSummary', function () {
- describe('render()', function () {
- it('renders nothing without contexts', () => {
- const event = {
- id: '',
- contexts: {},
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('renders nothing with a single user context', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {},
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('should bail out with empty contexts', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- device: {},
- os: {},
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('renders at least three contexts', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- device: CONTEXT_DEVICE,
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('renders up to four contexts', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- os: CONTEXT_OS,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE, // must be omitted
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('should prefer client_os over os', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- client_os: CONTEXT_OS,
- os: CONTEXT_OS_SERVER,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('renders client_os too', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- client_os: CONTEXT_OS,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('should skip non-default named contexts', () => {
- const event = {
- id: '',
- user: CONTEXT_USER,
- contexts: {
- os: CONTEXT_OS,
- chrome: CONTEXT_BROWSER, // non-standard context
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE,
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- it('should skip a missing user context', () => {
- const event = {
- id: '',
- contexts: {
- os: CONTEXT_OS,
- chrome: CONTEXT_BROWSER, // non-standard context
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE,
- },
- };
- const wrapper = mountWithTheme(<ContextSummary event={event} />);
- expect(wrapper).toSnapshot();
- });
- });
- });
- describe('OsSummary', function () {
- describe('render()', function () {
- it('renders the version string', () => {
- const os = {
- kernel_version: '17.5.0',
- version: '10.13.4',
- type: 'os',
- build: '17E199',
- name: 'Mac OS X',
- };
- const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
- expect(wrapper).toSnapshot();
- });
- it('renders the kernel version when no version', () => {
- const os = {
- kernel_version: '17.5.0',
- type: 'os',
- build: '17E199',
- name: 'Mac OS X',
- };
- const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
- expect(wrapper).toSnapshot();
- });
- it('renders unknown when no version', () => {
- const os = {
- type: 'os',
- build: '17E199',
- name: 'Mac OS X',
- };
- const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
- expect(wrapper).toSnapshot();
- });
- });
- });
- describe('GpuSummary', function () {
- describe('render()', function () {
- it('renders name and vendor', () => {
- const gpu = {
- name: 'Mali-T880',
- vendor_name: 'ARM',
- version: 'OpenGL ES 3.2 v1.r22p0-01rel0.f294e54ceb2cb2d81039204fa4b0402e',
- };
- const wrapper = mountWithTheme(<ContextSummaryGPU data={gpu} />);
- expect(wrapper).toSnapshot();
- });
- it('renders unknown when no vendor', () => {
- const gpu = {
- type: 'gpu',
- name: 'Apple A8 GPU',
- };
- const wrapper = mountWithTheme(<ContextSummaryGPU data={gpu} />);
- expect(wrapper).toSnapshot();
- });
- });
- });
- describe('UserSummary', function () {
- describe('render', function () {
- it('prefers email, then IP, then id, then username for title', function () {
- const user1 = {
- email: 'maisey@dogsrule.com',
- ip_address: '12.31.20.12',
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
- };
- const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
- expect(wrapper1.find('[data-test-id="user-title"]').render().text()).toEqual(
- user1.email
- );
- const user2 = {
- ip_address: '12.31.20.12',
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
- };
- const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
- expect(wrapper2.find('[data-test-id="user-title"]').render().text()).toEqual(
- user2.ip_address
- );
- const user3 = {
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
- };
- const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
- expect(wrapper3.find('[data-test-id="user-title"]').render().text()).toEqual(
- user3.id
- );
- const user4 = {
- username: 'maiseythedog',
- name: 'Maisey Dog',
- data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
- };
- const wrapper4 = mountWithTheme(<ContextSummaryUser data={user4} />);
- expect(wrapper4.find('[data-test-id="user-title"]').render().text()).toEqual(
- user4.username
- );
- });
- it('renders NoSummary if no email, IP, id, or username', function () {
- const user = {
- name: 'Maisey Dog',
- data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
- };
- const wrapper = mountWithTheme(<ContextSummaryUser data={user} />);
- expect(wrapper.find('[data-test-id="user-title"]')).toHaveLength(0);
- expect(wrapper.find('[data-test-id="no-summary-title"]').text()).toEqual(
- 'Unknown User'
- );
- });
- it('does not use filtered values for title', function () {
- const user1 = {
- email: FILTER_MASK,
- };
- const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
- expect(wrapper1.find('[data-test-id="user-title"]')).toHaveLength(0);
- expect(wrapper1.find('[data-test-id="no-summary-title"]').text()).toEqual(
- 'Unknown User'
- );
- // TODO: currently, the IP filter just eliminates IP addresses rather than
- // filtering them like other user data, so here, where you'd expect a filtered
- // IP address, there isn't one. Add a similar entry to the above and below
- // if/when that changes.
- const user2 = {
- id: FILTER_MASK,
- };
- const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
- expect(wrapper2.find('[data-test-id="user-title"]')).toHaveLength(0);
- expect(wrapper2.find('[data-test-id="no-summary-title"]').text()).toEqual(
- 'Unknown User'
- );
- const user3 = {
- username: FILTER_MASK,
- };
- const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
- expect(wrapper3.find('[data-test-id="user-title"]')).toHaveLength(0);
- expect(wrapper3.find('[data-test-id="no-summary-title"]').text()).toEqual(
- 'Unknown User'
- );
- });
- it('does not use filtered values for avatar', function () {
- // id is never used for avatar purposes, but is enough to keep us from
- // ending up with a NoSummary component where the UserSummary component
- // should be
- const user1 = {
- id: '26',
- name: FILTER_MASK,
- };
- const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
- expect(wrapper1.find('LetterAvatar').text()).toEqual('?');
- const user2 = {
- id: '26',
- email: FILTER_MASK,
- };
- const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
- expect(wrapper2.find('LetterAvatar').text()).toEqual('?');
- const user3 = {
- id: '26',
- username: FILTER_MASK,
- };
- const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
- expect(wrapper3.find('LetterAvatar').text()).toEqual('?');
- });
- });
- });
|