|
@@ -7,12 +7,16 @@ import {
|
|
|
waitFor,
|
|
|
} from 'sentry-test/reactTestingLibrary';
|
|
|
|
|
|
+import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
|
|
|
+import {tct} from 'sentry/locale';
|
|
|
import OrganizationStore from 'sentry/stores/organizationStore';
|
|
|
import TeamStore from 'sentry/stores/teamStore';
|
|
|
import {Organization} from 'sentry/types';
|
|
|
import * as useExperiment from 'sentry/utils/useExperiment';
|
|
|
import {CreateProject} from 'sentry/views/projectInstall/createProject';
|
|
|
|
|
|
+jest.mock('sentry/actionCreators/indicator');
|
|
|
+
|
|
|
function renderFrameworkModalMockRequests({
|
|
|
organization,
|
|
|
teamSlug,
|
|
@@ -43,9 +47,16 @@ function renderFrameworkModalMockRequests({
|
|
|
const projectCreationMockRequest = MockApiClient.addMockResponse({
|
|
|
url: `/teams/${organization.slug}/${teamSlug}/projects/`,
|
|
|
method: 'POST',
|
|
|
+ body: {slug: 'testProj'},
|
|
|
});
|
|
|
|
|
|
- return {projectCreationMockRequest};
|
|
|
+ const experimentalprojectCreationMockRequest = MockApiClient.addMockResponse({
|
|
|
+ url: `/organizations/${organization.slug}/experimental/projects/`,
|
|
|
+ method: 'POST',
|
|
|
+ body: {slug: 'testProj', team_slug: 'testTeam'},
|
|
|
+ });
|
|
|
+
|
|
|
+ return {projectCreationMockRequest, experimentalprojectCreationMockRequest};
|
|
|
}
|
|
|
|
|
|
describe('CreateProject', function () {
|
|
@@ -267,6 +278,116 @@ describe('CreateProject', function () {
|
|
|
expect(container).toSnapshot();
|
|
|
});
|
|
|
|
|
|
+ it('should display success message on proj creation', async function () {
|
|
|
+ const {organization} = initializeOrg({
|
|
|
+ organization: {
|
|
|
+ access: ['project:read'],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const frameWorkModalMockRequests = renderFrameworkModalMockRequests({
|
|
|
+ organization,
|
|
|
+ teamSlug: teamWithAccess.slug,
|
|
|
+ });
|
|
|
+ TeamStore.loadUserTeams([teamWithAccess]);
|
|
|
+
|
|
|
+ render(<CreateProject />, {
|
|
|
+ organization,
|
|
|
+ });
|
|
|
+
|
|
|
+ renderGlobalModal();
|
|
|
+ await userEvent.click(screen.getByTestId('platform-apple-ios'));
|
|
|
+ await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
|
|
|
+
|
|
|
+ expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes(
|
|
|
+ 1
|
|
|
+ );
|
|
|
+ expect(addSuccessMessage).toHaveBeenCalledWith(
|
|
|
+ tct('Created project [project]', {
|
|
|
+ project: 'testProj',
|
|
|
+ })
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should display error message on proj creation failure', async function () {
|
|
|
+ const {organization} = initializeOrg({
|
|
|
+ organization: {
|
|
|
+ access: ['project:read'],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const frameWorkModalMockRequests = renderFrameworkModalMockRequests({
|
|
|
+ organization,
|
|
|
+ teamSlug: teamWithAccess.slug,
|
|
|
+ });
|
|
|
+ frameWorkModalMockRequests.projectCreationMockRequest = MockApiClient.addMockResponse(
|
|
|
+ {
|
|
|
+ url: `/teams/${organization.slug}/${teamWithAccess.slug}/projects/`,
|
|
|
+ method: 'POST',
|
|
|
+ body: {slug: 'testProj'},
|
|
|
+ statusCode: 404,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ TeamStore.loadUserTeams([teamWithAccess]);
|
|
|
+
|
|
|
+ render(<CreateProject />, {
|
|
|
+ organization,
|
|
|
+ });
|
|
|
+
|
|
|
+ renderGlobalModal();
|
|
|
+ await userEvent.click(screen.getByTestId('platform-apple-ios'));
|
|
|
+ await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
|
|
|
+
|
|
|
+ expect(frameWorkModalMockRequests.projectCreationMockRequest).toHaveBeenCalledTimes(
|
|
|
+ 1
|
|
|
+ );
|
|
|
+ expect(addErrorMessage).toHaveBeenCalledWith(
|
|
|
+ tct('Failed to create project [project]', {
|
|
|
+ project: 'apple-ios',
|
|
|
+ })
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should display success message when using experimental endpoint', async function () {
|
|
|
+ const {organization} = initializeOrg({
|
|
|
+ organization: {
|
|
|
+ access: ['project:read'],
|
|
|
+ features: ['team-project-creation-all'],
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const frameWorkModalMockRequests = renderFrameworkModalMockRequests({
|
|
|
+ organization,
|
|
|
+ teamSlug: teamNoAccess.slug,
|
|
|
+ });
|
|
|
+ render(<CreateProject />, {
|
|
|
+ context: TestStubs.routerContext([
|
|
|
+ {
|
|
|
+ organization: {
|
|
|
+ id: '1',
|
|
|
+ slug: 'testOrg',
|
|
|
+ access: ['project:read'],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]),
|
|
|
+ organization,
|
|
|
+ });
|
|
|
+
|
|
|
+ renderGlobalModal();
|
|
|
+ await userEvent.click(screen.getByTestId('platform-apple-ios'));
|
|
|
+ await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
|
|
|
+
|
|
|
+ expect(
|
|
|
+ frameWorkModalMockRequests.experimentalprojectCreationMockRequest
|
|
|
+ ).toHaveBeenCalledTimes(1);
|
|
|
+ expect(addSuccessMessage).toHaveBeenCalledWith(
|
|
|
+ tct('Created [project] under new team [team]', {
|
|
|
+ project: 'testProj',
|
|
|
+ team: '#testTeam',
|
|
|
+ })
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
it('does not render framework selection modal if vanilla js is NOT selected', async function () {
|
|
|
const {organization} = initializeOrg({
|
|
|
organization: {
|