Improve testing suite

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-03-24 15:05:15 +01:00
parent 6f2f8c454f
commit 286cb1cd21
44 changed files with 2550 additions and 482 deletions
+23 -11
View File
@@ -1,18 +1,30 @@
import Search from "./Search.svelte";
import { mount } from "radicle-svelte-unit-test";
import { styles } from "@test/support/index";
import { fireEvent, render } from "@testing-library/svelte";
import "@public/index.css";
describe('Search', function () {
it("Renders correctly", () => {
mount(Search, {}, styles);
cy.get("input").should("exist");
describe('Logic', () => {
it("show a appropiate placeholder", () => {
render(Search);
cy.get("input").should("have.attr", "placeholder", "Search a name or address...");
});
it("Search input displays and navigates correctly", () => {
mount(Search, {}, styles);
cy.get("input").type("cloudhead{enter}");
cy.get("input").should("have.value", "cloudhead");
cy.url().should("contain", "/resolver/query?q=cloudhead");
it("allow input a query and navigates accordingly", () => {
render(Search);
cy.get("input").type("cloudhead.radicle.eth{enter}");
cy.get("input").should("have.value", "cloudhead.radicle.eth");
cy.url().should("contain", "/resolver/query?q=cloudhead.radicle.eth");
});
});
describe("Events", () => {
it("should fire an event when the input changes", () => {
const { component } = render(Search);
const mock = cy.spy();
component.$on("search", mock);
cy.get("input").then(([input]) => {
fireEvent.keyDown(input, { key: "Enter" });
expect(mock).to.have.been.calledOnce;
});
});
});