threads.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import assert from 'assert';
  2. import moment from 'moment';
  3. import reducer, { append, hydrate, hydrateThread } from 'misago/reducers/threads';
  4. describe("Threads Reducer", function() {
  5. it("hydrates thread", function() {
  6. let timestamp = moment().format();
  7. let thread = hydrateThread({
  8. started_on: timestamp,
  9. last_post_on: timestamp
  10. });
  11. assert.equal(thread.started_on.format(), timestamp,
  12. "thread start date was hydrated");
  13. assert.equal(thread.last_post_on.format(), timestamp,
  14. "thread last reply date was hydrated");
  15. });
  16. it("hydrates threads list", function() {
  17. let timestamp = moment().format();
  18. let threads = reducer([], hydrate([
  19. {
  20. id: 1,
  21. started_on: timestamp,
  22. last_post_on: timestamp
  23. },
  24. {
  25. id: 3,
  26. started_on: timestamp,
  27. last_post_on: timestamp
  28. }
  29. ]));
  30. assert.equal(threads.length, 2,
  31. "two threads were hydrated and set as state");
  32. assert.equal(threads[0].started_on.format(), timestamp,
  33. "first thread was hydrated");
  34. assert.equal(threads[1].started_on.format(), timestamp,
  35. "second thread was hydrated");
  36. });
  37. it("appends threads to list", function() {
  38. let timestamp = moment().format();
  39. let threads = reducer([
  40. {
  41. id: 1,
  42. started_on: timestamp,
  43. last_post_on: timestamp,
  44. last_post: 4
  45. },
  46. {
  47. id: 3,
  48. started_on: timestamp,
  49. last_post_on: timestamp,
  50. last_post: 1
  51. }
  52. ], append([
  53. {
  54. id: 1,
  55. started_on: timestamp,
  56. last_post_on: timestamp,
  57. last_post: 5
  58. },
  59. {
  60. id: 2,
  61. started_on: timestamp,
  62. last_post_on: timestamp,
  63. last_post: 3
  64. }
  65. ]));
  66. assert.equal(threads.length, 3, "one thread was added to state");
  67. assert.equal(threads[0].id, 1, "first thread wasn't moved");
  68. assert.equal(threads[0].last_post, 5, "first thread was updated");
  69. assert.equal(threads[1].id, 2, "new thread was appended as second");
  70. assert.equal(threads[2].id, 3, "old second thread is now last");
  71. });
  72. });