-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNameAndLinkingOptions.test.tsx
More file actions
169 lines (146 loc) · 6.37 KB
/
NameAndLinkingOptions.test.tsx
File metadata and controls
169 lines (146 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React from 'react';
import { render } from '@testing-library/react';
import { createFormInputId } from './utils';
import {
CALCULATED_CONCEPT_URI,
DOMAIN_FIELD_DESCRIPTION,
DOMAIN_FIELD_FULLY_LOCKED,
DOMAIN_FIELD_IMPORTALIASES,
DOMAIN_FIELD_LABEL,
DOMAIN_FIELD_ONTOLOGY_PRINCIPAL_CONCEPT,
DOMAIN_FIELD_URL,
DOMAIN_FIELD_URL_TARGET,
STORAGE_UNIQUE_ID_CONCEPT_URI,
STRING_RANGE_URI,
} from './constants';
import { DomainField } from './models';
import { NameAndLinkingOptions } from './NameAndLinkingOptions';
const _description = 'This is a description';
const _label = 'This is a label';
const _importAliases = 'This is an alias';
const _URL = 'This is a URL';
const field = DomainField.create({
name: 'key',
rangeURI: STRING_RANGE_URI,
propertyId: 1,
description: _description,
label: _label,
importAliases: _importAliases,
URL: _URL,
URLTarget: '_blank',
propertyURI: 'test',
});
const uniqueIdField = DomainField.create({
name: 'uniqueId',
rangeURI: STRING_RANGE_URI,
propertyId: 2,
description: 'test uniqueId',
label: 'UniqueId label',
conceptURI: STORAGE_UNIQUE_ID_CONCEPT_URI,
});
const calculatedField = DomainField.create({
name: 'calcField',
rangeURI: STRING_RANGE_URI,
propertyId: 2,
description: 'test calc',
label: 'Calc label',
conceptURI: CALCULATED_CONCEPT_URI,
});
const lockedField = DomainField.create({
name: 'lockedField',
rangeURI: STRING_RANGE_URI,
propertyId: 3,
description: 'locked field desc',
label: 'Locked Field',
lockType: DOMAIN_FIELD_FULLY_LOCKED,
});
const DEFAULT_PROPS = {
index: 1,
domainIndex: 1,
field,
onChange: jest.fn,
appPropertiesOnly: false,
serverModuleNames: undefined,
};
describe('NameAndLinkingOptions', () => {
test('Name and Linking options', () => {
const container = render(<NameAndLinkingOptions {...DEFAULT_PROPS} />).container;
// Verify section label
const sectionLabel = document.querySelectorAll('.domain-field-section-heading');
expect(sectionLabel.length).toEqual(1);
expect(sectionLabel[0].textContent).toEqual('Name and Linking Options');
// Verify values
// Description
let formField = document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_DESCRIPTION, 1, 1));
expect(formField.length).toEqual(1);
expect(formField[0].textContent).toEqual(_description);
expect(formField[0].hasAttribute('disabled')).toEqual(false);
// Label
formField = document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_LABEL, 1, 1));
expect(formField.length).toEqual(1);
expect(formField[0].getAttribute('value')).toEqual(_label);
expect(formField[0].hasAttribute('disabled')).toEqual(false);
// Aliases
formField = document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_IMPORTALIASES, 1, 1));
expect(formField.length).toEqual(1);
expect(formField[0].getAttribute('value')).toEqual(_importAliases);
expect(formField[0].hasAttribute('disabled')).toEqual(false);
// URL
formField = document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_URL, 1, 1));
expect(formField.length).toEqual(1);
expect(formField[0].getAttribute('value')).toEqual(_URL);
expect(formField[0].hasAttribute('disabled')).toEqual(false);
// URL Target
formField = document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_URL_TARGET, 1, 1));
expect(formField.length).toEqual(1);
expect(formField[0].hasAttribute('checked')).toEqual(true);
expect(formField[0].hasAttribute('disabled')).toEqual(false);
expect(container).toMatchSnapshot();
});
test('appPropertiesOnly without ontology module', () => {
render(<NameAndLinkingOptions {...DEFAULT_PROPS} appPropertiesOnly={true} />);
expect(
document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_ONTOLOGY_PRINCIPAL_CONCEPT, 1, 1))
).toHaveLength(0);
});
test('appPropertiesOnly with ontology module', () => {
LABKEY.moduleContext = {
api: {
moduleNames: ['ontology'],
},
};
render(<NameAndLinkingOptions {...DEFAULT_PROPS} appPropertiesOnly={false} />);
expect(
document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_ONTOLOGY_PRINCIPAL_CONCEPT, 1, 1))
).toHaveLength(1);
});
test('uniqueId field', () => {
render(<NameAndLinkingOptions {...DEFAULT_PROPS} field={uniqueIdField} />);
expect(document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_IMPORTALIASES, 1, 1))).toHaveLength(0);
});
test('calculated field', () => {
render(<NameAndLinkingOptions {...DEFAULT_PROPS} field={calculatedField} />);
expect(document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_IMPORTALIASES, 1, 1))).toHaveLength(0);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_URL, 1, 1)).getAttribute('value')).toEqual('');
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_URL_TARGET, 1, 1)).hasAttribute('checked')).toEqual(false);
});
test('hideImportAliases', () => {
render(
<NameAndLinkingOptions
{...DEFAULT_PROPS}
domainFormDisplayOptions={{
hideImportAliases: true,
}}
/>
);
expect(document.querySelectorAll('#' + createFormInputId(DOMAIN_FIELD_IMPORTALIASES, 1, 1))).toHaveLength(0);
});
test('locked field', () => {
render(<NameAndLinkingOptions {...DEFAULT_PROPS} field={lockedField} />);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_LABEL, 1, 1)).hasAttribute('disabled')).toEqual(true);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_DESCRIPTION, 1, 1)).hasAttribute('disabled')).toEqual(true);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_IMPORTALIASES, 1, 1)).hasAttribute('disabled')).toEqual(true);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_URL, 1, 1)).hasAttribute('disabled')).toEqual(true);
expect(document.querySelector('#' + createFormInputId(DOMAIN_FIELD_URL_TARGET, 1, 1)).hasAttribute('disabled')).toEqual(true);
});
});