username-history.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import assert from 'assert';
  2. import moment from 'moment'; // jshint ignore:line
  3. import React from 'react'; // jshint ignore:line
  4. import UsernameHistory from 'misago/components/username-history/root'; // jshint ignore:line
  5. import * as testUtils from 'misago/utils/test-utils';
  6. describe("Username History", function() {
  7. afterEach(function() {
  8. testUtils.unmountComponents();
  9. });
  10. it("renders preview", function(done) {
  11. /* jshint ignore:start */
  12. testUtils.render(<UsernameHistory isLoaded={false} />);
  13. /* jshint ignore:end */
  14. testUtils.onElement('#test-mount .username-history.ui-preview', function() {
  15. assert.ok(true, "component renders");
  16. done();
  17. });
  18. });
  19. it("renders empty", function(done) {
  20. /* jshint ignore:start */
  21. testUtils.render(
  22. <UsernameHistory isLoaded={true}
  23. changes={[]} />
  24. );
  25. /* jshint ignore:end */
  26. testUtils.onElement('#test-mount .empty-message', function() {
  27. assert.equal($('.empty-message').text().trim(),
  28. "No name changes have been recorded for your account.",
  29. "component renders with message");
  30. done();
  31. });
  32. });
  33. it("renders with two changes", function(done) {
  34. /* jshint ignore:start */
  35. let changes = [
  36. {
  37. id: 27,
  38. changed_by: {
  39. id: 1,
  40. username: "rafalp",
  41. slug: "rafalp",
  42. avatar_hash: "5c6a04b4",
  43. absolute_url: "/user/rafalp-1/"
  44. },
  45. changed_by_username: "rafalp",
  46. changed_on: moment(),
  47. new_username: "Newt",
  48. old_username: "LoremIpsum"
  49. },
  50. {
  51. id: 26,
  52. changed_by: {
  53. id: 1,
  54. username: "rafalp",
  55. slug: "rafalp",
  56. avatar_hash: "5c6a04b4",
  57. absolute_url: "/user/rafalp-1/"
  58. },
  59. changed_by_username: "rafalp",
  60. changed_on: moment(),
  61. new_username: "LoremIpsum",
  62. old_username: "BobBoberson"
  63. }
  64. ];
  65. testUtils.render(
  66. <UsernameHistory isLoaded={true}
  67. changes={changes} />
  68. );
  69. /* jshint ignore:end */
  70. testUtils.onElement('#test-mount .username-history.ui-ready', function() {
  71. assert.equal($('#test-mount .list-group-item').length, 2,
  72. "component renders with two items");
  73. done();
  74. });
  75. });
  76. });