123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- 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', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- contexts: {},
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('renders nothing with a single user context', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {},
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('should bail out with empty contexts', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- device: {},
- os: {},
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('renders at least three contexts', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- device: CONTEXT_DEVICE,
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('renders up to four contexts', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- os: CONTEXT_OS,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE, // must be omitted
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('should prefer client_os over os', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- client_os: CONTEXT_OS,
- os: CONTEXT_OS_SERVER,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('renders client_os too', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- client_os: CONTEXT_OS,
- browser: CONTEXT_BROWSER,
- runtime: CONTEXT_RUNTIME,
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('should skip non-default named contexts', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- user: CONTEXT_USER,
- contexts: {
- os: CONTEXT_OS,
- chrome: CONTEXT_BROWSER, // non-standard context
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE,
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- it('should skip a missing user context', function () {
- const event = {
- ...TestStubs.Event(),
- id: '',
- contexts: {
- os: CONTEXT_OS,
- chrome: CONTEXT_BROWSER, // non-standard context
- runtime: CONTEXT_RUNTIME,
- device: CONTEXT_DEVICE,
- },
- };
- const {container} = render(<ContextSummary event={event} />);
- expect(container).toSnapshot();
- });
- });
- });
- describe('OsSummary', function () {
- describe('render()', function () {
- it('renders the version string', function () {
- const {container} = render(
- <ContextSummaryOS
- data={{
- kernel_version: '17.5.0',
- version: '10.13.4',
- name: 'Mac OS X',
- }}
- meta={{}}
- />
- );
- expect(container).toSnapshot();
- });
- it('renders the kernel version when no version', function () {
- const {container} = render(
- <ContextSummaryOS
- data={{
- kernel_version: '17.5.0',
- name: 'Mac OS X',
- }}
- meta={{}}
- />
- );
- expect(container).toSnapshot();
- });
- it('renders unknown when no version', function () {
- const {container} = render(
- <ContextSummaryOS
- data={{
- name: 'Mac OS X',
- }}
- meta={{}}
- />
- );
- expect(container).toSnapshot();
- });
- it('display redacted name', async function () {
- render(
- <ContextSummaryOS
- data={{
- name: '',
- version: '10',
- }}
- meta={{
- name: {
- '': {
- rem: [['project:0', 's', 0, 0]],
- len: 19,
- },
- },
- }}
- />
- );
- userEvent.hover(screen.getByText(/redacted/));
- expect(
- await screen.findByText('Replaced because of PII rule "project:0"')
- ).toBeInTheDocument(); // tooltip description
- });
- it('handles invalid data', async function () {
- render(
- <ContextSummaryOS
- data={{
- name: false,
- version: false,
- }}
- meta={{
- name: {
- '': {
- rem: [['project:0', 's', 0, 0]],
- len: 19,
- },
- },
- }}
- />
- );
- userEvent.hover(screen.getByText(/redacted/));
- expect(
- await screen.findByText('Replaced because of PII rule "project:0"')
- ).toBeInTheDocument(); // tooltip description
- });
- });
- });
- describe('GpuSummary', function () {
- describe('render()', function () {
- it('renders name and vendor', function () {
- const {container} = render(
- <ContextSummaryGPU
- data={{
- name: 'Mali-T880',
- vendor_name: 'ARM',
- }}
- meta={{}}
- />
- );
- expect(container).toSnapshot();
- });
- it('renders unknown when no vendor', function () {
- const {container} = render(
- <ContextSummaryGPU
- data={{
- name: 'Apple A8 GPU',
- }}
- meta={{}}
- />
- );
- expect(container).toSnapshot();
- });
- it('display redacted name', async function () {
- render(
- <ContextSummaryGPU
- data={{
- name: '',
- }}
- meta={{
- name: {
- '': {
- rem: [['project:0', 's', 0, 0]],
- len: 19,
- },
- },
- }}
- />
- );
- userEvent.hover(screen.getByText(/redacted/));
- expect(
- await screen.findByText('Replaced because of PII rule "project:0"')
- ).toBeInTheDocument(); // tooltip description
- });
- });
- });
- 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',
- };
- const {rerender} = render(<ContextSummaryUser data={user1} meta={{}} />);
- expect(screen.getByText(user1.email)).toBeInTheDocument();
- const user2 = {
- ip_address: '12.31.20.12',
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- };
- rerender(<ContextSummaryUser data={user2} meta={{}} />);
- expect(screen.getByTestId('user-title')?.textContent).toEqual(user2.ip_address);
- const user3 = {
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- };
- rerender(
- <ContextSummaryUser
- data={{
- id: '26',
- username: 'maiseythedog',
- name: 'Maisey Dog',
- }}
- meta={{}}
- />
- );
- expect(screen.getByTestId('user-title')?.textContent).toEqual(user3.id);
- const user4 = {
- username: 'maiseythedog',
- name: 'Maisey Dog',
- };
- rerender(<ContextSummaryUser data={user4} meta={{}} />);
- expect(screen.getByTestId('user-title')).toHaveTextContent(user4.username);
- });
- it('renders NoSummary if no email, IP, id, or username', function () {
- render(
- <ContextSummaryUser
- data={{
- name: 'Maisey Dog',
- }}
- meta={{}}
- />
- );
- expect(screen.queryByTestId('user-title')).not.toBeInTheDocument();
- expect(screen.getByTestId('no-summary-title')).toHaveTextContent('Unknown User');
- });
- it('does not use filtered values for title', function () {
- const {rerender} = render(
- <ContextSummaryUser
- data={{
- email: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.queryByTestId('user-title')).not.toBeInTheDocument();
- expect(screen.getByTestId('no-summary-title')).toHaveTextContent('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.
- rerender(
- <ContextSummaryUser
- data={{
- id: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.queryByTestId('user-title')).not.toBeInTheDocument();
- expect(screen.getByTestId('no-summary-title')).toHaveTextContent('Unknown User');
- rerender(
- <ContextSummaryUser
- data={{
- username: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.queryByTestId('user-title')).not.toBeInTheDocument();
- expect(screen.getByTestId('no-summary-title')).toHaveTextContent('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 {rerender} = render(
- <ContextSummaryUser
- data={{
- id: '26',
- name: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.getByText('?')).toBeInTheDocument();
- rerender(
- <ContextSummaryUser
- data={{
- id: '26',
- email: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.getByText('?')).toBeInTheDocument();
- rerender(
- <ContextSummaryUser
- data={{
- id: '26',
- username: FILTER_MASK,
- }}
- meta={{}}
- />
- );
- expect(screen.getByText('?')).toBeInTheDocument();
- });
- it('display redacted email', async function () {
- render(
- <ContextSummaryUser
- data={{
- name: 'Maisey Dog',
- email: '',
- }}
- meta={{
- email: {
- '': {
- rem: [['project:0', 's', 0, 0]],
- len: 19,
- },
- },
- }}
- />
- );
- userEvent.hover(screen.getByText(/redacted/));
- expect(
- await screen.findByText('Replaced because of PII rule "project:0"')
- ).toBeInTheDocument(); // tooltip description
- });
- });
- });
|