Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {EventFixture} from 'sentry-fixture/event';

import {render, screen} from 'sentry-test/reactTestingLibrary';

import {ContextCard} from 'sentry/components/events/contexts/contextCard';
import {
getAccessibilityContextData,
type AccessibilityContext,
} from 'sentry/components/events/contexts/knownContext/accessibility';

const MOCK_ACCESSIBILITY_CONTEXT: AccessibilityContext = {
accessible_navigation: false,
bold_text: false,
disable_animations: true,
high_contrast: false,
invert_colors: false,
reduce_motion: false,
// Extra data is still valid and preserved
extra_data: 'something',
unknown_key: 123,
};

const MOCK_REDACTION = {
reduce_motion: {
'': {
rem: [['organization:0', 's', 0, 0]],
len: 5,
},
},
};

describe('AccessibilityContext', () => {
it('returns values according to the parameters', () => {
expect(getAccessibilityContextData({data: MOCK_ACCESSIBILITY_CONTEXT})).toEqual([
{
key: 'accessible_navigation',
subject: 'Accessible Navigation',
value: false,
},
{key: 'bold_text', subject: 'Bold Text', value: false},
{key: 'disable_animations', subject: 'Disable Animations', value: true},
{key: 'high_contrast', subject: 'High Contrast', value: false},
{key: 'invert_colors', subject: 'Invert Colors', value: false},
{key: 'reduce_motion', subject: 'Reduce Motion', value: false},
{
key: 'extra_data',
subject: 'extra_data',
value: 'something',
meta: undefined,
},
{
key: 'unknown_key',
subject: 'unknown_key',
value: 123,
meta: undefined,
},
]);
});

it('renders with meta annotations correctly', () => {
const event = EventFixture({
_meta: {contexts: {accessibility: MOCK_REDACTION}},
});

render(
<ContextCard
event={event}
type="accessibility"
alias="accessibility"
value={{...MOCK_ACCESSIBILITY_CONTEXT, reduce_motion: ''}}
/>
);

expect(screen.getByText('Accessibility')).toBeInTheDocument();
expect(screen.getByText('Disable Animations')).toBeInTheDocument();
expect(screen.getByText('Reduce Motion')).toBeInTheDocument();
expect(screen.getByText(/redacted/)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {getContextKeys} from 'sentry/components/events/contexts/utils';
import {t} from 'sentry/locale';
import type {KeyValueListData} from 'sentry/types/group';

enum AccessibilityContextKeys {
ACCESSIBLE_NAVIGATION = 'accessible_navigation',
BOLD_TEXT = 'bold_text',
DISABLE_ANIMATIONS = 'disable_animations',
HIGH_CONTRAST = 'high_contrast',
INVERT_COLORS = 'invert_colors',
REDUCE_MOTION = 'reduce_motion',
}

export interface AccessibilityContext {
[key: string]: any;
[AccessibilityContextKeys.ACCESSIBLE_NAVIGATION]?: boolean;
[AccessibilityContextKeys.BOLD_TEXT]?: boolean;
[AccessibilityContextKeys.DISABLE_ANIMATIONS]?: boolean;
[AccessibilityContextKeys.HIGH_CONTRAST]?: boolean;
[AccessibilityContextKeys.INVERT_COLORS]?: boolean;
[AccessibilityContextKeys.REDUCE_MOTION]?: boolean;
}

export function getAccessibilityContextData({
data,
meta,
}: {
data: AccessibilityContext;
meta?: Record<keyof AccessibilityContext, any>;
}): KeyValueListData {
return getContextKeys({data}).map(ctxKey => {
switch (ctxKey) {
case AccessibilityContextKeys.ACCESSIBLE_NAVIGATION:
return {
key: ctxKey,
subject: t('Accessible Navigation'),
value: data.accessible_navigation,
};
case AccessibilityContextKeys.BOLD_TEXT:
return {
key: ctxKey,
subject: t('Bold Text'),
value: data.bold_text,
};
case AccessibilityContextKeys.DISABLE_ANIMATIONS:
return {
key: ctxKey,
subject: t('Disable Animations'),
value: data.disable_animations,
};
case AccessibilityContextKeys.HIGH_CONTRAST:
return {
key: ctxKey,
subject: t('High Contrast'),
value: data.high_contrast,
};
case AccessibilityContextKeys.INVERT_COLORS:
return {
key: ctxKey,
subject: t('Invert Colors'),
value: data.invert_colors,
};
case AccessibilityContextKeys.REDUCE_MOTION:
return {
key: ctxKey,
subject: t('Reduce Motion'),
value: data.reduce_motion,
};
default:
return {
key: ctxKey,
subject: ctxKey,
value: data[ctxKey],
meta: meta?.[ctxKey]?.[''],
};
}
});
}
16 changes: 16 additions & 0 deletions static/app/components/events/contexts/knownContext/app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const MOCK_APP_CONTEXT: AppContext = {
is_active: false,
app_memory: 1048576 * 12,
view_names: ['app.view1', 'app.view2'],
is_split_apks: false,
permissions: {
ACCESS_NETWORK_STATE: 'granted',
CAMERA: 'not_granted',
INTERNET: 'granted',
},
// Extra data is still valid and preserved
extra_data: 'something',
unknown_key: 123,
Expand Down Expand Up @@ -73,6 +79,16 @@ describe('AppContext', () => {
subject: 'View Names',
value: ['app.view1', 'app.view2'],
},
{key: 'is_split_apks', subject: 'Split APKs', value: false},
{
key: 'permissions',
subject: 'Permissions',
value: {
ACCESS_NETWORK_STATE: 'granted',
CAMERA: 'not_granted',
INTERNET: 'granted',
},
},
{
key: 'extra_data',
subject: 'extra_data',
Expand Down
16 changes: 16 additions & 0 deletions static/app/components/events/contexts/knownContext/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ enum AppContextKeys {
// XXX: From https://github.com/getsentry/sentry/issues/87238, not in the schema yet.
FREE_MEMORY = 'free_memory',
ARCHITECTURE = 'app_arch',
IS_SPLIT_APKS = 'is_split_apks',
PERMISSIONS = 'permissions',
}

export interface AppContext {
Expand All @@ -43,6 +45,8 @@ export interface AppContext {
[AppContextKeys.VIEW_NAMES]?: string[];
[AppContextKeys.FREE_MEMORY]?: number;
[AppContextKeys.ARCHITECTURE]?: string;
[AppContextKeys.IS_SPLIT_APKS]?: boolean;
[AppContextKeys.PERMISSIONS]?: Record<string, string>;
}

// https://github.com/getsentry/relay/blob/24.10.0/relay-event-schema/src/protocol/contexts/app.rs#L37
Expand Down Expand Up @@ -151,6 +155,18 @@ export function getAppContextData({
subject: t('Architecture'),
value: data.app_arch,
};
case AppContextKeys.IS_SPLIT_APKS:
return {
key: ctxKey,
subject: t('Split APKs'),
value: data.is_split_apks,
};
case AppContextKeys.PERMISSIONS:
return {
key: ctxKey,
subject: t('Permissions'),
value: data.permissions,
};
default:
return {
key: ctxKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {EventFixture} from 'sentry-fixture/event';

import {render, screen} from 'sentry-test/reactTestingLibrary';

import {ContextCard} from 'sentry/components/events/contexts/contextCard';
import {
getDartContextData,
type DartContext,
} from 'sentry/components/events/contexts/knownContext/dartContext';

const MOCK_DART_CONTEXT: DartContext = {
compile_mode: 'debug',
executable: 'flutter',
resolved_executable: '/system/bin/app_process64',
script: 'file:///main.dart',
// Extra data is still valid and preserved
extra_data: 'something',
unknown_key: 123,
};

const MOCK_REDACTION = {
script: {
'': {
rem: [['organization:0', 's', 0, 0]],
len: 20,
},
},
};

describe('DartContext', () => {
it('returns values according to the parameters', () => {
expect(getDartContextData({data: MOCK_DART_CONTEXT})).toEqual([
{key: 'compile_mode', subject: 'Compile Mode', value: 'debug'},
{key: 'executable', subject: 'Executable', value: 'flutter'},
{
key: 'resolved_executable',
subject: 'Resolved Executable',
value: '/system/bin/app_process64',
},
{key: 'script', subject: 'Script', value: 'file:///main.dart'},
{
key: 'extra_data',
subject: 'extra_data',
value: 'something',
meta: undefined,
},
{
key: 'unknown_key',
subject: 'unknown_key',
value: 123,
meta: undefined,
},
]);
});

it('renders with meta annotations correctly', () => {
const event = EventFixture({
_meta: {contexts: {dart_context: MOCK_REDACTION}},
});

render(
<ContextCard
event={event}
type="dart_context"
alias="dart_context"
value={{...MOCK_DART_CONTEXT, script: ''}}
/>
);

expect(screen.getByText('Dart')).toBeInTheDocument();
expect(screen.getByText('Compile Mode')).toBeInTheDocument();
expect(screen.getByText('debug')).toBeInTheDocument();
expect(screen.getByText('Script')).toBeInTheDocument();
expect(screen.getByText(/redacted/)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {getContextKeys} from 'sentry/components/events/contexts/utils';
import {t} from 'sentry/locale';
import type {KeyValueListData} from 'sentry/types/group';

enum DartContextKeys {
COMPILE_MODE = 'compile_mode',
EXECUTABLE = 'executable',
RESOLVED_EXECUTABLE = 'resolved_executable',
SCRIPT = 'script',
}

export interface DartContext {
[key: string]: any;
[DartContextKeys.COMPILE_MODE]?: string;
[DartContextKeys.EXECUTABLE]?: string;
[DartContextKeys.RESOLVED_EXECUTABLE]?: string;
[DartContextKeys.SCRIPT]?: string;
}

export function getDartContextData({
data,
meta,
}: {
data: DartContext;
meta?: Record<keyof DartContext, any>;
}): KeyValueListData {
return getContextKeys({data}).map(ctxKey => {
switch (ctxKey) {
case DartContextKeys.COMPILE_MODE:
return {
key: ctxKey,
subject: t('Compile Mode'),
value: data.compile_mode,
};
case DartContextKeys.EXECUTABLE:
return {
key: ctxKey,
subject: t('Executable'),
value: data.executable,
};
case DartContextKeys.RESOLVED_EXECUTABLE:
return {
key: ctxKey,
subject: t('Resolved Executable'),
value: data.resolved_executable,
};
case DartContextKeys.SCRIPT:
return {
key: ctxKey,
subject: t('Script'),
value: data.script,
};
default:
return {
key: ctxKey,
subject: ctxKey,
value: data[ctxKey],
meta: meta?.[ctxKey]?.[''],
};
}
});
}
Loading
Loading