123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import {render, waitFor} from 'sentry-test/reactTestingLibrary';
- import ReleaseStore from 'sentry/stores/releaseStore';
- import withRelease from 'sentry/utils/withRelease';
- describe('withRelease HoC', function () {
- const organization = TestStubs.Organization();
- const orgSlug = organization.slug;
- const projectSlug = 'myProject';
- const releaseVersion = 'myRelease';
- const releaseUrl = `/projects/${orgSlug}/${projectSlug}/releases/${encodeURIComponent(
- releaseVersion
- )}/`;
- const deployUrl = `/organizations/${orgSlug}/releases/${encodeURIComponent(
- releaseVersion
- )}/deploys/`;
- const api = new MockApiClient();
- const mockData = {id: '1'};
- beforeEach(() => {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: releaseUrl,
- body: mockData,
- });
- MockApiClient.addMockResponse({
- url: deployUrl,
- body: [mockData],
- });
- jest.restoreAllMocks();
- ReleaseStore.reset();
- });
- it('adds release/deploys prop', async function () {
- const Component = jest.fn(() => null);
- const Container = withRelease(Component);
- render(
- <Container
- api={api}
- organization={organization}
- projectSlug={projectSlug}
- releaseVersion={releaseVersion}
- />
- );
- await waitFor(() =>
- expect(Component).toHaveBeenCalledWith(
- expect.objectContaining({
- release: mockData,
- releaseLoading: false,
- releaseError: undefined,
- deploys: [mockData],
- deploysLoading: false,
- deploysError: undefined,
- }),
- {}
- )
- );
- });
- it('prevents repeated calls', function () {
- const Component = jest.fn(() => null);
- const Container = withRelease(Component);
- jest.spyOn(api, 'requestPromise');
- jest.spyOn(Container.prototype, 'fetchRelease');
- jest.spyOn(Container.prototype, 'fetchDeploys');
- // Mount and run component
- render(
- <Container
- api={api}
- organization={organization}
- projectSlug={projectSlug}
- releaseVersion={releaseVersion}
- />
- );
- // Mount and run duplicates
- render(
- <Container
- api={api}
- organization={organization}
- projectSlug={projectSlug}
- releaseVersion={releaseVersion}
- />
- );
- render(
- <Container
- api={api}
- organization={organization}
- projectSlug={projectSlug}
- releaseVersion={releaseVersion}
- />
- );
- expect(api.requestPromise).toHaveBeenCalledTimes(2); // 1 for fetchRelease, 1 for fetchDeploys
- expect(Container.prototype.fetchRelease).toHaveBeenCalledTimes(3);
- expect(Container.prototype.fetchDeploys).toHaveBeenCalledTimes(3);
- });
- });
|