savedQueryList.spec.jsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import SavedQueryList from 'app/views/discover/sidebar/savedQueryList';
  4. describe('savedQueryList', function() {
  5. let organization, mockResponse;
  6. beforeEach(function() {
  7. organization = TestStubs.Organization();
  8. mockResponse = [];
  9. MockApiClient.addMockResponse({
  10. url: `/organizations/${organization.slug}/discover/saved/`,
  11. method: 'GET',
  12. body: mockResponse,
  13. });
  14. });
  15. afterEach(function() {
  16. MockApiClient.clearMockResponses();
  17. });
  18. it('renders empty state', async function() {
  19. const wrapper = mount(<SavedQueryList organization={organization} />);
  20. await tick();
  21. expect(wrapper.text()).toBe('No saved queries');
  22. });
  23. it('renders list', async function() {
  24. const savedQueries = [
  25. TestStubs.DiscoverSavedQuery({id: '1', name: 'one'}),
  26. TestStubs.DiscoverSavedQuery({id: '2', name: '2two'}),
  27. ];
  28. mockResponse.push(...savedQueries);
  29. const wrapper = mount(<SavedQueryList organization={organization} />);
  30. await tick();
  31. savedQueries.forEach(query => {
  32. expect(wrapper.text()).toContain(query.name);
  33. expect(wrapper.text()).toContain('Updated Sep 24 00:00:00 (UTC)');
  34. });
  35. });
  36. });