|
| 1 | +import { RegistrationForm, random_user_registration_data } from "../../user/registration"; |
| 2 | +import { random_tag_name } from "../fixtures"; |
| 3 | + |
| 4 | +describe("The admin user", () => { |
| 5 | + let registration_form: RegistrationForm; |
| 6 | + |
| 7 | + before(() => { |
| 8 | + registration_form = random_user_registration_data(); |
| 9 | + cy.register_as_admin_and_login(registration_form); |
| 10 | + }); |
| 11 | + |
| 12 | + after(() => { |
| 13 | + cy.delete_user_from_database(registration_form.username); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should be able to delete a tag", () => { |
| 17 | + const tag_name = random_tag_name(); |
| 18 | + |
| 19 | + cy.add_tag_to_database(tag_name); |
| 20 | + |
| 21 | + cy.go_to_settings(); |
| 22 | + |
| 23 | + // Click tags tab |
| 24 | + cy.contains("a", "tags").click(); |
| 25 | + |
| 26 | + // Delete the tag |
| 27 | + cy.get(`button[data-cy="delete-tag-${tag_name}"]`).click(); |
| 28 | + |
| 29 | + // Confirm alert should pop up |
| 30 | + cy.on("window:confirm", (str) => { |
| 31 | + expect(str).to.equal(`Are you sure you want to delete ${tag_name}?`); |
| 32 | + }); |
| 33 | + |
| 34 | + // Confirm delete |
| 35 | + cy.on("window:confirm", () => true); |
| 36 | + |
| 37 | + cy.get(`[data-cy="delete-tag-${tag_name}"]`).should("not.exist"); |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
| 41 | +describe("A non admin authenticated user", () => { |
| 42 | + let registration_form: RegistrationForm; |
| 43 | + |
| 44 | + before(() => { |
| 45 | + registration_form = random_user_registration_data(); |
| 46 | + cy.register_and_login(registration_form); |
| 47 | + }); |
| 48 | + |
| 49 | + after(() => { |
| 50 | + cy.delete_user_from_database(registration_form.username); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should not be able to delete tags", () => { |
| 54 | + cy.visit("/admin/settings/tags"); |
| 55 | + cy.contains("Please login to manage admin settings."); |
| 56 | + }); |
| 57 | +}); |
| 58 | + |
| 59 | +describe("A guest user", () => { |
| 60 | + it("should not be able to delete a tag", () => { |
| 61 | + cy.visit("/admin/settings/tags"); |
| 62 | + cy.contains("Please login to manage admin settings."); |
| 63 | + }); |
| 64 | +}); |
0 commit comments