Merge branch '18848-upgrade-yarn3'. Closes #18848
[arvados-workbench2.git] / src / models / vocabulary.test.ts
index 87a8dfb26f92688aa357318f6447203a45004cdc..f4ba64e5ad450a286ac419116d725543ac87651c 100644 (file)
@@ -3,7 +3,6 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as Vocabulary from './vocabulary';
-import { pipe } from 'lodash/fp';
 
 describe('Vocabulary', () => {
     let vocabulary: Vocabulary.Vocabulary;
@@ -19,7 +18,8 @@ describe('Vocabulary', () => {
                     strict: false,
                     labels: [
                         {label: "Animal" },
-                        {label: "Creature"}
+                        {label: "Creature"},
+                        {label: "Beast"},
                     ],
                     values: {
                         IDVALANIMALS1: {
@@ -40,18 +40,26 @@ describe('Vocabulary', () => {
                     labels: [{label: "Sizes"}],
                     values: {
                         IDVALSIZES1: {
-                            labels: [{label: "Small"}]
+                            labels: [{label: "Small"}, {label: "S"}, {label: "Little"}]
                         },
                         IDVALSIZES2: {
-                            labels: [{label: "Medium"}]
+                            labels: [{label: "Medium"}, {label: "M"}]
                         },
                         IDVALSIZES3: {
-                            labels: [{label: "Large"}]
+                            labels: [{label: "Large"}, {label: "L"}]
                         },
                         IDVALSIZES4: {
                             labels: []
                         }
                     }
+                },
+                automation: {
+                    strict: true,
+                    labels: [],
+                    values: {
+                        upload: { labels: [] },
+                        results: { labels: [] },
+                    }
                 }
             }
         }
@@ -62,9 +70,33 @@ describe('Vocabulary', () => {
         // Alphabetically ordered by label
         expect(tagKeys).toEqual([
             {id: "IDKEYANIMALS", label: "Animal"},
+            {id: "IDKEYANIMALS", label: "Beast"},
             {id: "IDKEYANIMALS", label: "Creature"},
             {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT"},
             {id: "IDKEYSIZES", label: "Sizes"},
+            {id: "automation", label: "automation"},
+        ]);
+    });
+
+    it('returns the list of preferred tag keys', () => {
+        const preferredTagKeys = Vocabulary.getPreferredTags(vocabulary);
+        // Alphabetically ordered by label
+        expect(preferredTagKeys).toEqual([
+            {id: "IDKEYANIMALS", label: "Animal", synonyms: []},
+            {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT", synonyms: []},
+            {id: "IDKEYSIZES", label: "Sizes", synonyms: []},
+            {id: "automation", label: "automation", synonyms: []},
+        ]);
+    });
+
+    it('returns the list of preferred tag keys with matching synonyms', () => {
+        const preferredTagKeys = Vocabulary.getPreferredTags(vocabulary, 'creat');
+        // Alphabetically ordered by label
+        expect(preferredTagKeys).toEqual([
+            {id: "IDKEYANIMALS", label: "Animal", synonyms: ["Creature"]},
+            {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT", synonyms: []},
+            {id: "IDKEYSIZES", label: "Sizes", synonyms: []},
+            {id: "automation", label: "automation", synonyms: []},
         ]);
     });
 
@@ -73,9 +105,47 @@ describe('Vocabulary', () => {
         // Alphabetically ordered by label
         expect(tagValues).toEqual([
             {id: "IDVALSIZES4", label: "IDVALSIZES4"},
+            {id: "IDVALSIZES3", label: "L"},
             {id: "IDVALSIZES3", label: "Large"},
+            {id: "IDVALSIZES1", label: "Little"},
+            {id: "IDVALSIZES2", label: "M"},
             {id: "IDVALSIZES2", label: "Medium"},
+            {id: "IDVALSIZES1", label: "S"},
             {id: "IDVALSIZES1", label: "Small"},
+        ]);
+        // Let's try a key that doesn't have any labels
+        const tagValues2 = Vocabulary.getTagValues('automation', vocabulary);
+        expect(tagValues2).toEqual([
+            {id: "results", label: "results"},
+            {id: "upload", label: "upload"},
+        ]);
+    });
+
+    it('returns the preferred tag values for a given key', () => {
+        const preferredTagValues = Vocabulary.getPreferredTagValues('IDKEYSIZES', vocabulary);
+        // Alphabetically ordered by label
+        expect(preferredTagValues).toEqual([
+            {id: "IDVALSIZES4", label: "IDVALSIZES4", synonyms: []},
+            {id: "IDVALSIZES3", label: "Large", synonyms: []},
+            {id: "IDVALSIZES2", label: "Medium", synonyms: []},
+            {id: "IDVALSIZES1", label: "Small", synonyms: []},
+        ]);
+        // Let's try a key that doesn't have any labels
+        const preferredTagValues2 = Vocabulary.getPreferredTagValues('automation', vocabulary);
+        expect(preferredTagValues2).toEqual([
+            {id: "results", label: "results", synonyms: []},
+            {id: "upload", label: "upload", synonyms: []},
+        ]);
+    });
+
+    it('returns the preferred tag values with matching synonyms for a given key', () => {
+        const preferredTagValues = Vocabulary.getPreferredTagValues('IDKEYSIZES', vocabulary, 'litt');
+        // Alphabetically ordered by label
+        expect(preferredTagValues).toEqual([
+            {id: "IDVALSIZES4", label: "IDVALSIZES4", synonyms: []},
+            {id: "IDVALSIZES3", label: "Large", synonyms: []},
+            {id: "IDVALSIZES2", label: "Medium", synonyms: []},
+            {id: "IDVALSIZES1", label: "Small", synonyms: ["Little"]},
         ])
     });
 
@@ -91,6 +161,8 @@ describe('Vocabulary', () => {
             {keyLabel: 'Creature', expected: 'IDKEYANIMALS'},
             // Non-existent label returns empty string
             {keyLabel: 'ThisKeyLabelDoesntExist', expected: ''},
+            // Key with no labels still returns the key ID
+            {keyLabel: 'automation', expected: 'automation'},
         ]
         testCases.forEach(tc => {
             const tagValueID = Vocabulary.getTagKeyID(tc.keyLabel, vocabulary);
@@ -122,6 +194,8 @@ describe('Vocabulary', () => {
             {keyID: 'IDKEYANIMALS', valueLabel: 'Dinosaur', expected: ''},
             // Key ID unknown
             {keyID: 'IDNONSENSE', valueLabel: 'Does not matter', expected: ''},
+            // Value with no labels still returns the value ID
+            {keyID: 'automation', valueLabel: 'results', expected: 'results'},
         ]
         testCases.forEach(tc => {
             const tagValueID = Vocabulary.getTagValueID(tc.keyID, tc.valueLabel, vocabulary);