Skip to content

Commit

Permalink
Check typing char by char for job wizard inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyos committed Dec 6, 2019
1 parent 49471bd commit eb90bff
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
52 changes: 52 additions & 0 deletions test/functional/services/test_subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,58 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
});
}

public async setValueWithChecks(
selector: string,
text: string,
options: SetValueOptions = {}
): Promise<void> {
return await retry.try(async () => {
const { clearWithKeyboard = false, typeCharByChar = false } = options;
log.debug(`TestSubjects.setValueWithChecks(${selector}, ${text})`);
await this.click(selector);
// in case the input element is actually a child of the testSubject, we
// call clearValue() and type() on the element that is focused after
// clicking on the testSubject
const input = await find.activeElement();

await retry.tryForTime(5000, async () => {
let currentValue = await input.getAttribute('value');
if (currentValue !== '') {
if (clearWithKeyboard === true) {
await input.clearValueWithKeyboard();
} else {
await input.clearValue();
}
currentValue = await input.getAttribute('value');
}

if (currentValue === '') {
return true;
} else {
throw new Error(`Expected input to be empty, but got value '${currentValue}'`);
}
});

for (const chr of text) {
await retry.tryForTime(5000, async () => {
const oldValue = await input.getAttribute('value');
await input.type(chr, { charByChar: typeCharByChar });

await retry.tryForTime(1000, async () => {
const newValue = await input.getAttribute('value');
if (newValue === `${oldValue}${chr}`) {
return true;
} else {
throw new Error(
`After typing character '${chr}', the new value in the input should be '${oldValue}${chr}' (got ${newValue})`
);
}
});
});
}
});
}

public async selectValue(selector: string, value: string): Promise<void> {
await find.selectValue(`[data-test-subj="${selector}"]`, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function({ loadTestFile }: FtrProviderContext) {
describe('anomaly detection', function() {
// eslint-disable-next-line ban/ban
describe.only('anomaly detection', function() {
this.tags(['skipFirefox']);

loadTestFile(require.resolve('./single_metric_job'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},

async setQueryDelay(queryDelay: string) {
await testSubjects.setValue('mlJobWizardInputQueryDelay', queryDelay, {
await testSubjects.setValueWithChecks('mlJobWizardInputQueryDelay', queryDelay, {
clearWithKeyboard: true,
typeCharByChar: true,
});
Expand All @@ -61,7 +61,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},

async setFrequency(frequency: string) {
await testSubjects.setValue('mlJobWizardInputFrequency', frequency, {
await testSubjects.setValueWithChecks('mlJobWizardInputFrequency', frequency, {
clearWithKeyboard: true,
typeCharByChar: true,
});
Expand All @@ -78,7 +78,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},

async setScrollSize(scrollSize: string) {
await testSubjects.setValue('mlJobWizardInputScrollSize', scrollSize, {
await testSubjects.setValueWithChecks('mlJobWizardInputScrollSize', scrollSize, {
clearWithKeyboard: true,
typeCharByChar: true,
});
Expand Down Expand Up @@ -257,7 +257,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},

async setDetectorDescription(description: string) {
await testSubjects.setValue('mlAdvancedDetectorDescriptionInput', description, {
await testSubjects.setValueWithChecks('mlAdvancedDetectorDescriptionInput', description, {
clearWithKeyboard: true,
});
await this.assertDetectorDescriptionValue(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function MachineLearningJobWizardCommonProvider({ getService }: FtrProvid
},

async setBucketSpan(bucketSpan: string) {
await testSubjects.setValue('mlJobWizardInputBucketSpan', bucketSpan, {
await testSubjects.setValueWithChecks('mlJobWizardInputBucketSpan', bucketSpan, {
clearWithKeyboard: true,
typeCharByChar: true,
});
Expand All @@ -125,7 +125,9 @@ export function MachineLearningJobWizardCommonProvider({ getService }: FtrProvid
},

async setJobId(jobId: string) {
await testSubjects.setValue('mlJobWizardInputJobId', jobId, { clearWithKeyboard: true });
await testSubjects.setValueWithChecks('mlJobWizardInputJobId', jobId, {
clearWithKeyboard: true,
});
await this.assertJobIdValue(jobId);
},

Expand All @@ -141,7 +143,7 @@ export function MachineLearningJobWizardCommonProvider({ getService }: FtrProvid
},

async setJobDescription(jobDescription: string) {
await testSubjects.setValue('mlJobWizardInputJobDescription', jobDescription, {
await testSubjects.setValueWithChecks('mlJobWizardInputJobDescription', jobDescription, {
clearWithKeyboard: true,
});
await this.assertJobDescriptionValue(jobDescription);
Expand Down Expand Up @@ -285,7 +287,7 @@ export function MachineLearningJobWizardCommonProvider({ getService }: FtrProvid
await this.ensureAdvancedSectionOpen();
subj = advancedSectionSelector(subj);
}
await testSubjects.setValue(subj, modelMemoryLimit, { clearWithKeyboard: true });
await testSubjects.setValueWithChecks(subj, modelMemoryLimit, { clearWithKeyboard: true });
await this.assertModelMemoryLimitValue(modelMemoryLimit, {
withAdvancedSection: sectionOptions.withAdvancedSection,
});
Expand Down

0 comments on commit eb90bff

Please sign in to comment.