-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1712 from jdi-testing/issue_1655-bug-with-locator…
…-data-in-edit-modal Issue 1655: bug with locator data in edit modal
- Loading branch information
Showing
6 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { escapeLocatorString } from '../../../features/locators/utils/escapeLocatorString'; | ||
|
||
describe('escapeLocatorString', () => { | ||
describe('should properly escape, when received', () => { | ||
it('strings with double quotes', () => { | ||
expect(escapeLocatorString('He said "Hello"')).toBe('He said \\"Hello\\"'); | ||
}); | ||
|
||
it('strings with single quotes', () => { | ||
expect(escapeLocatorString("It's a test")).toBe("It\\'s a test"); | ||
}); | ||
|
||
it('strings with backslashes', () => { | ||
expect(escapeLocatorString('Path\\to\\file')).toBe('Path\\\\to\\\\file'); | ||
}); | ||
|
||
it('strings with mixed special characters', () => { | ||
expect(escapeLocatorString('He said "It\'s alright"')).toBe('He said \\"It\\\'s alright\\"'); | ||
}); | ||
|
||
it('JSON strings', () => { | ||
const input = '{"category":"Header","action":"go to dashboard","label":"icon:logo"}'; | ||
const expected = '{\\"category\\":\\"Header\\",\\"action\\":\\"go to dashboard\\",\\"label\\":\\"icon:logo\\"}'; | ||
expect(escapeLocatorString(input)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe("shouldn't change", () => { | ||
it('string without special characters', () => { | ||
const normalString = 'Just a normal string'; | ||
expect(escapeLocatorString(normalString)).toBe(normalString); | ||
}); | ||
|
||
it('empty strings', () => { | ||
expect(escapeLocatorString('')).toBe(''); | ||
}); | ||
|
||
it('URL strings', () => { | ||
const UrlString = '/orgs/jdi-testing/hovercard'; | ||
expect(escapeLocatorString(UrlString)).toBe(UrlString); | ||
}); | ||
}); | ||
|
||
// tests for invalid data types: | ||
describe('should throw an error or handle, when received', () => { | ||
it('objects', () => { | ||
const obj = { key: 'value' }; | ||
expect(() => escapeLocatorString(obj as any)).toThrow(); | ||
}); | ||
|
||
it('arrays', () => { | ||
const arr = ['text1', 'text2']; | ||
expect(() => escapeLocatorString(arr as any)).toThrow(); | ||
}); | ||
|
||
it('null', () => { | ||
expect(() => escapeLocatorString(null as any)).toThrow(); | ||
}); | ||
|
||
it('undefined', () => { | ||
expect(() => escapeLocatorString(undefined as any)).toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const escapeLocatorString = (selector: string): string => { | ||
return selector.replace(/(["'\\])/g, '\\$1'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters