Просмотр исходного кода

test(onboarding): assert project platform (#51041)

Ogi 1 год назад
Родитель
Сommit
fca24d093c

+ 68 - 34
static/app/views/projectInstall/platform.spec.tsx

@@ -4,7 +4,31 @@ import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
 import ProjectsStore from 'sentry/stores/projectsStore';
 import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
 
+function mockProjectApiResponses(projects) {
+  MockApiClient.addMockResponse({
+    method: 'GET',
+    url: '/organizations/org-slug/projects/',
+    body: projects,
+  });
+
+  MockApiClient.addMockResponse({
+    method: 'GET',
+    url: '/projects/org-slug/project-slug/rules/',
+    body: [],
+  });
+
+  MockApiClient.addMockResponse({
+    method: 'GET',
+    url: '/projects/org-slug/project-slug/',
+    body: projects,
+  });
+}
+
 describe('ProjectInstallPlatform', function () {
+  beforeEach(function () {
+    MockApiClient.clearMockResponses();
+  });
+
   it('should render NotFound if no matching integration/platform', async function () {
     const routeParams = {
       projectId: TestStubs.Project().slug,
@@ -18,23 +42,7 @@ describe('ProjectInstallPlatform', function () {
       },
     });
 
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/organizations/org-slug/projects/',
-      body: [{...project, platform: 'lua'}],
-    });
-
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/projects/org-slug/project-slug/rules/',
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/projects/org-slug/project-slug/',
-      body: [{...project, platform: 'lua'}],
-    });
+    mockProjectApiResponses([{...project, platform: 'lua'}]);
 
     render(
       <ProjectInstallPlatform
@@ -71,23 +79,7 @@ describe('ProjectInstallPlatform', function () {
     // this is needed because we don't handle a loading state in the UI
     ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
 
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/organizations/org-slug/projects/',
-      body: [{...project, platform: 'other'}],
-    });
-
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/projects/org-slug/project-slug/rules/',
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      method: 'GET',
-      url: '/projects/org-slug/project-slug/',
-      body: [{...project, platform: 'other'}],
-    });
+    mockProjectApiResponses([{...project, platform: 'other'}]);
 
     render(
       <ProjectInstallPlatform
@@ -108,4 +100,46 @@ describe('ProjectInstallPlatform', function () {
       expect(router.push).toHaveBeenCalledTimes(1);
     });
   });
+
+  it('should render getting started docs for correct platform', async function () {
+    const project = TestStubs.Project({platform: 'javascript'});
+
+    const routeParams = {
+      projectId: project.slug,
+      platform: 'python',
+    };
+
+    const {router, route, routerContext} = initializeOrg({
+      router: {
+        location: {
+          query: {},
+        },
+        params: routeParams,
+      },
+    });
+
+    ProjectsStore.loadInitialData([project]);
+
+    mockProjectApiResponses([project]);
+
+    render(
+      <ProjectInstallPlatform
+        router={router}
+        route={route}
+        location={router.location}
+        routeParams={routeParams}
+        routes={router.routes}
+        params={routeParams}
+      />,
+      {
+        context: routerContext,
+      }
+    );
+
+    expect(
+      await screen.findByRole('heading', {
+        name: 'Configure JavaScript SDK',
+      })
+    ).toBeInTheDocument();
+  });
 });

+ 21 - 5
tests/acceptance/test_create_project.py

@@ -1,3 +1,5 @@
+from selenium.webdriver.common.by import By
+
 from sentry.testutils import AcceptanceTestCase
 from sentry.testutils.silo import region_silo_test
 
@@ -7,13 +9,12 @@ class CreateProjectTest(AcceptanceTestCase):
     def setUp(self):
         super().setUp()
         self.user = self.create_user("foo@example.com")
-        self.org = self.create_organization(name="Rowdy Tiger")
+        self.org = self.create_organization(name="Rowdy Tiger", owner=self.user)
         self.login_as(self.user)
 
         self.path = f"/organizations/{self.org.slug}/projects/new/"
 
     def test_no_teams(self):
-        self.create_member(user=self.user, organization=self.org, role="owner", teams=[])
         self.browser.get(self.path)
         self.browser.wait_until_not(".loading")
 
@@ -31,9 +32,24 @@ class CreateProjectTest(AcceptanceTestCase):
     def test_many_teams(self):
         self.team = self.create_team(organization=self.org, name="Mariachi Band")
         self.team2 = self.create_team(organization=self.org, name="team two")
-        self.create_member(
-            user=self.user, organization=self.org, role="owner", teams=[self.team, self.team2]
-        )
+
         self.browser.get(self.path)
         self.browser.wait_until_not(".loading")
         self.browser.snapshot(name="create project many teams")
+
+    def test_select_correct_platform(self):
+        self.create_team(organization=self.org, name="team three")
+
+        self.browser.get(self.path)
+        self.browser.wait_until_not(".loading")
+
+        self.browser.click('[data-test-id="platform-javascript-react"]')
+        self.browser.wait_until_not(".loading")
+        self.browser.click('[data-test-id="create-project"]')
+
+        self.browser.wait_until_not(".loading")
+        self.browser.wait_until("h2")
+
+        title = self.browser.find_element(by=By.CSS_SELECTOR, value="h2")
+
+        assert "React" in title.text