Skip to content

Commit de1ffdf

Browse files
committed
Merge #306: Adds tests for generating the magnet link on torrents list page
cbef88a test: [#232] added tests for generating the magnet link on torrents list page (Mario) Pull request description: Resolves #232. Top commit has no ACKs. Tree-SHA512: 0536c99a3a30665d5a90dd2ed3967f4ca77a6d8005d7481dc31be1532172b58e37ce64000719d730bdb0755a57243440d2d80a440b1bfcba955e605fe31800c2
2 parents 2fd0fa9 + cbef88a commit de1ffdf

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

components/torrent/TorrentList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<ArrowDownTrayIcon class="w-6" />
3333
</div>
3434
<div class="flex flex-col items-center justify-center w-10 h-10 ml-2 duration-500 cursor-pointer text-base-content/50 hover:text-base-content shrink-0 rounded-2xl">
35-
<a class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`" @click.stop>
35+
<a data-cy="torrent-list-magnet-link" class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`" @click.stop>
3636
<LinkIcon class="w-6" />
3737
</a>
3838
</div>

components/torrent/TorrentTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ArrowDownTrayIcon class="w-5" />
3838
</div>
3939
<div class="flex flex-col items-center justify-center w-10 h-10 ml-2 duration-500 cursor-pointer text-base-content/50 hover:text-base-content shrink-0">
40-
<a class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`">
40+
<a data-cy="torrent-table-magnet-link" class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`">
4141
<LinkIcon class="w-5" />
4242
</a>
4343
</div>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { RegistrationForm, random_user_registration_data } from "../../../user/registration";
2+
import { generateRandomTestTorrentInfo } from "../../test_torrent_info";
3+
4+
describe("A guest user", () => {
5+
let registration_form: RegistrationForm;
6+
7+
before(() => {
8+
registration_form = random_user_registration_data();
9+
cy.register_and_login(registration_form);
10+
// Generates and upload a random torrent file for the tests
11+
const torrent_info = generateRandomTestTorrentInfo();
12+
Cypress.env("torrent_info", torrent_info);
13+
cy.upload_torrent(torrent_info);
14+
// Stores the infoHash in the Cypress's env variables
15+
cy.get("[data-cy=\"torrent-action-info-hash\"]").invoke("text").then((infoHash) => {
16+
Cypress.env("infoHash", infoHash);
17+
});
18+
});
19+
20+
beforeEach(() => {
21+
cy.visit("/torrents");
22+
});
23+
24+
after(() => {
25+
cy.delete_user_from_database(registration_form.username);
26+
});
27+
28+
it("should be able get the a torrent magnet link from the torrents list", () => {
29+
// Get the magnet link
30+
cy.get("[data-cy=\"torrent-list-magnet-link\"]").invoke("attr", "href").then((href) => {
31+
expect(href).to.include(`magnet:?xt=urn:btih:${Cypress.env("infoHash")}`);
32+
});
33+
});
34+
35+
it("should be able get the a torrent magnet link from the torrents table", () => {
36+
// Sets the layout to "table"
37+
cy.get("[data-cy=\"torrents-table-layout-selector\"]").click();
38+
// Gets the magnet link
39+
cy.get("[data-cy=\"torrent-table-magnet-link\"]").invoke("attr", "href").then((href) => {
40+
expect(href).to.include(`magnet:?xt=urn:btih:${Cypress.env("infoHash")}`);
41+
});
42+
});
43+
});

cypress/support/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "../e2e/contexts/user/commands";
22
import "../e2e/contexts/torrent/commands";
33
import "../e2e/contexts/category/commands";
44
import "../e2e/common/commands";
5-
import { TestTorrentInfo } from "cypress/e2e/contexts/torrent/test_torrent_info";
5+
import { TestTorrentInfo } from "../e2e/contexts/torrent/test_torrent_info";
66
import { RegistrationForm } from "../e2e/contexts/user/registration";
77

88
declare global {

pages/torrents.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<button class="tab" :class="{ 'tab-active': layout === 'default' }" @click="layout = 'default'">
3434
Default
3535
</button>
36-
<button class="tab" :class="{ 'tab-active': layout === 'table' }" @click="layout = 'table'">
36+
<button data-cy="torrents-table-layout-selector" class="tab" :class="{ 'tab-active': layout === 'table' }" @click="layout = 'table'">
3737
Table
3838
</button>
3939
</div>

0 commit comments

Comments
 (0)