Skip to content

Commit

Permalink
Add in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
dado3212 committed Jul 9, 2024
1 parent 25e7d17 commit 68df480
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ Taking the `filepath` from the `/Books/Purchases/Purchases.plist` can let you pu
I built this using `node -v: v20.14.0` and `npm -v: 10.7.0`.

* `npm run start` runs the app locally
* `npm run dev` runs the app with temp data. Before deploying make sure it matches the screenshots.
* `npm run build` builds the Mac app in `release-builds`. I took the resulting `.app` and zipped it for the release version.

## Testing The App

You should go through a flow with a real phone, using `npm run start`. You can also use the three testing environments, and confirm they match the uploaded screenshots in those files, in light and dark mode.
* `npm run test1` - tests my production environment, tests all colors, styles, notes
* `npm run test2` - test some alternate data formats users have reported, other languages
* `npm run test3` - test no annotations

## Thanks

I sort the annotations by location in the book using the Epub CFI's like `epubcfi(/6/304[id167]!/4[4F1KC0-7077b85d15a1406085690fde3201ca05]/710/2/1,:0,:23)`, thanks @mlitwin for [his Gist detailing how to sort them](https://gist.github.com/mlitwin/1a5471ae2897c360914247bc8db6b57a).
Expand Down
18 changes: 11 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ var onDeviceManagerReady = () => { };
var mainWindow;

// Helper function for whether or not to use test data
function isTest() {
return !app.isPackaged && process.env.BOOKS_ANNOTATIONS_ENV == 'test';
function getTestVersion() {
if (app.isPackaged || process.env.BOOKS_ANNOTATIONS_ENV == null || !process.env.BOOKS_ANNOTATIONS_ENV.startsWith('test')) {
return null;
}
return process.env.BOOKS_ANNOTATIONS_ENV.replace('test', '');
}

const createWindow = () => {
Expand Down Expand Up @@ -49,26 +52,27 @@ app.whenReady().then(createWindow);
ipcMain.handle('read-plist', async (event, filePath, type) => {

// Return test data
if (isTest()) {
let testVersion = getTestVersion();
if (testVersion != null) {
return new Promise((resolve) => {
if (filePath === '/Books/Purchases/Purchases.plist') {
fs.readFile('./test-files/files-1/Purchases.plist', (err, data) => {
fs.readFile(`./test-files/files-${testVersion}/Purchases.plist`, (err, data) => {
if (err) {
console.log('failed to load', filePath);
return resolve(null);
}
resolve(plist.parse(data.toString()));
});
} else if (filePath === '/Books/com.apple.ibooks-sync.plist') {
fs.readFile('./test-files/files-1/com.apple.ibooks-sync.plist', (err, data) => {
fs.readFile(`./test-files/files-${testVersion}/com.apple.ibooks-sync.plist`, (err, data) => {
if (err) {
console.log('failed to load', filePath);
return resolve(null);
}
resolve(plist.parse(data.toString()));
});
} else if (filePath === '/Books/iBooksData2.plist') {
fs.readFile('./test-files/files-1/iBooksData2.plist', (err, data) => {
fs.readFile(`./test-files/files-${testVersion}/iBooksData2.plist`, (err, data) => {
if (err) {
console.log('failed to load', filePath);
return resolve(null);
Expand Down Expand Up @@ -128,7 +132,7 @@ function sendDevice(event) {
}

ipcMain.handle('fetch-devices', async (event) => {
if (isTest()) {
if (getTestVersion() != null) {
event.sender.send('device-name', { success: true, name: 'Test Device' });
return;
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "js/main.js",
"scripts": {
"start": "electron .",
"dev": "BOOKS_ANNOTATIONS_ENV=test electron .",
"test1": "BOOKS_ANNOTATIONS_ENV=test1 electron .",
"test2": "BOOKS_ANNOTATIONS_ENV=test2 electron .",
"test3": "BOOKS_ANNOTATIONS_ENV=test3 electron .",
"build": "electron-packager . 'Books Annotations' --overwrite --platform=darwin --icon=assets/icon.icns --ignore=images --prune --out=release-builds --app-bundle-id=\"com.alexbeals.BooksAnnotations\" --app-version=\"1.1.1\" --build-version=\"1.1.1\" --osx-sign"
},
"author": "Alex Beals",
Expand Down
49 changes: 49 additions & 0 deletions test-files/files-2/Purchases.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Books</key>
<array>
<dict>
<key>AppleID</key>
<string>[email protected]</string>
<key>Artist</key>
<string>H.G. Wells</string>
<key>Backup-Path</key>
<string>/var/mobile/Media/Books/Purchases/19AEC87B-65B3-4D2B-9F1F-D6CF03246FFD.epub</string>
<key>DSID</key>
<integer>123</integer>
<key>Estimated Download Size</key>
<integer>3196740</integer>
<key>Flavor</key>
<string>pluspub</string>
<key>Genre</key>
<string>Sci-Fi &amp; Fantasy</string>
<key>Name</key>
<string>H. G. Wells: Classics Novels and Short Stories</string>
<key>Page Progression Direction</key>
<string>default</string>
<key>Path</key>
<string>19AEC87B-65B3-4D2B-9F1F-D6CF03246FFD.epub</string>
<key>Persistent ID</key>
<string>0F76E52742AC4AC7</string>
<key>Persistent ID Generated On Device</key>
<true/>
<key>Publication Version</key>
<integer>163326480</integer>
<key>Release Date</key>
<string>2017-07-01T07:00:00Z</string>
<key>Sort Artist</key>
<string>Wells, H.G.</string>
<key>Sort Name</key>
<string>H. G. Wells: Classics Novels and Short Stories</string>
<key>Storefront ID</key>
<integer>123</integer>
<key>isSample</key>
<false/>
<key>s</key>
<integer>123</integer>
</dict>
</array>
</dict>
</plist>
72 changes: 72 additions & 0 deletions test-files/files-2/com.apple.ibooks-sync.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Bookmark-Container-12202011</key>
<dict>
<key>4</key>
<array>
<dict>
<key>annotationAssetID</key>
<string>CED2211604373C3FCF42A347F1E97E2E</string>
<key>annotationCreationDate</key>
<integer>1615368892</integer>
<key>annotationCreatorIdentifier</key>
<string>com~apple~iBooks</string>
<key>annotationDeleted</key>
<integer>0</integer>
<key>annotationIsUnderline</key>
<integer>0</integer>
<key>annotationLocation</key>
<string>epubcfi(/6/28[My-Enemy-s-Enemy-12]!/4[My-Enemy-s-Enemy-12]/2/82,/1:0,/3:164)</string>
<key>annotationModificationDate</key>
<integer>1615369163</integer>
<key>annotationNote</key>
<string>Прям как</string>
<key>annotationRepresentativeText</key>
<string>artistic circles which were the highest within her reach, discovered that her conversational qualifications were expected to include a grounding in the novels of Mr. H.G. Wells. She borrowed them in various directions so energetically that she swallowed them all within two months.</string>
<key>annotationSelectedText</key>
<string>discovered that her conversational qualifications were expected to include a grounding in the novels of Mr. H.G. Wells.</string>
<key>annotationStyle</key>
<integer>1</integer>
<key>annotationType</key>
<integer>2</integer>
<key>annotationUuid</key>
<string>E5D4816D-C09D-4217-9229-4B150EA814DB</string>
<key>futureProofing11</key>
<string>637061692.505751</string>
<key>futureProofing5</key>
<string>Act V</string>
<key>futureProofing6</key>
<string>637061963.132852</string>
<key>futureProofing7</key>
<string>{58, 119}</string>
<key>futureProofing9</key>
<string>1</string>
<key>plAbsolutePhysicalLocation</key>
<integer>0</integer>
<key>plLocationRangeEnd</key>
<integer>0</integer>
<key>plLocationRangeStart</key>
<integer>9</integer>
<key>plUserData</key>
<data>
YnBsaXN0MDDWAQIDBAUGBwgMDRwdVWNsYXNzVXN1cGVy
W3N0YXJ0T2Zmc2V0V2VuZFBhdGhZZW5kT2Zmc2V0WXN0
YXJ0UGF0aF5CS0VwdWJMb2NhdGlvbtIJAQoLV29yZGlu
YWwQCVpCS0xvY2F0aW9uIkM6AACkDhUXGtMPEBESExRX
dGFnTmFtZVljbGFzc05hbWVVaW5kZXhTZGl2VGJvZHkQ
AtMPEBESFhRUdGV4dNIPERgZUXAQINERGxABIkOYgACk
Hh8gIdMPEBESExTTDxAREhYU0g8RGBnRERsIFRshLTU/
SVhdZWdyd3yDi5Wbn6SmrbK3ubu+wMXK0djdAAAAAAAA
AQEAAAAAAAAAIgAAAAAAAAAAAAAAAAAAAOA=
</data>
</dict>
</array>
<key>Generation</key>
<integer>1699730376</integer>
<key>Wrapper-Revision</key>
<string>4</string>
</dict>
</dict>
</plist>
Binary file added test-files/files-2/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test-files/files-3/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68df480

Please sign in to comment.