Skip to content

Commit

Permalink
test: [#232] added tests for generating the magnet link on torrents l…
Browse files Browse the repository at this point in the history
…ist page
  • Loading branch information
MMelchor committed Oct 16, 2023
1 parent d0134fc commit ee028c9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/torrent/TorrentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ArrowDownTrayIcon class="w-6" />
</div>
<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">
<a class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`" @click.stop>
<a data-cy="torrent-list-magnet-link" class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`" @click.stop>
<LinkIcon class="w-6" />
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/torrent/TorrentTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<ArrowDownTrayIcon class="w-5" />
</div>
<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">
<a class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`">
<a data-cy="torrent-table-magnet-link" class="flex items-center" :href="`magnet:?xt=urn:btih:${torrent.info_hash}`">
<LinkIcon class="w-5" />
</a>
</div>
Expand Down
43 changes: 43 additions & 0 deletions cypress/e2e/contexts/torrent/specs/list/magnet_link.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { RegistrationForm, random_user_registration_data } from "../../../user/registration";
import { generateRandomTestTorrentInfo } from "../../test_torrent_info";

describe("A guest user", () => {
let registration_form: RegistrationForm;

before(() => {
registration_form = random_user_registration_data();
cy.register_and_login(registration_form);
// Generates and upload a random torrent file for the tests
const torrent_info = generateRandomTestTorrentInfo();
Cypress.env("torrent_info", torrent_info);
cy.upload_torrent(torrent_info);
// Stores the infoHash in the Cypress's env variables
cy.get("[data-cy=\"torrent-action-info-hash\"]").invoke("text").then((infoHash) => {
Cypress.env("infoHash", infoHash);
});
});

beforeEach(() => {
cy.visit("/torrents");
});

after(() => {
cy.delete_user_from_database(registration_form.username);
});

it("should be able get the a torrent magnet link from the torrents list", () => {
// Get the magnet link
cy.get("[data-cy=\"torrent-list-magnet-link\"]").invoke("attr", "href").then((href) => {
expect(href).to.include(`magnet:?xt=urn:btih:${Cypress.env("infoHash")}`);
});
});

it("should be able get the a torrent magnet link from the torrents table", () => {
// Sets the layout to "table"
cy.get("[data-cy=\"torrents-table-layout-selector\"]").click();
// Gets the magnet link
cy.get("[data-cy=\"torrent-table-magnet-link\"]").invoke("attr", "href").then((href) => {
expect(href).to.include(`magnet:?xt=urn:btih:${Cypress.env("infoHash")}`);
});
});
});
2 changes: 1 addition & 1 deletion pages/torrents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<button class="tab" :class="{ 'tab-active': layout === 'default' }" @click="layout = 'default'">
Default
</button>
<button class="tab" :class="{ 'tab-active': layout === 'table' }" @click="layout = 'table'">
<button data-cy="torrents-table-layout-selector" class="tab" :class="{ 'tab-active': layout === 'table' }" @click="layout = 'table'">
Table
</button>
</div>
Expand Down

0 comments on commit ee028c9

Please sign in to comment.