-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(app-starts): Generalize screen table component (#69839)
This component can be reused in the other mobile modules, generalize the screen table so we can pass in custom header name maps and body cell renderers.
- Loading branch information
1 parent
9fb3a8b
commit 0d46223
Showing
5 changed files
with
343 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
static/app/views/performance/mobile/appStarts/screens/screensTable.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import EventView from 'sentry/utils/discover/eventView'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {AppStartScreens} from 'sentry/views/performance/mobile/appStarts/screens/screensTable'; | ||
import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases'; | ||
|
||
jest.mock('sentry/views/starfish/queries/useReleases'); | ||
|
||
jest.mocked(useReleaseSelection).mockReturnValue({ | ||
primaryRelease: 'com.example.vu.android@2.10.5', | ||
isLoading: false, | ||
secondaryRelease: 'com.example.vu.android@2.10.3+42', | ||
}); | ||
|
||
function getMockEventView({fields}) { | ||
return new EventView({ | ||
id: '1', | ||
name: 'mock query', | ||
fields, | ||
|
||
sorts: [], | ||
query: '', | ||
project: [], | ||
start: '2019-10-01T00:00:00', | ||
end: '2019-10-02T00:00:00', | ||
statsPeriod: '14d', | ||
environment: [], | ||
additionalConditions: new MutableSearch(''), | ||
createdBy: undefined, | ||
interval: undefined, | ||
display: '', | ||
team: [], | ||
topEvents: undefined, | ||
yAxis: undefined, | ||
}); | ||
} | ||
|
||
describe('AppStartScreens', () => { | ||
it('renders the correct headers', () => { | ||
render( | ||
<AppStartScreens | ||
data={{ | ||
data: [], | ||
meta: { | ||
fields: [], | ||
}, | ||
}} | ||
eventView={getMockEventView({fields: []})} | ||
isLoading={false} | ||
pageLinks={undefined} | ||
/> | ||
); | ||
|
||
expect(screen.getByRole('columnheader', {name: 'Screen'})).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole('columnheader', {name: 'Cold Start (R1)'}) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole('columnheader', {name: 'Cold Start (R2)'}) | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole('columnheader', {name: 'Change'})).toBeInTheDocument(); | ||
expect( | ||
screen.getByRole('columnheader', {name: 'Type Breakdown'}) | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole('columnheader', {name: 'Count'})).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders custom transaction and breakdown fields', () => { | ||
render( | ||
<AppStartScreens | ||
data={{ | ||
data: [ | ||
{ | ||
id: '1', | ||
transaction: 'Screen 1', | ||
'avg_if(measurements.app_start_cold,release,com.example.vu.android@2.10.5)': 100, | ||
'avg_if(measurements.app_start_cold,release,com.example.vu.android@2.10.3+42)': 200, | ||
'avg_compare(measurements.app_start_cold,release,com.example.vu.android@2.10.5,com.example.vu.android@2.10.3+42)': 50, | ||
app_start_breakdown: 'breakdown', | ||
'count_starts(measurements.app_start_cold)': 10, | ||
}, | ||
], | ||
meta: { | ||
fields: [], | ||
}, | ||
}} | ||
eventView={getMockEventView({fields: []})} | ||
isLoading={false} | ||
pageLinks={undefined} | ||
/> | ||
); | ||
|
||
expect(screen.getByRole('link', {name: 'Screen 1'})).toBeInTheDocument(); | ||
expect(screen.getByTestId('app-start-breakdown')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
static/app/views/performance/mobile/components/screensTable.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import EventView from 'sentry/utils/discover/eventView'; | ||
import {MutableSearch} from 'sentry/utils/tokenizeSearch'; | ||
import {ScreensTable} from 'sentry/views/performance/mobile/components/screensTable'; | ||
|
||
function getMockEventView({fields}) { | ||
return new EventView({ | ||
id: '1', | ||
name: 'mock query', | ||
fields, | ||
|
||
sorts: [], | ||
query: '', | ||
project: [], | ||
start: '2019-10-01T00:00:00', | ||
end: '2019-10-02T00:00:00', | ||
statsPeriod: '14d', | ||
environment: [], | ||
additionalConditions: new MutableSearch(''), | ||
createdBy: undefined, | ||
interval: undefined, | ||
display: '', | ||
team: [], | ||
topEvents: undefined, | ||
yAxis: undefined, | ||
}); | ||
} | ||
|
||
describe('ScreensTable', () => { | ||
it('renders table header cells with translated names', () => { | ||
render( | ||
<ScreensTable | ||
columnNameMap={{ | ||
transaction: 'Screen', | ||
}} | ||
columnOrder={['transaction']} | ||
data={{ | ||
data: [{id: '1', transaction: 'Screen 1'}], | ||
meta: {}, | ||
}} | ||
defaultSort={[]} | ||
eventView={getMockEventView({fields: [{field: 'transaction'}]})} | ||
isLoading={false} | ||
pageLinks={undefined} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Screen')).toBeInTheDocument(); | ||
expect(screen.queryByText('transaction')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('renders body cells with custom renderer if applicable', () => { | ||
render( | ||
<ScreensTable | ||
columnNameMap={{ | ||
transaction: 'Screen', | ||
}} | ||
columnOrder={['transaction', 'non-custom']} | ||
data={{ | ||
data: [ | ||
{id: '1', transaction: 'Screen 1', 'non-custom': 'non customized value'}, | ||
], | ||
meta: {fields: {transaction: 'string'}}, | ||
}} | ||
defaultSort={[]} | ||
eventView={getMockEventView({ | ||
fields: [{field: 'transaction'}, {field: 'non-custom'}], | ||
})} | ||
isLoading={false} | ||
pageLinks={undefined} | ||
customBodyCellRenderer={(column, row) => { | ||
if (column.key === 'transaction') { | ||
return `Custom rendered ${row.transaction}`; | ||
} | ||
|
||
return null; | ||
}} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Custom rendered Screen 1')).toBeInTheDocument(); | ||
expect(screen.getByText('non customized value')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.