-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add utility for finding duplicate Notion pages (#433)
* refactor: Move element utility functions into a single file * refactor: Correctly indicate that `getXULElementById` can return null * refactor: Extract `WindowManager` service for providing latest window * refactor: Add index file for test utils * refactor: Add `getRequiredNoteroPref` that throws if missing value * refactor: Rename Notion types for clarity * feat: Add utility for finding duplicate Notion pages * feat: Support finding duplicates by properties other than title
- Loading branch information
Showing
25 changed files
with
311 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createWindowMock } from '../../../../test/utils/window-mock'; | ||
import { WindowManager } from '../window-manager'; | ||
|
||
describe('WindowManager.getLatestWindow', () => { | ||
it('returns the latest available window', () => { | ||
const windowManager = new WindowManager(); | ||
|
||
const window1 = createWindowMock(); | ||
const window2 = createWindowMock(); | ||
const window3 = createWindowMock(); | ||
|
||
windowManager.addToWindow(window1); | ||
windowManager.addToWindow(window2); | ||
windowManager.addToWindow(window3); | ||
windowManager.removeFromWindow(window2); | ||
|
||
expect(windowManager.getLatestWindow()).toBe(window3); | ||
|
||
windowManager.removeFromWindow(window3); | ||
|
||
expect(windowManager.getLatestWindow()).toBe(window1); | ||
}); | ||
|
||
it('returns undefined when all windows have been removed', () => { | ||
const windowManager = new WindowManager(); | ||
|
||
const window1 = createWindowMock(); | ||
const window2 = createWindowMock(); | ||
|
||
windowManager.addToWindow(window1); | ||
windowManager.addToWindow(window2); | ||
windowManager.removeFromWindow(window1); | ||
|
||
expect(windowManager.getLatestWindow()).toBe(window2); | ||
|
||
windowManager.removeFromWindow(window2); | ||
|
||
expect(windowManager.getLatestWindow()).toBeUndefined(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Service } from './service'; | ||
|
||
export class WindowManager implements Service { | ||
private readonly windows: Zotero.ZoteroWindow[] = []; | ||
|
||
public startup() {} | ||
|
||
public addToWindow(window: Zotero.ZoteroWindow) { | ||
if (!this.windows.includes(window)) { | ||
this.windows.unshift(window); | ||
} | ||
} | ||
|
||
public removeFromWindow(window: Zotero.ZoteroWindow) { | ||
const index = this.windows.indexOf(window); | ||
if (index >= 0) { | ||
this.windows.splice(index, 1); | ||
} | ||
} | ||
|
||
public getLatestWindow(): Zotero.ZoteroWindow | undefined { | ||
return this.windows[0]; | ||
} | ||
} |
Oops, something went wrong.