|
| 1 | +import { BrowserRouter } from "react-router-dom"; |
| 2 | +import { render, screen } from "@testing-library/react"; |
| 3 | +import "@testing-library/jest-dom"; |
| 4 | + |
| 5 | +import RegistrationError from "../RegistrationError"; |
| 6 | + |
| 7 | +function renderComponent(errorCode: string) { |
| 8 | + return render( |
| 9 | + <BrowserRouter> |
| 10 | + <RegistrationError |
| 11 | + snapName="test-snap-name" |
| 12 | + isPrivate="private" |
| 13 | + store="ubuntu" |
| 14 | + errorCode={errorCode} |
| 15 | + /> |
| 16 | + </BrowserRouter>, |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +describe("RegistrationError", () => { |
| 21 | + test("points user to dashboard when registering snap in global store", () => { |
| 22 | + renderComponent("name-review-required"); |
| 23 | + expect( |
| 24 | + screen.getByRole("link", { |
| 25 | + name: "https://dashboard.snapcraft.io/register-snap", |
| 26 | + }), |
| 27 | + ).toBeInTheDocument(); |
| 28 | + }); |
| 29 | + |
| 30 | + test("informs user if they already own snap", () => { |
| 31 | + renderComponent("already_owned"); |
| 32 | + const el = screen.getByText("You already own", { exact: false }); |
| 33 | + expect(el.textContent).toEqual("You already own 'test-snap-name'."); |
| 34 | + }); |
| 35 | + |
| 36 | + test("directs user to request a reserved name", () => { |
| 37 | + renderComponent("reserved_name"); |
| 38 | + expect( |
| 39 | + screen.getByRole("link", { name: "request a reserved name" }), |
| 40 | + ).toBeInTheDocument(); |
| 41 | + }); |
| 42 | + |
| 43 | + test("informs user if no permission to register snap", () => { |
| 44 | + renderComponent("no-permission"); |
| 45 | + expect( |
| 46 | + screen.getByText( |
| 47 | + "You do not have permission to register snaps to this store. Contact the store administrator.", |
| 48 | + ), |
| 49 | + ).toBeInTheDocument(); |
| 50 | + }); |
| 51 | + |
| 52 | + test("informs user if snap needs to be registered", () => { |
| 53 | + renderComponent("other_error_code"); |
| 54 | + expect( |
| 55 | + screen.getByText( |
| 56 | + "Before you can push your snap to the store, its name must be registered", |
| 57 | + ), |
| 58 | + ).toBeInTheDocument(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments