e2e: search and install (#600)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-05-12 19:15:34 +08:00 committed by GitHub
parent 5cbe8cade5
commit fa82d54279
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 98 additions and 12 deletions

View file

@ -79,6 +79,17 @@ pnpm install
pnpm build:desktop pnpm build:desktop
``` ```
## Build:lite
Builds a `.app` that is not codesigned or notarized. Ideal for local testing.
```
export CSC_IDENTITY_AUTO_DISCOVER=false
export MAC_BUILD_TARGET=dir
pnpm install
pnpm build:desktop
```
## Dev ## Dev
```sh ```sh

View file

@ -45,6 +45,7 @@
</script> </script>
<Button <Button
data-testid="install-button-{pkg.slug}"
class="w-full border p-0 text-xs text-white {buttonSize === 'small' ? 'h-8' : 'h-10'}" class="w-full border p-0 text-xs text-white {buttonSize === 'small' ? 'h-8' : 'h-10'}"
type="plain" type="plain"
color={getColor(pkg.state)} color={getColor(pkg.state)}

View file

@ -53,6 +53,7 @@
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div <div
class="version-item flex items-center justify-start gap-x-1 text-xs" class="version-item flex items-center justify-start gap-x-1 text-xs"
data-testid="install-{idx === 0 && pkg.version === version ? 'latest' : version}"
class:installable-version={!installedVersions.includes(version)} class:installable-version={!installedVersions.includes(version)}
on:click={(evt) => handleClick(evt, version)} on:click={(evt) => handleClick(evt, version)}
> >

View file

@ -29,7 +29,7 @@
: pkg.thumb_image_url} : pkg.thumb_image_url}
alt={pkg.name} alt={pkg.name}
/> />
<header class="flex-grow" on:click={() => gotoPackagePage()}> <header data-testid="card-result-{pkg.slug}" class="flex-grow" on:click={() => gotoPackagePage()}>
<h1>{pkg.full_name}</h1> <h1>{pkg.full_name}</h1>
<p class="text-xs line-clamp-2">{pkg.desc}</p> <p class="text-xs line-clamp-2">{pkg.desc}</p>
</header> </header>

View file

@ -45,10 +45,11 @@
{#if $searching === true} {#if $searching === true}
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div id="bg-close" class="z-40" on:click={onClose} /> <div id="bg-close" class="z-40" on:click={onClose} />
<section class="z-50"> <section class="z-50" data-testid="search-popup">
<header class="flex border border-x-0 border-t-0 border-gray bg-black"> <header class="flex border border-x-0 border-t-0 border-gray bg-black">
<div class="relative w-full"> <div class="relative w-full">
<SearchInput <SearchInput
data-testid="search-input-popup"
class="h-9 w-full rounded-sm" class="h-9 w-full rounded-sm"
size="small" size="small"
autofocus={true} autofocus={true}

View file

@ -12,7 +12,7 @@
$: needsUpdateCount = $packageList.filter((p) => p.state === PackageStates.NEEDS_UPDATE).length; $: needsUpdateCount = $packageList.filter((p) => p.state === PackageStates.NEEDS_UPDATE).length;
</script> </script>
<aside class="border border-b-0 border-l-0 border-t-0 border-gray p-2"> <aside id="side-menu" class="border border-b-0 border-l-0 border-t-0 border-gray p-2">
<ul class="flex flex-col gap-1 px-1 pt-4"> <ul class="flex flex-col gap-1 px-1 pt-4">
<MenuButton <MenuButton
label={$t("tags.discover").toLowerCase()} label={$t("tags.discover").toLowerCase()}

View file

@ -22,7 +22,7 @@
on:dblclick={topbarDoubleClick} on:dblclick={topbarDoubleClick}
> >
<ul class="flex h-10 items-center gap-1 pl-20 align-middle leading-10 text-gray"> <ul class="flex h-10 items-center gap-1 pl-20 align-middle leading-10 text-gray">
<a href="/?tab=discover"> <a href="/?tab=discover" data-testid="home-button">
<div class="home-btn w-12 text-center text-2xl"> <div class="home-btn w-12 text-center text-2xl">
<i class="icon-tea-logo-iconasset-1" /> <i class="icon-tea-logo-iconasset-1" />
</div> </div>
@ -43,6 +43,7 @@
</ul> </ul>
<div class="relative w-1/3 px-2"> <div class="relative w-1/3 px-2">
<SearchInput <SearchInput
data-testid="topbar-search-input"
class="h-9 w-full rounded-sm border border-gray" class="h-9 w-full rounded-sm border border-gray"
size="small" size="small"
placeholder={$t("store-search-placeholder")} placeholder={$t("store-search-placeholder")}

View file

@ -1,9 +1,17 @@
import { browser } from "wdio-electron-service"; import { browser } from "wdio-electron-service";
import { setupUtils } from "./utils.ts"; import { setupUtils, sleep } from "./utils.ts";
type utilType = ReturnType<typeof setupUtils>;
describe("basic smoke test", () => { describe("basic smoke test", () => {
let utils: utilType;
beforeEach(async () => {
utils = setupUtils(browser);
await utils.goHome();
});
it("install brewkit from the made by tea tab", async () => { it("install brewkit from the made by tea tab", async () => {
const utils = setupUtils(browser);
const { screen } = utils!; const { screen } = utils!;
// app launches to discover screen by default - make sure Stable Diffusion is there // app launches to discover screen by default - make sure Stable Diffusion is there
@ -33,5 +41,46 @@ describe("basic smoke test", () => {
) )
).toExist(); ).toExist();
await expect(await screen.findByRole("button", { name: "OPEN IN TERMINAL" })).toExist(); await expect(await screen.findByRole("button", { name: "OPEN IN TERMINAL" })).toExist();
const closeNotificationBtn = $(".close-notification");
await expect(closeNotificationBtn).toExist();
await closeNotificationBtn.click();
await expect(closeNotificationBtn).not.toExist();
});
it("search and install create-dmg", async () => {
const { screen } = utils!;
const fakeInput = await screen.findByTestId("topbar-search-input");
await fakeInput.click();
await (await screen.findByTestId("search-popup")).waitForExist();
const searchInput = await screen.findByTestId("search-input-popup");
await searchInput.setValue("create-dmg");
const packageFullname = "github.com/create-dmg/create-dmg";
const createDmgSlug = packageFullname.replace(/[^\w\s]/gi, "_").toLocaleLowerCase();
const createDmgCard = await utils.findSearchPackageCardBySlug(createDmgSlug);
await expect(createDmgCard).toExist();
createDmgCard.click();
await utils.packageDetailsLoaded();
await utils.uninstallPackageIfNeeded();
await utils.installLatestVersion();
await expect(
await screen.findByText(
/^Package github.com\/create-dmg\/create-dmg .* has been installed./,
{},
{ timeout: 60000, interval: 1000 }
)
).toExist();
const closeNotificationBtn = $(".close-notification");
await expect(closeNotificationBtn).toExist();
await closeNotificationBtn.click();
await expect(closeNotificationBtn).not.toExist();
}); });
}); });

View file

@ -1,4 +1,4 @@
import testingLibraryWdio from "@testing-library/webdriverio"; import * as testingLibraryWdio from "@testing-library/webdriverio";
// work around for importing CommonJS module // work around for importing CommonJS module
const { setupBrowser } = testingLibraryWdio; const { setupBrowser } = testingLibraryWdio;
@ -21,6 +21,16 @@ export function setupUtils(browser: WebdriverIO.Browser) {
return (await screen.findByTestId(`package-card-${slug}`)) as unknown as HTMLElement; return (await screen.findByTestId(`package-card-${slug}`)) as unknown as HTMLElement;
}; };
//
// Search Popup
//
// Find a package card on a package list screen
const findSearchPackageCardBySlug = async (slug: string) => {
// Trying to find the anchor tag role doesn't work, so we have to find by test id of the div inside the anchor
return (await screen.findByTestId(`card-result-${slug}`)) as unknown as HTMLElement;
};
// //
// Package Details Page // Package Details Page
// //
@ -44,15 +54,25 @@ export function setupUtils(browser: WebdriverIO.Browser) {
const installButton = await findButton(/^INSTALL |^UPDATE/); const installButton = await findButton(/^INSTALL |^UPDATE/);
installButton.click(); installButton.click();
// install the latest version const latestButton = await screen.findByTestId("install-latest");
const versionInstallButton = (await screen.findByText(/(latest)/)) as unknown as HTMLElement; await latestButton.waitForExist();
versionInstallButton.click(); latestButton.click();
};
const goHome = async () => {
// await browser.url("/");
const homeButton = await screen.findByTestId("home-button");
await homeButton.click();
const homeMenu = $("#side-menu");
await homeMenu.waitForExist();
}; };
return { return {
screen, screen,
goHome,
findButton, findButton,
findPackageCardBySlug, findPackageCardBySlug,
findSearchPackageCardBySlug,
packageDetailsLoaded, packageDetailsLoaded,
uninstallPackageIfNeeded, uninstallPackageIfNeeded,
installLatestVersion installLatestVersion

View file

@ -16,7 +16,7 @@ export const config: Options.Testrunner = {
transpileOnly: true transpileOnly: true
} }
}, },
specs: ["./test/specs/**/*.ts"], specs: ["./test/specs/**/*.e2e.ts"],
exclude: [ exclude: [
// 'path/to/excluded/files' // 'path/to/excluded/files'
], ],

View file

@ -15,6 +15,7 @@
<div class="button-container"> <div class="button-container">
<button <button
data-testid={$$props["data-testid"] || "button"}
type="button" type="button"
class="w-full text-gray {clazz} {type} {color}" class="w-full text-gray {clazz} {type} {color}"
class:active class:active

View file

@ -28,7 +28,7 @@
}}>{notification.callback_label}</button }}>{notification.callback_label}</button
> >
{/if} {/if}
<button class="icon-tea-x-btn mt-1 text-xs" on:click={onClose} /> <button class="close-notification icon-tea-x-btn mt-1 text-xs" on:click={onClose} />
</div> </div>
</div> </div>

View file

@ -53,6 +53,7 @@
<i class="icon-search-icon" /> <i class="icon-search-icon" />
</div> </div>
<input <input
data-testid={$$props["data-testid"] || "search-input"}
bind:this={searchInput} bind:this={searchInput}
type="search" type="search"
class="flex-grow pb-2 text-sm" class="flex-grow pb-2 text-sm"