Skip to content

Commit

Permalink
fix: improve automated testing
Browse files Browse the repository at this point in the history
Signed-off-by: The1111mp <The1111mp@outlook.com>
  • Loading branch information
1111mp committed Feb 13, 2024
1 parent 8cbacf7 commit a8b319b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
6 changes: 3 additions & 3 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ export default defineConfig(({ mode }) => {
const isProd = mode === "production",
isTest = process.env.TEST === "true";

return {
return {
main: {
clean: true,
entry: [isTest ? "src/main/main.test.ts" : "src/main/main.ts"],
entry: { main: isTest ? "src/main/main.test.ts" : "src/main/main.ts" },
target: "node18",
format: "esm",
minify: isProd,
watch: !isProd
},
preload: {
clean: true,
entry: [isTest ? "src/preload/preload.test.ts" : "src/preload/index.ts"],
entry: { preload: isTest ? "src/preload/preload.test.ts" : "src/preload/index.ts" },
format: "cjs",
minify: isProd,
watch: !isProd
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dev": "electron-vite-tsup dev --watch",
"build": "electron-vite-tsup build --outDir=release/app/dist",
"postinstall": "electron-builder install-app-deps",
"package": "electron-builder build --publish never",
"package": "npm run build && electron-builder build --publish never",
"package:mac": "npm run build && electron-builder build --publish never --mac",
"package:linux": "npm run build && electron-builder build --publish never --linux",
"package:win": "npm run build && electron-builder build --publish never --win",
Expand All @@ -41,7 +41,7 @@
"publish": "npm run build && electron-builder build --publish always",
"publish:all": "npm run build && electron-builder build --publish always -mwl",
"rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app",
"test": "wdio run ./wdio.conf.ts"
"test": "TS_NODE_TRANSPILE_ONLY=true wdio run ./wdio.conf.ts"
},
"dependencies": {
"@electron-toolkit/preload": "^3.0.0",
Expand Down
12 changes: 3 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions src/__tests__/specs/setting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ describe("Module Setting", () => {

describe("Language", async () => {
it("should be set & update", async () => {
const defaultLocale = await (await browser.$(".ant-select-selection-item")).getText(),
await (await browser.$('button[data-testid="setting-trigger"]')).click();

const trigger = await browser.$('button[data-testid="language-trigger"]');
const defaultLocale = await browser.waitUntil(async () => {
return await trigger.getText();
}),
selectLocale = defaultLocale === "English" ? "简体中文" : "English",
index = selectLocale === "English" ? 1 : 0;
index = defaultLocale === "English" ? 0 : 1;

await (await browser.$('button[data-testid="language-trigger"]')).click();

const exist = await browser.waitUntil(
async function () {
return await browser
.$$(".ant-select-item-option")
[index].$(".ant-select-item-option-content")
.getText();
const item = await browser.$$('div[data-testid="language-item"]')[index];
return await item.$$("span")[1].getText();
},
{
timeout: 5000,
Expand All @@ -40,11 +45,13 @@ describe("Module Setting", () => {

expect(exist).toHaveText(selectLocale);

await (await browser.$$(".ant-select-item-option"))[index].click();
await (await browser.$$('div[data-testid="language-item"]'))[index].click();

await expect(await browser.$(".ant-select-selection-item")).toHaveText(selectLocale);
await expect(await browser.$('button[data-testid="language-trigger"]')).toHaveText(
selectLocale
);

await (await screen.getByTestId("setting-submit")).click();
await (await browser.getByTestId("setting-submit")).click();
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ const createWindow = async (code?: number) => {
? "#000000"
: "#ffffff",
webPreferences: {
preload: app.isPackaged
? join(__dirname, "../preload/index.js")
: join(__dirname, "../../out/preload/index.js")
preload: app.isPackaged
? join(__dirname, "../preload/preload.js")
: join(__dirname, "../../out/preload/preload.js")
}
});

Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/components/ui/auto-complete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const AutoComplete: React.FC<AutoCompleteProps> = memo(
<CommandInput
ref={input}
value={value}
className="h-8"
placeholder={placeholder}
onFocus={() => setOpen(true)}
onBlur={() => setOpen(false)}
Expand Down
16 changes: 12 additions & 4 deletions src/renderer/src/pages/home/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const Setting: React.FC<Props> = memo(({}) => {
<SheetTrigger asChild>
<Button
className="nvmd-setting"
data-testid="setting-trigger"
size="sm"
title={i18n("Setting")}
variant="ghost"
Expand All @@ -157,13 +158,20 @@ export const Setting: React.FC<Props> = memo(({}) => {
<FormControl>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger className="w-44 h-8">
<SelectValue placeholder="Select a language to display" />
<SelectTrigger data-testid="language-trigger" className="w-44 h-8">
<SelectValue
data-testid="language-value"
placeholder="Select a language to display"
/>
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="zh-CN">简体中文</SelectItem>
<SelectItem value="en">English</SelectItem>
<SelectItem data-testid="language-item" value="zh-CN">
简体中文
</SelectItem>
<SelectItem data-testid="language-item" value="en">
English
</SelectItem>
</SelectContent>
</Select>
</FormControl>
Expand Down

0 comments on commit a8b319b

Please sign in to comment.