Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/web/src/stories/shared-schema-definition.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,12 @@ export const ParamsDialog = {
await expect(firstHelpIcon).toHaveAttribute('data-help-text', expect.stringContaining('Default: 1'));
await expect(dialogScope.getByRole('textbox', { name: /start value/i }).value).toBe('1');
await expect(dialogScope.getByRole('textbox', { name: /step value/i }).value).toBe('1');
const prefixInput = dialogScope.getByRole('textbox', { name: /prefix value/i });
let prefixInput = dialogScope.getByRole('textbox', { name: /prefix value/i });
await userEvent.click(prefixInput);
await waitFor(() => expect(document.activeElement).toBe(prefixInput));
await waitFor(() => {
prefixInput = dialogScope.getByRole('textbox', { name: /prefix value/i });
expect(document.activeElement).toBe(prefixInput);
});
await userEvent.clear(prefixInput);
await userEvent.type(prefixInput, 'filename');
await waitFor(() =>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"test:storybook": "node ./scripts/run-storybook-tests.mjs",
"test:ui:jest": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config ./jest.config.cjs --testPathPatterns packages/core-ui/src/tests apps/web/src/tests/jest",
"testenv:create": "node ./scripts/create-testenv.mjs",
"generate:faker-help": "node ./scripts/generate-faker-help.js",
"test:browser": "node ./node_modules/@playwright/test/cli.js test",
"test:browser:headed": "node ./node_modules/@playwright/test/cli.js test --headed",
"test:browser:install": "node ./node_modules/@playwright/test/cli.js install chromium",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDomainKeywordByCommand } from './domain-commands.js';
import { getDomainKeywordHelpByAlias } from '@anywaydata/core/domain/domain-keywords.js';

const ANYWAYDATA_DOMAIN_DOCS_BASE = 'https://anywaydata.com/docs/test-data/domain';

Expand Down Expand Up @@ -58,24 +58,20 @@ function getDomainCommandHelp(command) {
if (synthetic) {
return synthetic;
}
const keyword = getDomainKeywordByCommand(command);
if (!keyword) {
const commandHelp = getDomainKeywordHelpByAlias(command);
if (!commandHelp) {
return null;
}

return {
canonical: keyword.canonical,
summary: keyword.help?.summary || '',
docsUrl: resolveDomainDocsUrl(command, keyword.help?.docsUrl || ''),
example: keyword.help?.example || '',
examples: Array.isArray(keyword.help?.examples) ? keyword.help.examples : [],
exampleReturnValues: Array.isArray(keyword.help?.exampleReturnValues)
? keyword.help.exampleReturnValues
: Array.isArray(keyword.help?.returnExamples)
? keyword.help.returnExamples
: [],
returnType: keyword.help?.returnType || '',
args: Array.isArray(keyword.help?.args) ? keyword.help.args : [],
canonical: commandHelp.canonical,
summary: commandHelp.summary || '',
docsUrl: resolveDomainDocsUrl(command, commandHelp.docsUrl || ''),
example: commandHelp.example || '',
examples: Array.isArray(commandHelp.examples) ? commandHelp.examples : [],
exampleReturnValues: Array.isArray(commandHelp.exampleReturnValues) ? commandHelp.exampleReturnValues : [],
returnType: commandHelp.returnType || '',
args: Array.isArray(commandHelp.args) ? commandHelp.args : [],
};
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* - Keeps command help behavior unit-testable without booting full pages.
*/

import { getFakerCommandHelp } from '../../faker-command-help-metadata.js';
import { getFakerCommandHelp } from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';
import { getDomainCommandHelp } from '../../domain-command-help-metadata.js';
import { escapeHtml } from '../../html-escape.js';
import {
Expand Down Expand Up @@ -255,11 +255,7 @@ function buildSchemaHelpModel(sourceType, commandValue) {
params: normalizeHelpParams(commandHelp?.params || []),
example: commandHelp?.example || '',
examples: Array.isArray(commandHelp?.examples) ? commandHelp.examples : [],
exampleReturnValues: Array.isArray(commandHelp?.exampleReturnValues)
? commandHelp.exampleReturnValues
: Array.isArray(commandHelp?.returnExamples)
? commandHelp.returnExamples
: [],
exampleReturnValues: Array.isArray(commandHelp?.exampleReturnValues) ? commandHelp.exampleReturnValues : [],
};
}

Expand All @@ -283,11 +279,7 @@ function buildSchemaHelpModel(sourceType, commandValue) {
params: resolveDomainHelpParams(command, commandHelp),
example: commandHelp?.example || '',
examples: Array.isArray(commandHelp?.examples) ? commandHelp.examples : [],
exampleReturnValues: Array.isArray(commandHelp?.exampleReturnValues)
? commandHelp.exampleReturnValues
: Array.isArray(commandHelp?.returnExamples)
? commandHelp.returnExamples
: [],
exampleReturnValues: Array.isArray(commandHelp?.exampleReturnValues) ? commandHelp.exampleReturnValues : [],
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFakerCommandHelp } from '../../../../js/gui_components/shared/faker-command-help-metadata.js';
import { getFakerCommandHelp } from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';
import {
getKnownDomainCommandsAlphabetical,
getDomainKeywordByCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import RandExp from 'randexp';
import { TestDataGenerator } from '@anywaydata/core/data_generation/testDataGenerator.js';
import { Exporter } from '@anywaydata/core/grid/exporter.js';
import { createDataGeneratorPage } from '../../../../../js/gui_components/generator/runtime/create-generator-page.js';
import { getFakerCommandHelp } from '../../../../../js/gui_components/shared/faker-command-help-metadata.js';
import { getFakerCommandHelp } from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';
import { getDomainCommandHelp } from '../../../../../js/gui_components/shared/domain-command-help-metadata.js';
import { resolveFakerDocsUrl } from '../../../../../js/gui_components/shared/test-data/help/help-model-builder.js';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAllowedFakerCommandsAlphabetical } from '../../../../../js/gui_components/shared/faker-commands.js';
import { getFakerCommandHelp } from '../../../../../js/gui_components/shared/faker-command-help-metadata.js';
import { getFakerCommandHelp } from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';
import { faker } from '@faker-js/faker';
import RandExp from 'randexp';
import { TestDataGenerator } from '@anywaydata/core/data_generation/testDataGenerator.js';
Expand Down Expand Up @@ -29,6 +29,7 @@ import {
buildDataRuleFromSchemaRow,
} from '../../../../../js/gui_components/shared/schema-row-rule-mapper.js';
import { schemaRowsToDataRules, dataRulesToSchemaText } from '@anywaydata/core/data_generation/schema-rules-adapter.js';
import { hasPermissiveAllowedType } from '../../support/generated-value-quality.js';

const CUSTOM_SOURCE_TYPES = [
SOURCE_TYPE_ENUM,
Expand Down Expand Up @@ -750,7 +751,7 @@ function scenarioRowLooksValid(row, value) {
}

const allowedTypes = getAllowedTypesForScenarioRow(row);
if (allowedTypes.includes('string')) {
if (hasPermissiveAllowedType(allowedTypes)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getFakerCommandHelp } from '../../../../js/gui_components/shared/faker-command-help-metadata.js';
import { getFakerCommandHelp } from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';
import { getDomainCommandHelp } from '../../../../js/gui_components/shared/domain-command-help-metadata.js';
import {
SOURCE_TYPE_DOMAIN,
Expand Down Expand Up @@ -91,6 +91,10 @@ function getAllowedTypesForRow(row) {
}
}

function hasPermissiveAllowedType(allowedTypes) {
return allowedTypes.includes('string') || allowedTypes.includes('unknown');
}

function assertNoErrorIndicators(value, _contextLabel = 'value') {
const text = toSearchableText(value);
ERROR_PATTERNS.forEach((pattern) => {
Expand Down Expand Up @@ -147,7 +151,7 @@ function assertRowValueMatchesScenario(row, value, contextLabel) {

const allowedTypes = getAllowedTypesForRow(row);
const inferred = inferTypeAndConfidence(value);
if (inferred.confidence === 'high' && !allowedTypes.includes('string')) {
if (inferred.confidence === 'high' && !hasPermissiveAllowedType(allowedTypes)) {
expect(allowedTypes).toContain(inferred.type);
}
}
Expand All @@ -165,4 +169,9 @@ function assertScenarioDataQuality({ scenario, dataTable, exportedText = '', out
});
}

export { assertNoErrorIndicators, assertDataTableHasNoErrorIndicators, assertScenarioDataQuality };
export {
assertNoErrorIndicators,
assertDataTableHasNoErrorIndicators,
assertScenarioDataQuality,
hasPermissiveAllowedType,
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { KNOWN_FAKER_COMMANDS } from '../../../js/gui_components/shared/faker-commands.js';
import {
FAKER_COMMAND_HELP_METADATA,
getFakerCommandHelp,
} from '../../../js/gui_components/shared/faker-command-help-metadata.js';
FAKER_HELPER_KEYWORD_DEFINITIONS,
buildFakerHelperHelpMetadata,
} from '@anywaydata/core/faker/faker-helper-keyword-definitions.js';

describe('faker command help metadata', () => {
test('contains help entries for all curated faker commands', () => {
const fakerCommands = KNOWN_FAKER_COMMANDS.filter((command) => command !== 'RegEx');
test('contains direct metadata entries only for faker-only helper commands', () => {
const fakerCommands = KNOWN_FAKER_COMMANDS.filter((command) => command.startsWith('helpers.'));
expect(fakerCommands).toEqual(Object.keys(FAKER_HELPER_KEYWORD_DEFINITIONS));
const helperMetadata = buildFakerHelperHelpMetadata();
fakerCommands.forEach((command) => {
expect(FAKER_COMMAND_HELP_METADATA[command]).toBeDefined();
expect(helperMetadata[command]).toBeDefined();
});
expect(helperMetadata['person.firstName']).toBeUndefined();
});

test('normalizes helper metadata directly from helper definitions', () => {
const helperMetadata = buildFakerHelperHelpMetadata();
expect(Object.keys(helperMetadata)).toEqual(Object.keys(FAKER_HELPER_KEYWORD_DEFINITIONS));
});

test('contains docsUrl for all curated faker commands', () => {
Expand All @@ -34,29 +43,26 @@ describe('faker command help metadata', () => {
expect(helper.docsUrl).toBe('https://fakerjs.dev/api/helpers');
});

test('includes params when signatures are available and supports fallback summaries', () => {
test('falls back to domain keyword help for domain-backed faker commands', () => {
const firstName = getFakerCommandHelp('person.firstName');
const nestedPropertyAccess = getFakerCommandHelp('airline.airplane.name');
const imageDataUri = getFakerCommandHelp('image.dataUri');
const uuid = getFakerCommandHelp('string.uuid');

expect(firstName.params).toEqual(
expect.arrayContaining([
expect.objectContaining({ name: 'sex', optional: true, type: "'female' | 'generic' | 'male'" }),
])
expect.arrayContaining([expect.objectContaining({ name: 'sex', optional: true, type: 'string' })])
);
expect(firstName.example.length).toBeGreaterThan(0);
expect(buildFakerHelperHelpMetadata()['person.firstName']).toBeUndefined();

expect(imageDataUri.params).toEqual(
expect.arrayContaining([expect.objectContaining({ name: 'options', optional: true, type: 'object' })])
);
expect(Array.isArray(imageDataUri.params)).toBe(true);
expect(imageDataUri.example.length).toBeGreaterThan(0);

expect(uuid.summary).toContain('Returns a UUID');
expect(uuid.params).toEqual(
expect.arrayContaining([
expect.objectContaining({ name: 'version', optional: true, type: '4 | 7' }),
expect.objectContaining({ name: 'refDate', optional: true, type: 'string | Date | number' }),
expect.objectContaining({ name: 'version', optional: true, type: '4|7' }),
expect.objectContaining({ name: 'refDate', optional: true, type: 'string|number|date' }),
])
);
expect(uuid.params.find((param) => param.name === 'version')?.description).toContain(
Expand All @@ -75,6 +81,7 @@ describe('faker command help metadata', () => {
const mustache = getFakerCommandHelp('helpers.mustache');
const arrayElement = getFakerCommandHelp('helpers.arrayElement');
const rangeToNumber = getFakerCommandHelp('helpers.rangeToNumber');
const multiple = getFakerCommandHelp('helpers.multiple');

expect(mustache.summary).toContain('Replaces {{placeholder}} tokens');
expect(mustache.params).toEqual(
Expand All @@ -100,5 +107,7 @@ describe('faker command help metadata', () => {
);
expect(rangeToNumber.example).toBe('2');
expect(rangeToNumber.examples).toContain('helpers.rangeToNumber({ min: 1, max: 2 })');

expect(multiple.returnType).toBe('array');
});
});
24 changes: 24 additions & 0 deletions packages/core/js/domain/domain-keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ function getDomainKeywordByAlias(alias, index = DOMAIN_KEYWORD_ALIAS_INDEX) {
return index.byAlias[key];
}

function normalizeDomainKeywordHelp(keyword) {
if (!keyword) {
return null;
}

return {
canonical: String(keyword.canonical || '').trim(),
keyword: String(keyword.keyword || '').trim(),
summary: String(keyword.help?.summary || '').trim(),
docsUrl: String(keyword.help?.docsUrl || '').trim(),
example: String(keyword.help?.example || '').trim(),
examples: Array.isArray(keyword.help?.examples) ? keyword.help.examples : [],
exampleReturnValues: Array.isArray(keyword.help?.exampleReturnValues) ? keyword.help.exampleReturnValues : [],
returnType: String(keyword.help?.returnType || '').trim(),
args: Array.isArray(keyword.help?.args) ? keyword.help.args : [],
};
}

function getDomainKeywordHelpByAlias(alias, index = DOMAIN_KEYWORD_ALIAS_INDEX) {
return normalizeDomainKeywordHelp(getDomainKeywordByAlias(alias, index));
}

function runFakerDelegate(target, fakerInstance, args = [], resultPath = '') {
const parts = String(target || '')
.split('.')
Expand Down Expand Up @@ -348,4 +370,6 @@ export {
buildAliasCandidates,
getCommandFromCanonical,
getDomainKeywordByAlias,
getDomainKeywordHelpByAlias,
normalizeDomainKeywordHelp,
};
Loading