Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add manual test case and meaningful ids #725

Merged
merged 4 commits into from
Aug 22, 2024
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: 7 additions & 0 deletions .changeset/fast-tomatoes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/xml-views-quick-fix": patch
---

fix: add manual test case and meaningful ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Property binding info

## Associated user stories:

[#646](https://github.com/SAP/ui5-language-assistant/issues/646) Generate ID's: make this unique for a whole project

## Install latest UI5 Language Assistant

[UI5 Language Assistant](https://marketplace.visualstudio.com/items?itemName=SAPOSS.vscode-ui5-language-assistant)

## Test project

1. Prepare an UI5 Project
- Your project or
- Clone [ui5-language-assistant](https://github.com/SAP/ui5-language-assistant) repo and open `test-packages/framework/projects/cap`
2. Launch VSCode and open project root folder
3. Install project dependencies using command `npm install`

**Note:** For this manual test, we use `test-packages/framework/projects/cap` project

## Diagnostic

1. Open `Main.view.xml` file which is located under `app/manage_travels/webapp/ext/main` folder
2. Copy and paste snippet below inside `<Content>` tag

```xml
<Text id="_IDGenText" >
<Button id="_IDGenButton" />
```

3. Check that no diagnostic is reported as there is not duplicate id
4. Create a new file e.g `MyTest.view.xml` under webapp and copy paste content of `Main.view.xml` file in `MyTest.view.xml`
5. Check that diagnostics are reported for duplicate ids. e.g `Main`
6. Remove `MyTest.view.xml` file
7. Check that no diagnostic is reported as duplicate ids are removed

##### Note

You can navigate to related file where identical ids are used

## Quick fix

1. Open `Main.view.xml` file which is located under `app/manage_travels/webapp/ext/main` folder
2. Copy and paste snippet below inside `<Content>` tag

```xml
<Text >
<Text >
<Button id="" />
```

3. Diagnostic is reported for missing id e.g `The "Text" class can't have an empty ID attribute when flexEnabled is "true" in manifest.json.`
4. Click on `Text` tag. Light bulb appears
5. Click on light bulb. Two options are displayed. `Generate a unique ID` and `Generate unique IDs for the entire file`
6. Click on `Generate a unique ID`. Unique Id is generated. This ID is unique for entire app
7. Click on `Button` tag. Light bulb appears
8. Click on light bulb and select `Generate unique IDs for the entire file`. Unique Ids are generated. These IDs are unique for entire app
13 changes: 7 additions & 6 deletions packages/xml-views-quick-fix/src/quick-fix-stable-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ function getUniqueId(
suffix = 0
): string {
if (existingIds[newId]) {
const lastChar = Number(newId.slice(-1));
if (!isNaN(lastChar)) {
// last char is number
suffix = lastChar + 1;
// remove last char
newId = newId.slice(0, -1);
const match = newId.match(/(\d{1,10})$/);
if (match) {
const num = Number(match[0]);
const len = match[0].length;
// remove number char(s) from end
newId = newId.slice(0, -len);
suffix = num + 1;
} else {
suffix = suffix + 1;
}
Expand Down
Loading