mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-10-30 14:49:14 +00:00
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import {ReleaseFixture} from 'sentry-fixture/release';
|
|
|
|
import {initializeOrg} from 'sentry-test/initializeOrg';
|
|
import {render, screen} from 'sentry-test/reactTestingLibrary';
|
|
|
|
import type {PageFilters} from 'sentry/types';
|
|
import {ReleasesProvider, useReleases} from 'sentry/utils/releases/releasesProvider';
|
|
|
|
function TestComponent({other}: {other: string}) {
|
|
const {releases, loading} = useReleases();
|
|
return (
|
|
<div>
|
|
<span>{other}</span>
|
|
{releases?.map(release => (
|
|
<em key={release.version}>{release.version}</em>
|
|
))}
|
|
{`loading: ${loading}`}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
describe('useReleases', function () {
|
|
const {organization} = initializeOrg();
|
|
const selection = {
|
|
projects: [1],
|
|
environments: ['prod'],
|
|
datetime: {
|
|
period: '14d',
|
|
start: null,
|
|
end: null,
|
|
utc: false,
|
|
},
|
|
} as PageFilters;
|
|
|
|
it("fetches releases and save values in the context's state", async function () {
|
|
const mockReleases = MockApiClient.addMockResponse({
|
|
url: '/organizations/org-slug/releases/',
|
|
body: [
|
|
ReleaseFixture({
|
|
shortVersion: '[email protected]',
|
|
version: '[email protected]',
|
|
}),
|
|
ReleaseFixture({
|
|
shortVersion: '[email protected]',
|
|
version: '[email protected]',
|
|
}),
|
|
ReleaseFixture({
|
|
shortVersion: '[email protected]',
|
|
version: '[email protected]',
|
|
}),
|
|
],
|
|
});
|
|
|
|
render(
|
|
<ReleasesProvider organization={organization} selection={selection}>
|
|
<TestComponent other="value" />
|
|
</ReleasesProvider>
|
|
);
|
|
|
|
// Should forward prop
|
|
expect(screen.getByText('value')).toBeInTheDocument();
|
|
|
|
expect(mockReleases).toHaveBeenCalledTimes(1);
|
|
|
|
expect(await screen.findByText('loading: false')).toBeInTheDocument();
|
|
expect(screen.getByText('[email protected]')).toBeInTheDocument();
|
|
expect(screen.getByText('[email protected]')).toBeInTheDocument();
|
|
});
|
|
});
|