projectsStore.spec.jsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import ProjectsStore from 'app/stores/projectsStore';
  2. import ProjectActions from 'app/actions/projectActions';
  3. import TeamActions from 'app/actions/teamActions';
  4. describe('ProjectsStore', function() {
  5. let teamFoo = TestStubs.Team({
  6. slug: 'team-foo',
  7. });
  8. let teamBar = TestStubs.Team({
  9. slug: 'team-bar',
  10. });
  11. let projectFoo = TestStubs.Project({
  12. id: '2',
  13. slug: 'foo',
  14. name: 'Foo',
  15. teams: [teamFoo],
  16. });
  17. let projectBar = TestStubs.Project({
  18. id: '10',
  19. slug: 'bar',
  20. name: 'Bar',
  21. teams: [teamFoo, teamBar],
  22. });
  23. beforeEach(function() {
  24. ProjectsStore.reset();
  25. ProjectsStore.loadInitialData([projectFoo, projectBar]);
  26. });
  27. it('updates when slug changes', async function() {
  28. ProjectActions.changeSlug('foo', 'new-project');
  29. await tick();
  30. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  31. slug: 'new-project',
  32. });
  33. expect(ProjectsStore.itemsById[projectBar.id]).toBeDefined();
  34. });
  35. it('adds project to store on "create success"', async function() {
  36. let project = TestStubs.Project({id: '11', slug: 'created-project'});
  37. ProjectActions.createSuccess(project);
  38. await tick();
  39. expect(ProjectsStore.itemsById[project.id]).toMatchObject({
  40. id: '11',
  41. slug: 'created-project',
  42. });
  43. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  44. id: '2',
  45. slug: 'foo',
  46. name: 'Foo',
  47. });
  48. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  49. id: '10',
  50. slug: 'bar',
  51. });
  52. });
  53. it('updates a project in store', async function() {
  54. // Create a new project, but should have same id as `projectBar`
  55. let project = TestStubs.Project({id: '10', slug: 'bar', name: 'New Name'});
  56. ProjectActions.updateSuccess(project);
  57. await tick();
  58. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  59. id: '10',
  60. slug: 'bar',
  61. name: 'New Name',
  62. });
  63. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  64. id: '2',
  65. slug: 'foo',
  66. name: 'Foo',
  67. });
  68. });
  69. it('can remove a team from a single project', async function() {
  70. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  71. teams: [
  72. expect.objectContaining({slug: 'team-foo'}),
  73. expect.objectContaining({slug: 'team-bar'}),
  74. ],
  75. });
  76. ProjectActions.removeTeamSuccess('team-foo', 'bar');
  77. await tick();
  78. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  79. teams: [expect.objectContaining({slug: 'team-bar'})],
  80. });
  81. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  82. teams: [expect.objectContaining({slug: 'team-foo'})],
  83. });
  84. });
  85. it('removes a team from all projects when team is deleted', async function() {
  86. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  87. teams: [
  88. expect.objectContaining({slug: 'team-foo'}),
  89. expect.objectContaining({slug: 'team-bar'}),
  90. ],
  91. });
  92. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  93. teams: [expect.objectContaining({slug: 'team-foo'})],
  94. });
  95. TeamActions.removeTeamSuccess('team-foo');
  96. await tick();
  97. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  98. teams: [expect.objectContaining({slug: 'team-bar'})],
  99. });
  100. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  101. teams: [],
  102. });
  103. });
  104. it('can add a team to a project', async function() {
  105. let team = TestStubs.Team({
  106. slug: 'new-team',
  107. });
  108. ProjectActions.addTeamSuccess(team, 'foo');
  109. await tick();
  110. expect(ProjectsStore.itemsById[projectBar.id]).toMatchObject({
  111. teams: [
  112. expect.objectContaining({slug: 'team-foo'}),
  113. expect.objectContaining({slug: 'team-bar'}),
  114. ],
  115. });
  116. expect(ProjectsStore.itemsById[projectFoo.id]).toMatchObject({
  117. teams: [
  118. expect.objectContaining({slug: 'team-foo'}),
  119. expect.objectContaining({slug: 'new-team'}),
  120. ],
  121. });
  122. });
  123. });