withDiscoverSavedQueries.spec.jsx 1003 B

12345678910111213141516171819202122232425262728293031323334
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import DiscoverSavedQueriesStore from 'app/stores/discoverSavedQueriesStore';
  4. import withDiscoverSavedQueries from 'app/utils/withDiscoverSavedQueries';
  5. describe('withDiscoverSavedQueries HoC', function() {
  6. beforeEach(() => {
  7. DiscoverSavedQueriesStore.reset();
  8. });
  9. it('works', function() {
  10. const MyComponent = () => null;
  11. const Container = withDiscoverSavedQueries(MyComponent);
  12. const wrapper = mount(<Container />);
  13. expect(wrapper.find('MyComponent').prop('savedQueries')).toEqual([]);
  14. // Insert into the store
  15. const query = {
  16. id: '1',
  17. fields: ['title', 'count()'],
  18. createdAt: new Date(),
  19. updatedAt: new Date(),
  20. createdBy: '1',
  21. };
  22. DiscoverSavedQueriesStore.fetchSavedQueriesSuccess([query]);
  23. wrapper.update();
  24. const props = wrapper.find('MyComponent').prop('savedQueries');
  25. expect(props).toHaveLength(1);
  26. expect(props[0].id).toBe(query.id);
  27. });
  28. });