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.

inlineSystemTagsAction.spec.ts 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @copyright Copyright (c) 2023 Lucas Azevedo <lhs_azevedo@hotmail.com>
  3. *
  4. * @author Lucas Azevedo <lhs_azevedo@hotmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { action } from './inlineSystemTagsAction'
  23. import { expect } from '@jest/globals'
  24. import { File, Permission, View, FileAction } from '@nextcloud/files'
  25. const view = {
  26. id: 'files',
  27. name: 'Files',
  28. } as View
  29. describe('Inline system tags action conditions tests', () => {
  30. test('Default values', () => {
  31. const file = new File({
  32. id: 1,
  33. source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
  34. owner: 'admin',
  35. mime: 'text/plain',
  36. permissions: Permission.ALL,
  37. })
  38. expect(action).toBeInstanceOf(FileAction)
  39. expect(action.id).toBe('system-tags')
  40. expect(action.displayName([file], view)).toBe('')
  41. expect(action.iconSvgInline([], view)).toBe('')
  42. expect(action.default).toBeUndefined()
  43. expect(action.enabled).toBeUndefined()
  44. expect(action.order).toBe(0)
  45. })
  46. })
  47. describe('Inline system tags action render tests', () => {
  48. test('Render nothing when Node does not have system tags', async () => {
  49. const file = new File({
  50. id: 1,
  51. source: 'http://localhost/remote.php/dav/files/admin/foobar.txt',
  52. owner: 'admin',
  53. mime: 'text/plain',
  54. permissions: Permission.ALL,
  55. })
  56. const result = await action.renderInline!(file, view)
  57. expect(result).toBeNull()
  58. })
  59. test('Render a single system tag', async () => {
  60. const file = new File({
  61. id: 1,
  62. source: 'http://localhost/remote.php/dav/files/admin/foobar.txt',
  63. owner: 'admin',
  64. mime: 'text/plain',
  65. permissions: Permission.ALL,
  66. attributes: {
  67. 'system-tags': {
  68. 'system-tag': 'Confidential'
  69. }
  70. }
  71. })
  72. const result = await action.renderInline!(file, view)
  73. expect(result).toBeInstanceOf(HTMLElement)
  74. expect(result!.outerHTML).toBe(
  75. '<ul class="files-list__system-tags" aria-label="This file has the tag Confidential">' +
  76. '<li class="files-list__system-tag">Confidential</li>' +
  77. '</ul>'
  78. )
  79. })
  80. test('Render two system tags', async () => {
  81. const file = new File({
  82. id: 1,
  83. source: 'http://localhost/remote.php/dav/files/admin/foobar.txt',
  84. owner: 'admin',
  85. mime: 'text/plain',
  86. permissions: Permission.ALL,
  87. attributes: {
  88. 'system-tags': {
  89. 'system-tag': [
  90. 'Important',
  91. 'Confidential'
  92. ]
  93. }
  94. }
  95. })
  96. const result = await action.renderInline!(file, view)
  97. expect(result).toBeInstanceOf(HTMLElement)
  98. expect(result!.outerHTML).toBe(
  99. '<ul class="files-list__system-tags" aria-label="This file has the tags Important and Confidential">' +
  100. '<li class="files-list__system-tag">Important</li>' +
  101. '<li class="files-list__system-tag files-list__system-tag--more" title="Confidential">+1</li>' +
  102. '</ul>'
  103. )
  104. })
  105. test('Render multiple system tags', async () => {
  106. const file = new File({
  107. id: 1,
  108. source: 'http://localhost/remote.php/dav/files/admin/foobar.txt',
  109. owner: 'admin',
  110. mime: 'text/plain',
  111. permissions: Permission.ALL,
  112. attributes: {
  113. 'system-tags': {
  114. 'system-tag': [
  115. 'Important',
  116. 'Confidential',
  117. 'Secret',
  118. 'Classified'
  119. ]
  120. }
  121. }
  122. })
  123. const result = await action.renderInline!(file, view)
  124. expect(result).toBeInstanceOf(HTMLElement)
  125. expect(result!.outerHTML).toBe(
  126. '<ul class="files-list__system-tags" aria-label="This file has the tags Important, Confidential, Secret and Classified">' +
  127. '<li class="files-list__system-tag">Important</li>' +
  128. '<li class="files-list__system-tag files-list__system-tag--more" title="Confidential, Secret, Classified">+3</li>' +
  129. '</ul>'
  130. )
  131. })
  132. })