category-picker.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import CategoryPicker from 'misago/components/threads/category-picker'; // jshint ignore:line
  4. import * as testUtils from 'misago/utils/test-utils';
  5. /* jshint ignore:start */
  6. let list = {
  7. name: "All",
  8. nameLong: "All threads",
  9. path: ''
  10. };
  11. let categories = {
  12. 1: {
  13. id: 1,
  14. name: "First Category",
  15. css_class: null,
  16. absolute_url: '/category-1/'
  17. },
  18. 3: {
  19. id: 3,
  20. name: "Second Category",
  21. css_class: 'custom',
  22. absolute_url: '/category-3/'
  23. }
  24. };
  25. /* jshint ignore:end */
  26. describe("Threads List Category Picker", function() {
  27. afterEach(function() {
  28. testUtils.unmountComponents();
  29. });
  30. it("renders with invalid categories", function() {
  31. /* jshint ignore:start */
  32. testUtils.render(
  33. <CategoryPicker list={list}
  34. categories={{}}
  35. choices={[1, 3, 5]} />
  36. );
  37. /* jshint ignore:end */
  38. let element = $('#test-mount .list-inline');
  39. assert.ok(element.length, "component renders");
  40. assert.ok(!element.find('li').length, "picker renders without choices");
  41. });
  42. it("renders with some invalid categories", function() {
  43. /* jshint ignore:start */
  44. testUtils.render(
  45. <CategoryPicker list={list}
  46. categories={categories}
  47. choices={[1, 2, 3, 4, 5]} />
  48. );
  49. /* jshint ignore:end */
  50. let element = $('#test-mount .list-inline');
  51. assert.ok(element.length, "component renders");
  52. assert.equal(element.find('li').length, 2,
  53. "picker renders with two valid choices");
  54. assert.equal(element.find('li').first().text(),
  55. "First Category",
  56. "first category is rendered in picker");
  57. assert.equal(element.find('li').last().text(),
  58. "Second Category",
  59. "second category is rendered in picker");
  60. assert.ok(element.find('li').find('a.subcategory-custom').length,
  61. "second category has custom class");
  62. });
  63. it("renders with categories", function() {
  64. /* jshint ignore:start */
  65. testUtils.render(
  66. <CategoryPicker list={list}
  67. categories={categories}
  68. choices={[1, 3]} />
  69. );
  70. /* jshint ignore:end */
  71. let element = $('#test-mount .list-inline');
  72. assert.ok(element.length, "component renders");
  73. assert.equal(element.find('li').length, 2,
  74. "picker renders with two valid choices");
  75. assert.equal(element.find('li').first().text(),
  76. "First Category",
  77. "first category is rendered in picker");
  78. assert.equal(element.find('li').last(1).text(),
  79. "Second Category",
  80. "second category is rendered in picker");
  81. assert.ok(element.find('li').find('a.subcategory-custom').length,
  82. "second category has custom class");
  83. });
  84. });