blob: 0c4e3aeb68cbd41eedcbe8b0b2caeb68d0a2d771 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6import {MrAutocomplete} from './mr-autocomplete.js';
7
8let element;
9
10describe('mr-autocomplete', () => {
11 beforeEach(() => {
12 element = document.createElement('mr-autocomplete');
13 document.body.appendChild(element);
14 });
15
16 afterEach(() => {
17 document.body.removeChild(element);
18 });
19
20 it('initializes', () => {
21 assert.instanceOf(element, MrAutocomplete);
22 });
23
24 it('sets properties based on vocabularies', async () => {
25 assert.deepEqual(element.strings, []);
26 assert.deepEqual(element.docDict, {});
27
28 element.vocabularies = {
29 'project': {
30 'strings': ['chromium', 'v8'],
31 'docDict': {'chromium': 'move the web forward'},
32 },
33 };
34
35 element.vocabularyName = 'project';
36
37 await element.updateComplete;
38
39 assert.deepEqual(element.strings, ['chromium', 'v8']);
40 assert.deepEqual(element.docDict, {'chromium': 'move the web forward'});
41 });
42
43 it('_setupProjectVocabulary', () => {
44 assert.deepEqual(element._setupProjectVocabulary({}), {strings: []});
45
46 assert.deepEqual(element._setupProjectVocabulary({
47 ownerOf: ['chromium'],
48 memberOf: ['skia'],
49 contributorTo: ['v8'],
50 }), {strings: ['chromium', 'skia', 'v8']});
51 });
52
53 it('_setupMemberVocabulary', () => {
54 assert.deepEqual(element._setupMemberVocabulary({}), {strings: []});
55
56 assert.deepEqual(element._setupMemberVocabulary({
57 userRefs: [
58 {displayName: 'group@example.com', userId: '100'},
59 {displayName: 'test@example.com', userId: '123'},
60 {displayName: 'test2@example.com', userId: '543'},
61 ],
62 groupRefs: [
63 {displayName: 'group@example.com', userId: '100'},
64 ],
65 }), {strings:
66 ['group@example.com', 'test@example.com', 'test2@example.com'],
67 });
68 });
69
70 it('_setupOwnerVocabulary', () => {
71 assert.deepEqual(element._setupOwnerVocabulary({}), {strings: []});
72
73 assert.deepEqual(element._setupOwnerVocabulary({
74 userRefs: [
75 {displayName: 'group@example.com', userId: '100'},
76 {displayName: 'test@example.com', userId: '123'},
77 {displayName: 'test2@example.com', userId: '543'},
78 ],
79 groupRefs: [
80 {displayName: 'group@example.com', userId: '100'},
81 ],
82 }), {strings:
83 ['test@example.com', 'test2@example.com'],
84 });
85 });
86});