You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchResultEntry-test.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { shallow } from 'enzyme';
  22. import SearchResultEntry, {
  23. SearchResultText,
  24. SearchResultTitle,
  25. SearchResultTokens
  26. } from '../SearchResultEntry';
  27. describe('SearchResultEntry', () => {
  28. it('should render', () => {
  29. expect(
  30. shallow(<SearchResultEntry active={true} result={mockSearchResult()} />)
  31. ).toMatchSnapshot();
  32. });
  33. });
  34. describe('SearchResultText', () => {
  35. it('should render with highlights', () => {
  36. expect(
  37. shallow(<SearchResultText result={mockSearchResult({ highlights: { text: [[12, 9]] } })} />)
  38. ).toMatchSnapshot();
  39. });
  40. it('should correctly extract exact matches', () => {
  41. expect(
  42. shallow(
  43. <SearchResultText
  44. result={mockSearchResult({ exactMatch: true, query: 'variable understood' })}
  45. />
  46. )
  47. ).toMatchSnapshot();
  48. });
  49. it('should render without highlights', () => {
  50. expect(shallow(<SearchResultText result={mockSearchResult()} />)).toMatchSnapshot();
  51. });
  52. });
  53. describe('SearchResultTitle', () => {
  54. it('should render with highlights', () => {
  55. expect(
  56. shallow(<SearchResultTitle result={mockSearchResult({ highlights: { title: [[0, 6]] } })} />)
  57. ).toMatchSnapshot();
  58. });
  59. it('should render not without highlights', () => {
  60. expect(shallow(<SearchResultTitle result={mockSearchResult()} />)).toMatchSnapshot();
  61. });
  62. });
  63. describe('SearchResultTokens', () => {
  64. it('should render', () => {
  65. expect(
  66. shallow(
  67. <SearchResultTokens
  68. tokens={[
  69. { marked: false, text: 'Foobar is a ' },
  70. { marked: true, text: 'universal' },
  71. {
  72. marked: false,
  73. text: ' variable understood to represent whatever is being discussed.'
  74. }
  75. ]}
  76. />
  77. )
  78. ).toMatchSnapshot();
  79. });
  80. });
  81. function mockSearchResult(overrides = {}) {
  82. return {
  83. page: {
  84. content: '',
  85. relativeName: 'foo/bar',
  86. url: '/foo/bar',
  87. text: 'Foobar is a universal variable understood to represent whatever is being discussed.',
  88. title: 'Foobar',
  89. navTitle: undefined
  90. },
  91. highlights: {},
  92. longestTerm: '',
  93. query: '',
  94. ...overrides
  95. };
  96. }