Skip to content

Commit 4d0bb14

Browse files
committed
Code style changes.
- Invert negative connotation of variables for improved readability. - Return null instead of undefined from validators. - Extract Jest test component instantiation into beforeEach.
1 parent 2687a16 commit 4d0bb14

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

x-pack/plugins/remote_clusters/public/sections/components/remote_cluster_form/remote_cluster_form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const RemoteClusterForm = injectI18n(
203203
hasErrors = () => {
204204
const { fieldsErrors, localSeedErrors } = this.state;
205205
const errorValues = Object.values(fieldsErrors);
206-
const hasErrors = errorValues.some(error => error !== undefined) || localSeedErrors.length;
206+
const hasErrors = errorValues.some(error => error != null) || localSeedErrors.length;
207207
return hasErrors;
208208
};
209209

x-pack/plugins/remote_clusters/public/sections/components/remote_cluster_form/validators/validate_name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export function validateName(name) {
2626
);
2727
}
2828

29-
return undefined;
29+
return null;
3030
}

x-pack/plugins/remote_clusters/public/sections/components/remote_cluster_form/validators/validate_seed.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export function validateSeed(seed) {
1818
return errors;
1919
}
2020

21-
const isInvalid = !isSeedNodeValid(seed);
21+
const isValid = isSeedNodeValid(seed);
2222

23-
if (isInvalid) {
23+
if (!isValid) {
2424
errors.push(i18n.translate(
2525
'xpack.remoteClusters.remoteClusterForm.localSeedError.invalidCharactersMessage',
2626
{
@@ -30,9 +30,9 @@ export function validateSeed(seed) {
3030
));
3131
}
3232

33-
const isPortInvalid = !isSeedNodePortValid(seed);
33+
const isPortValid = isSeedNodePortValid(seed);
3434

35-
if (isPortInvalid) {
35+
if (!isPortValid) {
3636
errors.push(i18n.translate(
3737
'xpack.remoteClusters.remoteClusterForm.localSeedError.invalidPortMessage',
3838
{

x-pack/plugins/remote_clusters/public/sections/components/remote_cluster_form/validators/validate_seeds.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export function validateSeeds(seeds, seedInput) {
1111
const seedsHaveBeenCreated = seeds.some(seed => Boolean(seed.trim()));
1212

1313
if (seedsHaveBeenCreated) {
14-
return undefined;
14+
return null;
1515
}
1616

1717
// If the user hasn't entered any seeds then we only want to prompt them for some if they
1818
// aren't already in the process of entering one in. In this case, we'll just show the
1919
// combobox-specific validation.
2020
if (seedInput) {
21-
return undefined;
21+
return null;
2222
}
2323

2424
return (

x-pack/plugins/remote_clusters/public/sections/components/remote_cluster_form/validators/validate_seeds.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ describe('validateSeeds', () => {
1212
});
1313

1414
test(`accepts empty seeds when there's input`, () => {
15-
expect(validateSeeds([], 'input')).toBe(undefined);
15+
expect(validateSeeds([], 'input')).toBe(null);
1616
});
1717

1818
test(`accepts existing seeds`, () => {
19-
expect(validateSeeds(['seed'])).toBe(undefined);
19+
expect(validateSeeds(['seed'])).toBe(null);
2020
});
2121
});

x-pack/plugins/remote_clusters/public/sections/remote_cluster_list/remote_cluster_table/remote_cluster_table.test.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,27 @@ describe('RemoteClusterTable', () => {
6969
seeds: ['seed'],
7070
}];
7171

72-
test('name link opens detail panel when clicked', () => {
73-
const component = mountWithIntl(
72+
let component;
73+
74+
beforeEach(() => {
75+
component = mountWithIntl(
7476
<Provider store={remoteClustersStore}>
7577
<RemoteClusterTable
7678
clusters={clusters}
7779
openDetailPanel={() => {}}
7880
/>
7981
</Provider>
8082
);
83+
});
8184

85+
test('name link opens detail panel when clicked', () => {
8286
const rowName = findTestSubject(component, `remoteClusterTableRowName-${name}`);
8387
rowName.simulate('click');
8488
const detailPanel = findTestSubject(component, 'remoteClusterDetailFlyout');
8589
expect(detailPanel).toBeTruthy();
8690
});
8791

8892
test('remove button displays a confirmation modal when clicked', () => {
89-
const component = mountWithIntl(
90-
<Provider store={remoteClustersStore}>
91-
<RemoteClusterTable
92-
clusters={clusters}
93-
openDetailPanel={() => {}}
94-
/>
95-
</Provider>
96-
);
97-
9893
const removeButton = findTestSubject(component, `remoteClusterTableRowRemoveButton-${name}`);
9994
removeButton.simulate('click');
10095
const confirmModal = findTestSubject(component, 'remoteClustersDeleteConfirmModal');

0 commit comments

Comments
 (0)