-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix copy link issue in Safari (#1633)
Signed-off-by: [email protected] <[email protected]> Signed-off-by: leanneeliatra <[email protected]> Signed-off-by: leanneeliatra <[email protected]> (cherry picked from commit 8f1334e)
- Loading branch information
1 parent
a77d969
commit 7927cbd
Showing
2 changed files
with
161 additions
and
42 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
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,102 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
// Import necessary modules and dependencies | ||
import { API_ENDPOINT_MULTITENANCY } from '../../apps/configuration/constants.tsx'; | ||
import { | ||
addTenantToShareURL, | ||
processCopyEvent, | ||
setClipboardAndTarget, | ||
updateClipboard, | ||
} from '../shared-link.ts'; | ||
|
||
describe('addTenantToShareURL function', () => { | ||
it('should add a listener for copy events', () => { | ||
const coreMock: any = { | ||
http: { | ||
get: jest.fn().mockResolvedValue('mocked-tenant'), | ||
}, | ||
}; | ||
|
||
jest.spyOn(document, 'addEventListener').mockImplementation((event, callback) => { | ||
if (event === 'copy') { | ||
callback(new Event('copy')); | ||
expect(coreMock.http.get).toHaveBeenCalledWith(API_ENDPOINT_MULTITENANCY); | ||
} | ||
}); | ||
addTenantToShareURL(coreMock); | ||
}); | ||
}); | ||
|
||
describe('processCopyEvent function', () => { | ||
it('should update the clipboard and target text content', () => { | ||
const shareButtonMock: any = { | ||
getAttribute: jest.fn().mockReturnValue('mocked-share-url'), | ||
}; | ||
|
||
const targetMock: any = { | ||
textContent: 'mocked-text-content', | ||
}; | ||
|
||
jest.spyOn(document, 'querySelector').mockImplementation((selector) => { | ||
if (selector === '[data-share-url]') { | ||
return shareButtonMock; | ||
} else if (selector === 'body > span') { | ||
return targetMock; | ||
} | ||
}); | ||
|
||
jest.spyOn(document, 'createRange').mockReturnValue({ | ||
selectNode: jest.fn(), | ||
} as any); | ||
|
||
processCopyEvent('mocked-tenant'); | ||
}); | ||
}); | ||
|
||
describe('updateClipboard function', () => { | ||
it('should update the clipboard and target text content', () => { | ||
const shareButtonMock: any = { | ||
getAttribute: jest.fn().mockReturnValue('mocked-share-url'), | ||
removeAllRanges: jest.fn(), | ||
addRange: jest.fn(), | ||
}; | ||
|
||
const targetMock: any = { | ||
textContent: 'mocked-text-content', | ||
}; | ||
|
||
jest.spyOn(document, 'querySelector').mockImplementation((selector) => { | ||
if (selector === '[data-share-url]') { | ||
return shareButtonMock; | ||
} else if (selector === 'body > span') { | ||
return targetMock; | ||
} | ||
}); | ||
updateClipboard('mocked-url-part', 'mocked-original-value', 'mocked-tenant'); | ||
}); | ||
}); | ||
describe('setClipboardAndTarget function', () => { | ||
it('should set clipboard and target correctly', () => { | ||
const shareButtonMock: any = { | ||
removeAllRanges: jest.fn(), | ||
addRange: jest.fn(), | ||
}; | ||
|
||
const targetMock: any = { | ||
textContent: 'mocked-text-content', | ||
}; | ||
setClipboardAndTarget(shareButtonMock, targetMock, 'mocked-new-value', 'mocked-original-value'); | ||
}); | ||
}); |