Sentry plugin refactoring - code review changes

This commit is contained in:
Wojciech Adaszynski
2020-05-20 09:57:32 +02:00
parent 0783e07290
commit baf8188db7
17 changed files with 73 additions and 85 deletions
@@ -39,12 +39,12 @@ describe('SentryIssuesTable', () => {
<SentryIssuesTable sentryIssues={issues} />
</ThemeProvider>,
);
expect(await table.findByText('Error')).toBeInTheDOM();
expect(await table.findByText('Graph')).toBeInTheDOM();
expect(await table.findByText('First seen')).toBeInTheDOM();
expect(await table.findByText('Last seen')).toBeInTheDOM();
expect(await table.findByText('Events')).toBeInTheDOM();
expect(await table.findByText('Users')).toBeInTheDOM();
expect(await table.findByText('Error')).toBeInTheDocument();
expect(await table.findByText('Graph')).toBeInTheDocument();
expect(await table.findByText('First seen')).toBeInTheDocument();
expect(await table.findByText('Last seen')).toBeInTheDocument();
expect(await table.findByText('Events')).toBeInTheDocument();
expect(await table.findByText('Users')).toBeInTheDocument();
});
it('should render values in a table', async () => {
const issues: SentryIssue[] = [
@@ -63,9 +63,9 @@ describe('SentryIssuesTable', () => {
<SentryIssuesTable sentryIssues={issues} />
</ThemeProvider>,
);
expect(await table.findByText('Exception')).toBeInTheDOM();
expect(await table.findByText('exception was thrown')).toBeInTheDOM();
expect(await table.findByText('101')).toBeInTheDOM();
expect(await table.findByText('202')).toBeInTheDOM();
expect(await table.findByText('Exception')).toBeInTheDocument();
expect(await table.findByText('exception was thrown')).toBeInTheDocument();
expect(await table.findByText('101')).toBeInTheDocument();
expect(await table.findByText('202')).toBeInTheDocument();
});
});
@@ -26,7 +26,7 @@ const errorApi = { post: () => {} };
describe('SentryPluginPage', () => {
it('should render header and time switched', () => {
mockFetch.mockResponse(() => new Promise(() => {}));
mockFetch.mockResponse('{}');
const rendered = render(
<ApiProvider apis={ApiRegistry.from([[errorApiRef, errorApi]])}>
<ThemeProvider theme={lightTheme}>
@@ -24,13 +24,13 @@ import {
ContentHeader,
SupportButton,
} from '@backstage/core';
import SentryPluginWidget from '../SentryPluginWidget/SentryPluginWidget';
import { SentryPluginWidget } from '../SentryPluginWidget/SentryPluginWidget';
import { ToggleButton, ToggleButtonGroup } from '@material-ui/lab';
const SentryPluginPage: FC<{}> = () => {
const [statsFor, setStatsFor] = useState<'12h' | '24h'>('12h');
const toggleStatsFor = () =>
statsFor === '12h' ? setStatsFor('24h') : setStatsFor('12h');
const toggleStatsFor = () => setStatsFor(statsFor === '12h' ? '12h' : '24h');
return (
<Page theme={pageTheme.tool}>
<Header title="Welcome to Sentry Plugin!">
@@ -28,7 +28,7 @@ import { sentryApiFactory } from '../../data/api-factory';
const api = sentryApiFactory('spotify');
const SentryPluginWidget: FC<{
export const SentryPluginWidget: FC<{
sentryProjectId: string;
statsFor: '24h' | '12h';
}> = ({ sentryProjectId, statsFor }) => {
@@ -55,5 +55,3 @@ const SentryPluginWidget: FC<{
return <SentryIssuesTable sentryIssues={value || []} />;
};
export default SentryPluginWidget;
+2 -1
View File
@@ -16,7 +16,8 @@
import { SentryIssue } from './sentry-issue';
import { SentryApi } from './sentry-api';
const API_BASE_URL = 'http://localhost:7000/sentry/api/0/projects/';
const API_HOST = process.env.API_HOST || 'http://localhost:7000';
const API_BASE_URL = `${API_HOST}/sentry/api/0/projects/`;
export class ProductionSentryApi implements SentryApi {
private organization: string;
+1 -1
View File
@@ -15,4 +15,4 @@
*/
export { plugin } from './plugin';
export { default as SentryIssuesWidget } from './components/SentryPluginWidget/SentryPluginWidget';
export { SentryPluginWidget as SentryIssuesWidget } from './components/SentryPluginWidget/SentryPluginWidget';
+1 -1
View File
@@ -14,5 +14,5 @@
* limitations under the License.
*/
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';
require('jest-fetch-mock').enableMocks();