Skip to content

Commit

Permalink
fix: adapt test case and adress sonar cloud issue
Browse files Browse the repository at this point in the history
  • Loading branch information
marufrasully committed Apr 26, 2024
1 parent 6faa936 commit 77ab880
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
8 changes: 4 additions & 4 deletions packages/fe/src/services/completion/providers/meta-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function metaPathSuggestions({
);
baseType = base?.entityType;
}
let isCollection;
let isCollection: boolean | undefined;

// for (navigation) property segment or annotation term
if (!isAbsolutePath && completionSegmentIndex > 0) {
Expand All @@ -147,7 +147,7 @@ export function metaPathSuggestions({
({
target: base,
targetStructuredType: baseType,
isCollection: isCollection,
isCollection,
} = resolvePathTarget(metadata, contextToConsider, baseType));
if (!base) {
// target not resolved e.g. for wrong nav segment - no further segments possible
Expand All @@ -159,7 +159,7 @@ export function metaPathSuggestions({
({
target: base,
targetStructuredType: baseType,
isCollection: isCollection,
isCollection,
} = resolvePathTarget(metadata, normalizePath(contextPath)));
}

Expand Down Expand Up @@ -195,7 +195,7 @@ export function metaPathSuggestions({
// for first path segment completion, where current base can be entity set or singleton,
// we collect also terms applied on their structural entity type

// targetStructuredType is never undefined in this context
// baseType is never undefined in this context
annotationList.push(
...collectAnnotationsForElement(expectedAnnotations, baseType)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,18 @@ export function validateUnknownAnnotationPath(
];
}

base = base as Exclude<ResolvedPathTargetType, Property>;
const baseEntity =
segments.length === 0
? (base as Exclude<ResolvedPathTargetType, Property>)
: targetEntity;

const termSegment = originalSegments[termSegmentIndex];
const parts = termSegment.split("@");
let annotations: AnnotationBase[] | undefined;

annotations = getAnnotationAppliedOnElement(
expectedAnnotations,
segments.length === 0 ? base : targetEntity,
baseEntity,
parts[0]
);

Expand All @@ -282,19 +286,15 @@ export function validateUnknownAnnotationPath(
} else {
// check whether the provided term exists on target
const term: AnnotationTerm = fullyQualifiedNameToTerm(parts[1]);
annotations = getAnnotationAppliedOnElement(
[term],
segments.length === 0 ? base : targetEntity,
parts[0]
);
annotations = getAnnotationAppliedOnElement([term], baseEntity, parts[0]);
const match = annotations.find(
(anno) => composeAnnotationPath(anno) === "@" + parts[1]
);
if (match) {
// determine whether any allowed term exists in the project suitable for the current context
annotations = getAnnotationAppliedOnElement(
expectedAnnotations,
segments.length === 0 ? base : targetEntity
baseEntity
);

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe("metaPath attribute value validation (annotation path)", () => {
);
expect(result.length).toEqual(0);
});

it("is absolute path", async function () {
const result = await validateView(
`<macros:Chart metaPath="/Booking/to_Travel/@com.sap.vocabularies.UI.v1.Chart#sample1"></macros:Chart>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,17 @@ annotate service.Travel with @(
2. Observe diagnostics warning: `Annotation path value cannot be empty`.
3. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample`. Observe warning message `Unknown annotation path: "/Travel/@com.sap.vocabularies.UI.v1.Chart#sample"`.
4. Set the metaPath attribute value as `to_Booking`. Observe warning message `Path value must end with annotation term. Use code completion to select annotation path`.
5. Set the metaPath attribute value as `/Travel/@com.sap.vocabularies.UI.v1.Chart#sample1`. Observe warning message `Absolute annotation paths not allowed in metaPath. Use contextPath attribute to change path context`
6. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.LineItem`. Observe warning message `Invalid annotation term: "@com.sap.vocabularies.UI.v1.LineItem". Trigger code completion to choose one of allowed annotations`.
7. Go to app manifest file, find `routing\targets\TravelMain` settings entry and rename `entitySet` property in the nested object structure to `entitySet_`. Save the file.
8. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample1`. Observe info message `EntitySet or contextPath for the current view are not defined in application manifest. Attribute value completion and diagnostics is not possible if EntitySet or contextPath are not defined or defined dynamically in controllers`.
9. Revert manifest change that is done at previous step 7. Change property `entitySet` value to `Travel_`. Save the file.
10. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample`. Observe info message `Entity Set "Travel_" specified in manifest for the current view is not found. Attribute value completion and diagnostics are disabled`.
11. Reset property `entitySet` value to `Travel` in app manifest. Save the file.
12. Replace current macros element with the snippet:
5. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.LineItem`. Observe warning message `Invalid annotation term: "@com.sap.vocabularies.UI.v1.LineItem". Trigger code completion to choose one of allowed annotations`.
6. Go to app manifest file, find `routing\targets\TravelMain` settings entry and rename `entitySet` property in the nested object structure to `entitySet_`. Save the file.
7. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample1`. Observe info message `EntitySet or contextPath for the current view are not defined in application manifest. Attribute value completion and diagnostics is not possible if EntitySet or contextPath are not defined or defined dynamically in controllers`.
8. Revert manifest change that is done at previous step 7. Change property `entitySet` value to `Travel_`. Save the file.
9. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample`. Observe info message `Entity Set "Travel_" specified in manifest for the current view is not found. Attribute value completion and diagnostics are disabled`.
10. Reset property `entitySet` value to `Travel` in app manifest. Save the file.
11. Replace current macros element with the snippet:

```XML
<macros:Chart contextPath="/TravelService.EntityContainer/Travel" metaPath="" id="chart1" />
```

13. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#sample`. Observe warning message `Unknown annotation path: "/TravelService.EntityContainer/Travel/@com.sap.vocabularies.UI.v1.Chart#sample`.
14. Set the metaPath attribute value as `to_Booking/@com.sap.vocabularies.UI.v1.Chart#sample`. Observe warning message `Navigation segments not allowed when contextPath is provided`.
13. Set the metaPath attribute value as `@com.sap.vocabularies.UI.v1.Chart#notDefined`. Observe warning message `Unknown annotation path: "/TravelService.EntityContainer/Travel/@com.sap.vocabularies.UI.v1.Chart#notDefined`.
14. Set the metaPath attribute value as `to_Booking/@com.sap.vocabularies.UI.v1.Chart#sample1`. Observe warning message `Navigation segments not allowed when contextPath is provided`.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ Associated user stories:
```

4. Place the cursor at the position of the `metaPath` attribute value and trigger code completion.
5. Observe the list of suggestions for the first path segment. Make sure that properties of the current default entity set `Travel` specified in manifest go first in the list and followed by possible navigation segments. Choose first property and press `Enter`. Observe no error messages are shown for the attribute value.
5. Observe the list of suggestions for the first path segment. Make sure that list is sort as:

- properties of the current default entity set `Travel` specified in manifest
- navigation segments
- entity types with absolute path
- entity sets
- entity container

Choose first property and press `Enter`. Observe no error messages are shown for the attribute value.

6. Place cursor at value's first position and trigger code completion. Choose option `to_Booking` and press `/` to confirm. Observe the segment is added, and completion for next segment is triggered. Choose navigation property `to_Travel` and press `/` to confirm. Observe `Travel` properties are listed and further navigation segment `to_Booking` is not available to avoid cyclic routes. Choose first property and press `Enter`. Observe no error messages are shown for the attribute value.
7. Remove entire current element and place following snippet instead:

Expand Down

0 comments on commit 77ab880

Please sign in to comment.