Skip to content

Commit

Permalink
Add a test for recognize/unrecognize item.
Browse files Browse the repository at this point in the history
Also updated fixtures and fixed failing tests.
  • Loading branch information
tnajdek committed Jan 24, 2025
1 parent aa9860a commit a58d784
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 40 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"npm-run-all": "^4.1.5",
"nyc": "^17.1.0",
"pixelmatch": "<6.0.0",
"playwright": "<1.47",
"playwright": "^1.49.0",
"pngjs": "^7.0.0",
"postcss": "^8.4.49",
"postcss-cli": "^11.0.0",
Expand Down
7 changes: 4 additions & 3 deletions scripts/generate-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import psTree from 'ps-tree';
// "apiKey": "",
// "userName": "",
// "userId": "",
// "translateServerURL": ""
// "translateServerUrl": "",
// "recognizerServerUrl": ""
// }

const URL = 'http://localhost:8001/';
Expand All @@ -42,7 +43,8 @@ const fixtures = [
];

const config = JSON.stringify({
translateUrl: secret.translateServerURL,
translateUrl: secret.translateServerUrl,
recognizerUrl: secret.recognizerServerUrl,
libraries: {
include: [{
key: "g5119976",
Expand Down Expand Up @@ -206,7 +208,6 @@ async function makeFixture(stateURL, name) {
state = state.replaceAll(secret.apiKey, 'zzzzzzzzzzzzzzzzzzzzzzzz');
state = state.replaceAll(secret.userName, 'testuser');
state = state.replaceAll(secret.userId, '1');
state = state.replaceAll(secret.translateServerURL, 'https://translate-server.zotero.org/Prod');
let stateJSON = JSON.parse(state);
try {
stateJSON.config.libraries.find(l => l.key === 'g5119976').isReadOnly = false;
Expand Down
25 changes: 18 additions & 7 deletions src/js/component/modal/metadata-retrieval.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ const MetadataRetrievalTitleCell = memo(props => {
{...pick(props, ['colIndex', 'width', 'isFirstColumn', 'isLastColumn'])}
>
<Icon
label={`${iconName} icon`}
type={`16/${iconName}`}
symbol={iconName}
className="metadata-status-icon"
color={iconName === 'tick' ? 'var(--accent-green)' : iconName === 'cross' ? 'var(--accent-red)' : 'var(--fill-secondary)'}
width="16"
height="16"
className="metadata-status-icon"
label={iconName === 'tick' ? 'Completed' : iconName === 'cross' ? 'Error' : 'Processing'}
role="status"
symbol={iconName}
type={`16/${iconName}`}
width="16"
/>
<div className="truncate" id={labelledById}>
{title}
Expand Down Expand Up @@ -194,7 +195,9 @@ const MetadataRetrievalModal = () => {
return {
title: item.itemTitle,
parentItemTitle: item.completed ? item.parentItemTitle : item.error ? 'Error' : 'Processing',
iconName
iconName,
completed: item.completed,
error: item.error
}
}, [recognizeEntries]);

Expand Down Expand Up @@ -267,6 +270,7 @@ const MetadataRetrievalModal = () => {
icon
className="close"
onClick={handleCancel}
title="Close Dialog"
>
<Icon type={'16/close'} width="16" height="16" />
</Button>
Expand All @@ -279,7 +283,14 @@ const MetadataRetrievalModal = () => {
tabIndex={!isTouchOrSmall ? 0 : null}
>
<div className="recognize-progress">
<progress value={recognizeProgress} max="1" />
<progress
aria-label="Metadata retrieval progress"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={recognizeProgress * 100}
value={recognizeProgress}
max="1"
/>
</div>
{isTouchOrSmall ? (
<List
Expand Down
1 change: 1 addition & 0 deletions src/js/component/modal/settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const SettingsModal = () => {
icon
className="close"
onClick={handleClose}
title="Close Dialog"
>
<Icon type={'16/close'} width="16" height="16" />
</Button>
Expand Down
10 changes: 5 additions & 5 deletions test/basic-ui.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Basic UI', () => {
expect(screen.getByRole('button', { name: 'Tag Selector Options' })).toBeInTheDocument();
expect(screen.getByRole('toolbar', { name: 'items toolbar' })).toBeInTheDocument();
expect(screen.getByRole('grid', { name: 'items' })).toBeInTheDocument();
expect(screen.getByText('81 items in this view')).toBeInTheDocument();
expect(screen.getByText('82 items in this view')).toBeInTheDocument();
});


Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Basic UI', () => {
await user.click(clearSearchButton);

await waitFor(() => expect(searchBox).toHaveValue(''));
await waitFor(() => expect(screen.getByText('81 items in this view')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('82 items in this view')).toBeInTheDocument());
expect(await screen.findByRole('row', { name: 'Border Collie' })).toBeInTheDocument();
expect(screen.queryByRole('row', { name: 'Summary of pathfinding algorithms used in game development' })).not.toBeInTheDocument();
});
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('Basic UI', () => {
const tagSelector = screen.getByRole('navigation', { name: 'tag selector' });
const tagButton = getByRole(tagSelector, 'button', { name: 'to read', pressed: false });

expect(screen.getByText('81 items in this view')).toBeInTheDocument();
expect(screen.getByText('82 items in this view')).toBeInTheDocument();

await userEvent.click(tagButton);
await waitForPosition();
Expand All @@ -227,7 +227,7 @@ describe('Basic UI', () => {
renderWithProviders(<MainZotero />, { preloadedState: libraryViewState });
await waitForPosition();

expect(screen.getByText('81 items in this view')).toBeInTheDocument();
expect(screen.getByText('82 items in this view')).toBeInTheDocument();
expect(screen.queryByRole('tablist', { name: 'Item Details' })).not.toBeInTheDocument();

const item = screen.getByRole('row',
Expand All @@ -240,7 +240,7 @@ describe('Basic UI', () => {
{ name: 'A comparison of sequential Delaunay triangulation algorithms' })
).toHaveAttribute('aria-selected', 'true');

expect(screen.queryByRole('81 items in this view')).not.toBeInTheDocument();
expect(screen.queryByRole('82 items in this view')).not.toBeInTheDocument();
expect(screen.getByRole('tablist', { name: 'Item Details' })).toBeInTheDocument();
expect(screen.getByRole('tab', { name: 'Info', selected: true })).toBeInTheDocument();
});
Expand Down
69 changes: 69 additions & 0 deletions test/fixtures/response/search-by-identifier-recognize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[
{
"key": "PBXD4AZ2",
"version": 0,
"itemType": "preprint",
"creators": [
{
"firstName": "Ashish",
"lastName": "Vaswani",
"creatorType": "author"
},
{
"firstName": "Noam",
"lastName": "Shazeer",
"creatorType": "author"
},
{
"firstName": "Niki",
"lastName": "Parmar",
"creatorType": "author"
},
{
"firstName": "Jakob",
"lastName": "Uszkoreit",
"creatorType": "author"
},
{
"firstName": "Llion",
"lastName": "Jones",
"creatorType": "author"
},
{
"firstName": "Aidan N.",
"lastName": "Gomez",
"creatorType": "author"
},
{
"firstName": "Lukasz",
"lastName": "Kaiser",
"creatorType": "author"
},
{
"firstName": "Illia",
"lastName": "Polosukhin",
"creatorType": "author"
}
],
"tags": [
{
"tag": "Computer Science - Computation and Language",
"type": 1
},
{
"tag": "Computer Science - Machine Learning",
"type": 1
}
],
"title": "Attention Is All You Need",
"date": "2023-08-02",
"abstractNote": "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.",
"url": "http://arxiv.org/abs/1706.03762",
"extra": "arXiv:1706.03762",
"repository": "arXiv",
"archiveID": "arXiv:1706.03762",
"DOI": "10.48550/arXiv.1706.03762",
"libraryCatalog": "arXiv.org",
"accessDate": "2025-01-24T16:42:30Z"
}
]
123 changes: 123 additions & 0 deletions test/fixtures/response/test-user-add-by-identifier-recognize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"successful": {
"0": {
"key": "S8CIV6VJ",
"version": 250,
"library": {
"type": "user",
"id": 1,
"name": "testuser",
"links": {
"alternate": {
"href": "https://www.zotero.org/testuser",
"type": "text/html"
}
}
},
"links": {
"self": {
"href": "https://api.zotero.org/users/1/items/S8CIV6VJ",
"type": "application/json"
},
"alternate": {
"href": "https://www.zotero.org/testuser/items/S8CIV6VJ",
"type": "text/html"
}
},
"meta": {
"creatorSummary": "Vaswani et al.",
"parsedDate": "2023-08-02",
"numChildren": 0
},
"data": {
"key": "S8CIV6VJ",
"version": 250,
"itemType": "preprint",
"title": "Attention Is All You Need",
"creators": [
{
"creatorType": "author",
"firstName": "Ashish",
"lastName": "Vaswani"
},
{
"creatorType": "author",
"firstName": "Noam",
"lastName": "Shazeer"
},
{
"creatorType": "author",
"firstName": "Niki",
"lastName": "Parmar"
},
{
"creatorType": "author",
"firstName": "Jakob",
"lastName": "Uszkoreit"
},
{
"creatorType": "author",
"firstName": "Llion",
"lastName": "Jones"
},
{
"creatorType": "author",
"firstName": "Aidan N.",
"lastName": "Gomez"
},
{
"creatorType": "author",
"firstName": "Lukasz",
"lastName": "Kaiser"
},
{
"creatorType": "author",
"firstName": "Illia",
"lastName": "Polosukhin"
}
],
"abstractNote": "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.",
"genre": "",
"repository": "arXiv",
"archiveID": "arXiv:1706.03762",
"place": "",
"date": "2023-08-02",
"series": "",
"seriesNumber": "",
"DOI": "10.48550/arXiv.1706.03762",
"citationKey": "",
"url": "http://arxiv.org/abs/1706.03762",
"accessDate": "2025-01-24T16:42:30Z",
"archive": "",
"archiveLocation": "",
"shortTitle": "",
"language": "en",
"libraryCatalog": "arXiv.org",
"callNumber": "",
"rights": "",
"extra": "arXiv:1706.03762",
"tags": [
{
"tag": "Computer Science - Computation and Language",
"type": 1
},
{
"tag": "Computer Science - Machine Learning",
"type": 1
}
],
"collections": [
"CSB4KZUU"
],
"relations": {},
"dateAdded": "2025-01-24T16:42:31Z",
"dateModified": "2025-01-24T16:42:31Z"
}
}
},
"success": {
"0": "S8CIV6VJ"
},
"unchanged": {},
"failed": {}
}
2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-group-item-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-attachment-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-item-view.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-library-view.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-note-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-reader-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-search-selected.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/desktop-test-user-trash-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/state/mobile-test-user-item-list-view.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/playwright/items.mobile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Mobile Snapshots', () => {
await page.goto(`http://localhost:${port}/testuser/collections/WTTJ2J56/item-list`);
await waitForLoad(page);
const itemsList = page.getByRole('list', { name: 'items' });
expect(await itemsList.getByRole('listitem').count()).toBe(7);
await expect(itemsList.getByRole('listitem')).toHaveCount(7);
expect(await screenshot(page, `mobile-items-list-${browserName}`)).toBeTruthy();

if (singleColumnContexts.includes(browserName)) {
Expand Down
Loading

0 comments on commit a58d784

Please sign in to comment.