import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen} from 'sentry-test/reactTestingLibrary';
import {PageFilters} from 'sentry/types';
import {ReleasesProvider, useReleases} from 'sentry/utils/releases/releasesProvider';
function TestComponent({other}: {other: string}) {
const {releases, loading} = useReleases();
return (
{other}
{releases &&
releases.map(release => {release.version})}
{`loading: ${loading}`}
);
}
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: [
TestStubs.Release({
shortVersion: 'sentry-android-shop@1.2.0',
version: 'sentry-android-shop@1.2.0',
}),
TestStubs.Release({
shortVersion: 'sentry-android-shop@1.3.0',
version: 'sentry-android-shop@1.3.0',
}),
TestStubs.Release({
shortVersion: 'sentry-android-shop@1.4.0',
version: 'sentry-android-shop@1.4.0',
}),
],
});
render(
);
// Should forward prop
expect(screen.getByText('value')).toBeInTheDocument();
expect(mockReleases).toHaveBeenCalledTimes(1);
expect(await screen.findByText('loading: false')).toBeInTheDocument();
expect(screen.getByText('sentry-android-shop@1.2.0')).toBeInTheDocument();
expect(screen.getByText('sentry-android-shop@1.3.0')).toBeInTheDocument();
});
});