search-settings-panel-spec.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const SearchSettingsPanel = require('../lib/search-settings-panel');
  2. describe("SearchSettingsPanel", () => {
  3. describe("handleSettingsString", () => {
  4. let searchSettingsPanel = null;
  5. beforeEach(() => {
  6. searchSettingsPanel = new SearchSettingsPanel(null);
  7. });
  8. it("Is able to handle null values", () => {
  9. let string = searchSettingsPanel.handleSettingsString(null);
  10. expect(string).toBe("");
  11. });
  12. it("Is able to convert upercase to lowercase", () => {
  13. let string = searchSettingsPanel.handleSettingsString("Hello World");
  14. expect(string).toBe("hello world");
  15. });
  16. it("Does nothing to an already lowercase string", () => {
  17. let string = searchSettingsPanel.handleSettingsString("hello world");
  18. expect(string).toBe("hello world");
  19. });
  20. });
  21. describe("getScore", () => {
  22. let searchSettingsPanel = null;
  23. beforeEach(() => {
  24. searchSettingsPanel = new SearchSettingsPanel(null);
  25. });
  26. it("Returns a properly structured object", () => {
  27. let obj = searchSettingsPanel.getScore("hello world", "hello");
  28. expect(typeof obj === "object").toBe(true);
  29. expect(typeof obj.score === "number").toBe(true);
  30. expect(typeof obj.sequence === "string").toBe(true);
  31. });
  32. it("Returns the expected sequence", () => {
  33. let obj = searchSettingsPanel.getScore("hello world", "hello");
  34. expect(obj.sequence).toBe("hello");
  35. });
  36. it("Returns the expected score", () => {
  37. let obj = searchSettingsPanel.getScore("bank", "ba");
  38. expect(obj.score).toBe(0.5)
  39. });
  40. });
  41. describe("generateRanks", () => {
  42. let searchSettingsPanel = null;
  43. beforeEach(() => {
  44. searchSettingsPanel = new SearchSettingsPanel(null);
  45. });
  46. it("Returns a properly structured object", () => {
  47. let obj = searchSettingsPanel.generateRanks(
  48. "tab",
  49. "Tab Setting",
  50. "Just a friendly tab setting",
  51. "tabs",
  52. "tabSetting"
  53. );
  54. expect(typeof obj.title === "object").toBe(true);
  55. expect(typeof obj.title.score === "number").toBe(true);
  56. expect(typeof obj.title.sequence === "string").toBe(true);
  57. expect(typeof obj.description === "object").toBe(true);
  58. expect(typeof obj.description.score === "number").toBe(true);
  59. expect(typeof obj.description.sequence === "string").toBe(true);
  60. expect(typeof obj.settingName === "object").toBe(true);
  61. expect(typeof obj.settingName.score === "number").toBe(true);
  62. expect(typeof obj.settingName.sequence === "string").toBe(true);
  63. expect(typeof obj.settingItem === "object").toBe(true);
  64. expect(typeof obj.settingItem.score === "number").toBe(true);
  65. expect(typeof obj.settingItem.sequence === "string").toBe(true);
  66. expect(typeof obj.totalScore === "number").toBe(true);
  67. });
  68. });
  69. });