|
5 | 5 |
|
6 | 6 | import type { DAVResultResponseProps } from 'webdav' |
7 | 7 | import type { ServerTag, Tag } from './types.js' |
8 | | -import { describe, expect, it } from 'vitest' |
9 | 8 |
|
10 | | -import { formatTag, parseIdFromLocation, parseTags } from './utils' |
| 9 | +import { describe, expect, it } from 'vitest' |
| 10 | +import { formatTag, getNodeSystemTags, parseIdFromLocation, parseTags } from './utils' |
| 11 | +import { Folder } from '@nextcloud/files' |
11 | 12 |
|
12 | 13 | describe('systemtags - utils', () => { |
13 | 14 | describe('parseTags', () => { |
@@ -85,4 +86,92 @@ describe('systemtags - utils', () => { |
85 | 86 | }) |
86 | 87 | }) |
87 | 88 | }) |
| 89 | + |
| 90 | + describe('getNodeSystemTags', () => { |
| 91 | + it('parses a plain tag', () => { |
| 92 | + const node = new Folder({ |
| 93 | + owner: 'test', |
| 94 | + source: 'https://example.com/remote.php/dav/files/test/folder', |
| 95 | + attributes: { |
| 96 | + 'system-tags': { |
| 97 | + 'system-tag': 'tag', |
| 98 | + }, |
| 99 | + }, |
| 100 | + }) |
| 101 | + expect(getNodeSystemTags(node)).toStrictEqual(['tag']) |
| 102 | + }) |
| 103 | + |
| 104 | + it('parses plain tags', () => { |
| 105 | + const node = new Folder({ |
| 106 | + owner: 'test', |
| 107 | + source: 'https://example.com/remote.php/dav/files/test/folder', |
| 108 | + attributes: { |
| 109 | + 'system-tags': { |
| 110 | + 'system-tag': [ |
| 111 | + 'tag', |
| 112 | + 'my-tag', |
| 113 | + ], |
| 114 | + }, |
| 115 | + }, |
| 116 | + }) |
| 117 | + expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag']) |
| 118 | + }) |
| 119 | + |
| 120 | + it('parses tag with attributes', () => { |
| 121 | + const node = new Folder({ |
| 122 | + owner: 'test', |
| 123 | + source: 'https://example.com/remote.php/dav/files/test/folder', |
| 124 | + attributes: { |
| 125 | + 'system-tags': { |
| 126 | + 'system-tag': { |
| 127 | + text: 'tag', |
| 128 | + '@can-assign': true, |
| 129 | + }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + }) |
| 133 | + expect(getNodeSystemTags(node)).toStrictEqual(['tag']) |
| 134 | + }) |
| 135 | + |
| 136 | + it('parses tags with attributes', () => { |
| 137 | + const node = new Folder({ |
| 138 | + owner: 'test', |
| 139 | + source: 'https://example.com/remote.php/dav/files/test/folder', |
| 140 | + attributes: { |
| 141 | + 'system-tags': { |
| 142 | + 'system-tag': [ |
| 143 | + { |
| 144 | + text: 'tag', |
| 145 | + '@can-assign': true, |
| 146 | + }, |
| 147 | + { |
| 148 | + text: 'my-tag', |
| 149 | + '@can-assign': false, |
| 150 | + }, |
| 151 | + ], |
| 152 | + }, |
| 153 | + }, |
| 154 | + }) |
| 155 | + expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag']) |
| 156 | + }) |
| 157 | + |
| 158 | + it('parses tags mixed with and without attributes', () => { |
| 159 | + const node = new Folder({ |
| 160 | + owner: 'test', |
| 161 | + source: 'https://example.com/remote.php/dav/files/test/folder', |
| 162 | + attributes: { |
| 163 | + 'system-tags': { |
| 164 | + 'system-tag': [ |
| 165 | + 'tag', |
| 166 | + { |
| 167 | + text: 'my-tag', |
| 168 | + '@can-assign': false, |
| 169 | + }, |
| 170 | + ], |
| 171 | + }, |
| 172 | + }, |
| 173 | + }) |
| 174 | + expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag']) |
| 175 | + }) |
| 176 | + }) |
88 | 177 | }) |
0 commit comments