From ee028c976934dffbf6c02429e4fdeb595aa15b15 Mon Sep 17 00:00:00 2001 From: MMelchor Date: Mon, 16 Oct 2023 17:24:57 +0200 Subject: [PATCH] test: [#232] added tests for generating the magnet link on torrents list page --- components/torrent/TorrentList.vue | 2 +- components/torrent/TorrentTable.vue | 2 +- .../torrent/specs/list/magnet_link.cy.ts | 43 +++++++++++++++++++ pages/torrents.vue | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/contexts/torrent/specs/list/magnet_link.cy.ts diff --git a/components/torrent/TorrentList.vue b/components/torrent/TorrentList.vue index 12c3c938..3ed2449b 100644 --- a/components/torrent/TorrentList.vue +++ b/components/torrent/TorrentList.vue @@ -32,7 +32,7 @@ diff --git a/components/torrent/TorrentTable.vue b/components/torrent/TorrentTable.vue index 200c1233..1ad92b22 100644 --- a/components/torrent/TorrentTable.vue +++ b/components/torrent/TorrentTable.vue @@ -37,7 +37,7 @@ diff --git a/cypress/e2e/contexts/torrent/specs/list/magnet_link.cy.ts b/cypress/e2e/contexts/torrent/specs/list/magnet_link.cy.ts new file mode 100644 index 00000000..c05a9d90 --- /dev/null +++ b/cypress/e2e/contexts/torrent/specs/list/magnet_link.cy.ts @@ -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")}`); + }); + }); +}); diff --git a/pages/torrents.vue b/pages/torrents.vue index f70b0e98..2a89341d 100644 --- a/pages/torrents.vue +++ b/pages/torrents.vue @@ -33,7 +33,7 @@ -