diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "author": "The Software Heritage developers", "license": "AGPL-3.0-or-later", "dependencies": { - "@babel/runtime-corejs3": "^7.8.7", - "@sentry/browser": "^5.14.2", + "@babel/runtime-corejs3": "^7.9.2", + "@sentry/browser": "^5.15.4", "admin-lte": "^3.0.2", "ansi_up": "^4.0.4", "bootstrap": "^4.4.1", @@ -37,13 +37,13 @@ "iframe-resizer": "^4.2.10", "jquery": "^3.4.1", "js-cookie": "^2.2.1", - "js-year-calendar": "^1.0.0-alpha.7", + "js-year-calendar": "^1.0.1", "mocha-junit-reporter": "^1.23.3", "notebookjs": "^0.4.2", "object-fit-images": "^3.2.4", "octicons": "^8.5.0", "org": "^0.2.0", - "pdfjs-dist": "^2.2.228", + "pdfjs-dist": "^2.3.200", "popper.js": "^1.16.1", "showdown": "^1.9.1", "typeface-alegreya": "0.0.69", @@ -53,30 +53,30 @@ "whatwg-fetch": "^3.0.0" }, "devDependencies": { - "@babel/core": "^7.8.7", + "@babel/core": "^7.9.0", "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@babel/plugin-transform-runtime": "^7.8.3", - "@babel/preset-env": "^7.8.7", - "@cypress/code-coverage": "^1.14.0", - "autoprefixer": "^9.7.4", + "@babel/plugin-transform-runtime": "^7.9.0", + "@babel/preset-env": "^7.9.0", + "@cypress/code-coverage": "^2.0.0", + "autoprefixer": "^9.7.5", "axios": "^0.19.2", "babel-eslint": "^10.1.0", - "babel-loader": "^8.0.6", + "babel-loader": "^8.1.0", "babel-plugin-istanbul": "^6.0.0", "bootstrap-loader": "^3.0.4", "cache-loader": "^4.1.0", "clean-webpack-plugin": "^3.0.0", "copy-webpack-plugin": "^5.1.1", "css-loader": "^3.4.2", - "cypress": "^4.2.0", + "cypress": "^4.3.0", "cypress-multi-reporters": "^1.2.4", - "ejs": "^3.0.1", + "ejs": "^3.0.2", "eslint": "^6.8.0", "eslint-loader": "^3.0.3", "eslint-plugin-chai-friendly": "^0.5.0", "eslint-plugin-cypress": "^2.10.3", - "eslint-plugin-import": "^2.20.1", - "eslint-plugin-node": "^11.0.0", + "eslint-plugin-import": "^2.20.2", + "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-standard": "^4.0.1", "exports-loader": "^0.7.0", @@ -110,7 +110,7 @@ "stylelint-config-standard": "^20.0.0", "terser-webpack-plugin": "^2.3.5", "url-loader": "^4.0.0", - "webpack": "^4.42.0", + "webpack": "^4.42.1", "webpack-bundle-tracker": "^0.4.3", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.10.3" diff --git a/swh/web/browse/views/utils/snapshot_context.py b/swh/web/browse/views/utils/snapshot_context.py --- a/swh/web/browse/views/utils/snapshot_context.py +++ b/swh/web/browse/views/utils/snapshot_context.py @@ -807,7 +807,7 @@ prev_branches_url = reverse(browse_view_name, url_args=url_args, query_params=query_params) - if len(displayed_branches) > PER_PAGE: + if snapshot['next_branch'] is not None: query_params_next = dict(query_params) next_branch = displayed_branches[-1]['name'] del displayed_branches[-1] @@ -906,7 +906,7 @@ prev_releases_url = reverse(browse_view_name, url_args=url_args, query_params=query_params) - if len(displayed_releases) > PER_PAGE: + if snapshot['next_branch'] is not None: query_params_next = dict(query_params) next_rel = displayed_releases[-1]['branch_name'] del displayed_releases[-1] diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py --- a/swh/web/tests/browse/views/test_origin.py +++ b/swh/web/tests/browse/views/test_origin.py @@ -5,6 +5,7 @@ import random import re +import string import swh.web.browse.utils @@ -20,11 +21,12 @@ reverse, gen_path_info, format_utc_iso_date, parse_timestamp, get_swh_persistent_id ) -from swh.web.tests.data import get_content +from swh.web.tests.data import get_content, random_sha1 from swh.web.tests.django_asserts import assert_contains, assert_template_used from swh.web.tests.strategies import ( origin, origin_with_multiple_visits, new_origin, - new_snapshot, visit_dates, revisions, origin_with_releases + new_snapshot, visit_dates, revisions, origin_with_releases, + release as existing_release ) @@ -903,3 +905,46 @@ escape(browse_release_url)) assert_contains(resp, '' % escape(browse_revision_url)) + + +@given(new_origin(), visit_dates(), revisions(min_size=10, max_size=10), + existing_release()) +def test_origin_branches_pagination_with_alias(client, archive_data, mocker, + new_origin, visit_dates, + revisions, existing_release): + """ + When a snapshot contains a branch or a release alias, pagination links + in the branches / releases view should be displayed. + """ + mocker.patch('swh.web.browse.views.utils.snapshot_context.PER_PAGE', + len(revisions) / 2) + snp_dict = {'branches': {}, 'id': hash_to_bytes(random_sha1())} + for i in range(len(revisions)): + branch = ''.join(random.choices(string.ascii_lowercase, k=8)) + snp_dict['branches'][branch.encode()] = { + 'target_type': 'revision', + 'target': hash_to_bytes(revisions[i]), + } + release = ''.join(random.choices(string.ascii_lowercase, k=8)) + snp_dict['branches'][b'RELEASE_ALIAS'] = { + 'target_type': 'alias', + 'target': release.encode() + } + snp_dict['branches'][release.encode()] = { + 'target_type': 'release', + 'target': hash_to_bytes(existing_release) + } + new_origin = archive_data.origin_add([new_origin])[0] + archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) + visit = archive_data.origin_visit_add( + new_origin['url'], visit_dates[0], type='git') + archive_data.origin_visit_update(new_origin['url'], visit.visit, + status='full', + snapshot=snp_dict['id']) + + url = reverse('browse-origin-branches', + url_args={'origin_url': new_origin['url']}) + resp = client.get(url) + assert resp.status_code == 200 + assert_template_used(resp, 'browse/branches.html') + assert_contains(resp, '