-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ find in page (global keyboard shortcuts) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page (main) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page (webpack) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page (constants) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page (components) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page (tab-manager) Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page Signed-off-by: Marc Nuri <[email protected]> * ✨ find in page Signed-off-by: Marc Nuri <[email protected]> --------- Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
29 changed files
with
825 additions
and
61 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
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
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
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
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
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
110 changes: 110 additions & 0 deletions
110
src/find-in-page/__tests__/find-in-page.browser.test.mjs
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,110 @@ | ||
/* | ||
Copyright 2024 Marc Nuri San Felix | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 {jest} from '@jest/globals'; | ||
import {loadDOM} from '../../__tests__/index.mjs'; | ||
import {getByTestId, fireEvent, waitFor} from '@testing-library/dom'; | ||
|
||
describe('Find in Page :: in browser test suite', () => { | ||
let onFindInPageCallback; | ||
beforeEach(async () => { | ||
jest.resetModules(); | ||
window.electron = { | ||
close: jest.fn(), | ||
findInPage: jest.fn(), | ||
onFindInPage: jest.fn(callback => { | ||
onFindInPageCallback = callback; | ||
}) | ||
}; | ||
await loadDOM({meta: import.meta, path: ['..', 'index.html']}); | ||
}); | ||
describe.each([ | ||
{testId: 'find-previous', icon: '\ue316', title: 'Previous', expectedFunction: 'findInPage'}, | ||
{testId: 'find-next', icon: '\ue313', title: 'Next', expectedFunction: 'findInPage'}, | ||
{testId: 'close', icon: '\ue5cd', title: 'Close', expectedFunction: 'close'} | ||
])('Has Icon button $testId entry', ({testId, icon, title, expectedFunction}) => { | ||
let $iconButton; | ||
beforeEach(() => { | ||
$iconButton = getByTestId(document, testId); | ||
}); | ||
test(`should have icon ${icon}`, () => { | ||
expect($iconButton.textContent).toBe(icon); | ||
}); | ||
test(`should have title ${icon}`, () => { | ||
expect($iconButton.getAttribute('title')).toBe(title); | ||
}); | ||
test('click, should invoke function', () => { | ||
// When | ||
fireEvent.click($iconButton); | ||
// Then | ||
expect(window.electron[expectedFunction]).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
describe('Input field', () => { | ||
let $input; | ||
beforeEach(() => { | ||
$input = document.querySelector('.input-wrapper input'); | ||
}); | ||
test('should be focused', () => { | ||
expect(document.activeElement).toBe($input); | ||
}); | ||
test('should call findInPage on Enter', () => { | ||
// Given | ||
$input.value = 'test'; | ||
// When | ||
fireEvent.keyDown($input, {key: 'Enter'}); | ||
// Then | ||
expect(window.electron.findInPage).toHaveBeenCalledTimes(1); | ||
expect(window.electron.findInPage).toHaveBeenCalledWith({text: 'test'}); | ||
}); | ||
test('should close on Escape', () => { | ||
// When | ||
fireEvent.keyDown($input, {key: 'Escape'}); | ||
// Then | ||
expect(window.electron.close).toHaveBeenCalledTimes(1); | ||
}); | ||
test('should not call findInPage on other keys', () => { | ||
// When | ||
fireEvent.keyDown($input, {key: 'a'}); | ||
// Then | ||
expect(window.electron.findInPage).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('Results', () => { | ||
let $results; | ||
beforeEach(() => { | ||
$results = document.querySelector('.results'); | ||
}); | ||
test('should be hidden when no matches', () => { | ||
// Then | ||
expect($results.style.visibility).toBe('hidden'); | ||
}); | ||
test('should be visible when matches', async () => { | ||
// Given | ||
onFindInPageCallback(null, {matches: 1}); | ||
// Then | ||
await waitFor(() => expect($results.style.visibility).toBe('visible')); | ||
}); | ||
test('should show active match ordinal and total matches', async () => { | ||
// Given | ||
onFindInPageCallback(null, {matches: 2, activeMatchOrdinal: 1}); | ||
// Then | ||
await waitFor(() => expect($results.textContent).toBe('1/2')); | ||
}); | ||
test('should set focus on input', () => { | ||
expect(document.activeElement).toBe(document.querySelector('.input-wrapper input')); | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
/* | ||
Copyright 2024 Marc Nuri San Felix | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 {jest} from '@jest/globals'; | ||
import {loadDOM} from '../../__tests__/index.mjs'; | ||
|
||
describe('Find in Page :: index.html test suite', () => { | ||
beforeEach(async () => { | ||
jest.resetModules(); | ||
window.electron = { | ||
close: jest.fn(), | ||
findInPage: jest.fn(), | ||
onFindInPage: jest.fn() | ||
}; | ||
await loadDOM({meta: import.meta, path: ['..', 'index.html']}); | ||
}); | ||
test('loads required styles', () => { | ||
expect(Array.from(document.querySelectorAll('link[rel=stylesheet]')) | ||
.map(link => link.getAttribute('href'))) | ||
.toEqual(['./find-in-page.browser.css']); | ||
}); | ||
}); |
Oops, something went wrong.