organizationStore.spec.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {updateOrganization} from 'app/actionCreators/organizations';
  2. import OrganizationActions from 'app/actions/organizationActions';
  3. import ProjectActions from 'app/actions/projectActions';
  4. import OrganizationStore from 'app/stores/organizationStore';
  5. describe('OrganizationStore', function () {
  6. beforeEach(function () {
  7. OrganizationStore.reset();
  8. });
  9. it('starts with loading state', function () {
  10. expect(OrganizationStore.get()).toMatchObject({
  11. loading: true,
  12. error: null,
  13. errorType: null,
  14. organization: null,
  15. dirty: false,
  16. });
  17. });
  18. it('updates correctly', async function () {
  19. const organization = TestStubs.Organization();
  20. OrganizationActions.update(organization);
  21. await tick();
  22. expect(OrganizationStore.get()).toMatchObject({
  23. loading: false,
  24. error: null,
  25. errorType: null,
  26. organization,
  27. dirty: false,
  28. });
  29. // updates
  30. organization.slug = 'a new slug';
  31. OrganizationActions.update(organization);
  32. await tick();
  33. expect(OrganizationStore.get()).toMatchObject({
  34. loading: false,
  35. error: null,
  36. errorType: null,
  37. organization,
  38. dirty: false,
  39. });
  40. });
  41. it('updates correctly from setting changes', async function () {
  42. const organization = TestStubs.Organization();
  43. updateOrganization(organization);
  44. await tick();
  45. expect(OrganizationStore.get()).toMatchObject({
  46. loading: false,
  47. error: null,
  48. errorType: null,
  49. organization,
  50. dirty: false,
  51. });
  52. });
  53. it('errors correctly', async function () {
  54. const error = new Error('uh-oh');
  55. error.status = 404;
  56. OrganizationActions.fetchOrgError(error);
  57. await tick();
  58. expect(OrganizationStore.get()).toMatchObject({
  59. loading: false,
  60. error,
  61. errorType: 'ORG_NOT_FOUND',
  62. organization: null,
  63. dirty: false,
  64. });
  65. });
  66. it('loads in sorted projects', async function () {
  67. const organization = TestStubs.Organization();
  68. OrganizationActions.update(organization);
  69. // wait for action to get dispatched to store
  70. await tick();
  71. const projectA = TestStubs.Project({slug: 'a'});
  72. const projectB = TestStubs.Project({slug: 'b'});
  73. const projects = [projectB, projectA];
  74. ProjectActions.loadProjects(projects);
  75. // wait for action to get dispatched to store
  76. await tick();
  77. // verify existence and sorted order of loaded projects
  78. expect(OrganizationStore.get().organization.projects).toEqual([projectA, projectB]);
  79. });
  80. });