/** * @copyright Copyright (c) 2023 Lucas Azevedo * * @author Lucas Azevedo * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ import { action } from './inlineSystemTagsAction' import { expect } from '@jest/globals' import { File, Permission, View, FileAction } from '@nextcloud/files' const view = { id: 'files', name: 'Files', } as View describe('Inline system tags action conditions tests', () => { test('Default values', () => { const file = new File({ id: 1, source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt', owner: 'admin', mime: 'text/plain', permissions: Permission.ALL, }) expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('system-tags') expect(action.displayName([file], view)).toBe('') expect(action.iconSvgInline([], view)).toBe('') expect(action.default).toBeUndefined() expect(action.enabled).toBeUndefined() expect(action.order).toBe(0) }) }) describe('Inline system tags action render tests', () => { test('Render nothing when Node does not have system tags', async () => { const file = new File({ id: 1, source: 'http://localhost/remote.php/dav/files/admin/foobar.txt', owner: 'admin', mime: 'text/plain', permissions: Permission.ALL, }) const result = await action.renderInline!(file, view) expect(result).toBeNull() }) test('Render a single system tag', async () => { const file = new File({ id: 1, source: 'http://localhost/remote.php/dav/files/admin/foobar.txt', owner: 'admin', mime: 'text/plain', permissions: Permission.ALL, attributes: { 'system-tags': { 'system-tag': 'Confidential' } } }) const result = await action.renderInline!(file, view) expect(result).toBeInstanceOf(HTMLElement) expect(result!.outerHTML).toBe( '
    ' + '
  • Confidential
  • ' + '
' ) }) test('Render two system tags', async () => { const file = new File({ id: 1, source: 'http://localhost/remote.php/dav/files/admin/foobar.txt', owner: 'admin', mime: 'text/plain', permissions: Permission.ALL, attributes: { 'system-tags': { 'system-tag': [ 'Important', 'Confidential' ] } } }) const result = await action.renderInline!(file, view) expect(result).toBeInstanceOf(HTMLElement) expect(result!.outerHTML).toBe( '
    ' + '
  • Important
  • ' + '
  • +1
  • ' + '
' ) }) test('Render multiple system tags', async () => { const file = new File({ id: 1, source: 'http://localhost/remote.php/dav/files/admin/foobar.txt', owner: 'admin', mime: 'text/plain', permissions: Permission.ALL, attributes: { 'system-tags': { 'system-tag': [ 'Important', 'Confidential', 'Secret', 'Classified' ] } } }) const result = await action.renderInline!(file, view) expect(result).toBeInstanceOf(HTMLElement) expect(result!.outerHTML).toBe( '
    ' + '
  • Important
  • ' + '
  • +3
  • ' + '
' ) }) })