organizationStore.spec.jsx 3.1 KB

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