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

54 connector widget special chars #83

Closed
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## 0.2.5

* Automatically activate server extension
* Fixed error that broke `Delete` and `Connect` buttons on the Connector Widget
when special characters were included in the connection alias

## 0.2.4

Expand Down
22 changes: 22 additions & 0 deletions src/utils/helper-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Convert special characters to their ASCII number values.
*
* @param str Input string to be processed.
* @returns Input string with special characters replaced with
* their ASCII values.
*/
export const specialToASCII = (str: string): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let res = '';
for(let i = 0; i < str.length; i++) {
if(+str[i] || str[i].toLowerCase() !== str[i].toUpperCase()){
res += str[i];
continue;
}
else if (str[i] === ' ') {
res += '_';
continue;
}
res += str[i].charCodeAt(0);
};
return res;
};
7 changes: 4 additions & 3 deletions src/widgets/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

import { MODULE_NAME, MODULE_VERSION } from '../version';

import { specialToASCII } from '../utils/helper-functions';

// Import the CSS
import '../../style/connector.css';
Expand Down Expand Up @@ -155,7 +156,7 @@ export class ConnectorView extends DOMWidgetView {
// Draw connection buttons
connections.forEach((connection: Connection) => {
const { name } = connection;
const name_without_spaces = name.replace(/ /g, "_");
const name_without_spaces = specialToASCII(name)

const buttonContainer = document.createElement("DIV");
buttonContainer.className = "connection-button-container";
Expand Down Expand Up @@ -339,7 +340,7 @@ export class ConnectorView extends DOMWidgetView {
deleteConnectionMessage.querySelector(".actions").appendChild(deleteButton);

// hide controllers
const deleteConnBtn = this.el.querySelector(`#deleteConnBtn_${connection["name"].replace(/ /g, "_")}`);
const deleteConnBtn = this.el.querySelector(`#deleteConnBtn_${specialToASCII(connection["name"])}`);
const actionsContainer = <HTMLElement>deleteConnBtn.parentNode;
actionsContainer.style.display = "none"

Expand Down Expand Up @@ -635,7 +636,7 @@ export class ConnectorView extends DOMWidgetView {
buttonEl.classList.add("secondary");
});

const selectedButtonEl = (<HTMLButtonElement>this.el.querySelector(`#connBtn_${connectionName.replace(/ /g, "_")}`));
const selectedButtonEl = (<HTMLButtonElement>this.el.querySelector(`#connBtn_${specialToASCII(connectionName)}`));
selectedButtonEl.innerText = "Connected";
selectedButtonEl.classList.add("primary");
}
Expand Down
49 changes: 48 additions & 1 deletion ui-tests/tests/widget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,51 @@ test('test error if edit connection with existing name', async ({ page }) => {


await expect(page.locator('.user-error-message')).toContainText("A connection named 'default' already exists in your connections file");
});
});

const specialAliases = [
{alias: 'db', id: 'db'},
{alias: 'db with space', id: 'db_with_space'},
{alias: 'db?', id: 'db63'},
{alias: 'db://', id: 'db584747'},
{alias: 'db! !', id: 'db33_33'},
{alias: ';db', id: '59db'},
{alias: ' db', id: '_db'},
]

for (const {alias, id} of specialAliases) {
test(`test delete button for aliases with special chars: ${alias}`, async ({ page }) => {
await displayWidget(page);

// create a new connection
await page.locator('#createNewConnection').click();
await page.locator('#connectionName').fill(alias);
await page.locator('#createConnectionFormButton').click();

// delete connection with special characters in alias
await page.locator(`#deleteConnBtn_${id}`).click();
await page.locator('#deleteConnectionButton').click();

expect(page.locator('#connectionsButtonsContainer')).toBeEmpty();

})
}

for (const {alias, id} of specialAliases) {
test(`test connect button for aliases with special chars: ${alias}`, async ({ page }) => {
// create default connection
await createDefaultConnection(page);

// create a new connection
await page.locator('#createNewConnection').click();
await page.locator('#connectionName').fill(alias);
await page.locator('#createConnectionFormButton').click();

// connect to default, then connect back to new connection
await page.locator('#connBtn_default').click();
await page.locator(`#connBtn_${id}`).click();

await page.locator(`#connBtn_${id}`).waitFor();
await expect(page.locator(`#connBtn_${id}`)).toContainText('Connected');
})
}
Loading