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

test(ui): Convert screenshot tests to RTL (#37329)

Scott Cooper 2 лет назад
Родитель
Сommit
53fe8ba344

+ 1 - 12
tests/js/spec/views/accountAuthorization.spec.jsx

@@ -1,5 +1,3 @@
-import * as PropTypes from 'prop-types';
-
 import {render} from 'sentry-test/reactTestingLibrary';
 
 import {Client} from 'sentry/api';
@@ -18,16 +16,7 @@ describe('AccountAuthorizations', function () {
     });
 
     const wrapper = render(<AccountAuthorizations />, {
-      context: {
-        context: {
-          location: TestStubs.location(),
-          router: TestStubs.router(),
-        },
-        childContextTypes: {
-          location: PropTypes.object,
-          router: PropTypes.object,
-        },
-      },
+      context: TestStubs.routerContext(),
     });
 
     expect(wrapper.container).toSnapshot();

+ 8 - 20
tests/js/spec/views/accountSubscriptions.spec.jsx

@@ -1,6 +1,4 @@
-import * as PropTypes from 'prop-types';
-
-import {mountWithTheme} from 'sentry-test/enzyme';
+import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
 
 import {Client} from 'sentry/api';
 import AccountSubscriptions from 'sentry/views/settings/account/accountSubscriptions';
@@ -17,16 +15,11 @@ describe('AccountSubscriptions', function () {
       url: ENDPOINT,
       body: [],
     });
-    const wrapper = mountWithTheme(<AccountSubscriptions />, {
-      context: {
-        router: TestStubs.router(),
-      },
-      childContextTypes: {
-        router: PropTypes.object,
-      },
+    const wrapper = render(<AccountSubscriptions />, {
+      context: TestStubs.routerContext(),
     });
 
-    expect(wrapper).toSnapshot();
+    expect(wrapper.container).toSnapshot();
   });
 
   it('renders list and can toggle', function () {
@@ -39,20 +32,15 @@ describe('AccountSubscriptions', function () {
       method: 'PUT',
     });
 
-    const wrapper = mountWithTheme(<AccountSubscriptions />, {
-      context: {
-        router: TestStubs.router(),
-      },
-      childContextTypes: {
-        router: PropTypes.object,
-      },
+    const wrapper = render(<AccountSubscriptions />, {
+      context: TestStubs.routerContext(),
     });
 
-    expect(wrapper).toSnapshot();
+    expect(wrapper.container).toSnapshot();
 
     expect(mock).not.toHaveBeenCalled();
 
-    wrapper.find('Switch').first().simulate('click');
+    userEvent.click(screen.getAllByTestId('switch')[0]);
 
     expect(mock).toHaveBeenCalledWith(
       ENDPOINT,

+ 6 - 18
tests/js/spec/views/settings/organizationApiKeyDetailsView.spec.jsx

@@ -1,15 +1,7 @@
-import * as PropTypes from 'prop-types';
-
-import {mountWithTheme} from 'sentry-test/enzyme';
+import {render, screen} from 'sentry-test/reactTestingLibrary';
 
 import OrganizationApiKeyDetails from 'sentry/views/settings/organizationApiKeys/organizationApiKeyDetails';
 
-const childContextTypes = {
-  organization: PropTypes.object,
-  router: PropTypes.object,
-  location: PropTypes.object,
-};
-
 describe('OrganizationApiKeyDetails', function () {
   beforeEach(function () {
     MockApiClient.clearMockResponses();
@@ -21,19 +13,15 @@ describe('OrganizationApiKeyDetails', function () {
   });
 
   it('renders', function () {
-    const wrapper = mountWithTheme(
+    const wrapper = render(
       <OrganizationApiKeyDetails params={{apiKey: 1, orgId: 'org-slug'}} />,
       {
-        context: {
-          router: TestStubs.router(),
-          organization: TestStubs.Organization(),
-          location: TestStubs.location(),
-        },
-        childContextTypes,
+        context: TestStubs.routerContext(),
+        organization: TestStubs.Organization(),
       }
     );
 
-    expect(wrapper.find('LoadingIndicator')).toHaveLength(0);
-    expect(wrapper).toSnapshot();
+    expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
+    expect(wrapper.container).toSnapshot();
   });
 });