hpkp.spec.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectHpkpReports from 'sentry/views/settings/projectSecurityHeaders/hpkp';
  4. describe('ProjectHpkpReports', function () {
  5. const {organization, project} = initializeOrg();
  6. const keysUrl = `/projects/${organization.slug}/${project.slug}/keys/`;
  7. beforeEach(function () {
  8. MockApiClient.clearMockResponses();
  9. MockApiClient.addMockResponse({
  10. url: keysUrl,
  11. method: 'GET',
  12. body: [],
  13. });
  14. });
  15. it('renders', async function () {
  16. render(<ProjectHpkpReports />, {
  17. organization,
  18. });
  19. // Renders the loading indication initially
  20. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  21. // Heading
  22. expect(
  23. await screen.findByText('HTTP Public Key Pinning', {selector: 'h4'})
  24. ).toBeInTheDocument();
  25. });
  26. it('renders loading error', async function () {
  27. MockApiClient.addMockResponse({
  28. url: keysUrl,
  29. method: 'GET',
  30. statusCode: 400,
  31. body: {},
  32. });
  33. render(<ProjectHpkpReports />, {
  34. organization,
  35. });
  36. expect(
  37. await screen.findByText('There was an error loading data.')
  38. ).toBeInTheDocument();
  39. });
  40. });