-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from NoamRa/tests-tests-tests
tests!
- Loading branch information
Showing
11 changed files
with
25,772 additions
and
14,169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"setsar", | ||
"STARTPTS", | ||
"submenu", | ||
"testid", | ||
"timecode", | ||
"togglefullscreen", | ||
"typecheck", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { parseProgress } from "./parseProgress"; | ||
|
||
describe("Test parseProgress", () => { | ||
it("should parse progress string", () => { | ||
const example = ` | ||
foo=BAR fps=2 width=high! number=5 percent=66% | ||
time=01:23:45.67 last=one | ||
`; | ||
expect(parseProgress(example)).toEqual({ | ||
foo: "BAR", | ||
fps: 2, | ||
number: 5, | ||
percent: "66%", | ||
width: "high!", | ||
time: "01:23:45.67", | ||
last: "one", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testRegex: ".test.(ts|tsx?)$", | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { genShortId } from "./generateId"; | ||
|
||
describe("Test ID generation", () => { | ||
it("should create unique IDs with prefix", () => { | ||
// for genShortId and its 3 random bytes, 1000 ids should be | ||
// enough of a validation for uniqueness | ||
const length = 1000; | ||
const prefix = "test-short-id"; | ||
const IDs = [ | ||
...new Set(Array.from({ length }, () => genShortId("test-short-id"))), | ||
]; | ||
expect(IDs).toHaveLength(length); | ||
expect(IDs.every((id) => id.includes(prefix))).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { fireEvent, render, screen } from "./testUtils/testUtils"; | ||
import { App } from "./App"; | ||
import { presets } from "./presets"; | ||
|
||
describe("Test Navigation", () => { | ||
it("should see the app's title and preset selection", () => { | ||
render(<App />); | ||
|
||
expect(screen.getByText("Alpha-Badger🦡")).toBeVisible(); | ||
|
||
expect(screen.getByLabelText("Choose preset:")).toBeVisible(); | ||
|
||
expect(screen.getAllByRole("option").length).toBe(presets.length); | ||
}); | ||
|
||
it("should be able to switch between presets and see the preset's description", async () => { | ||
const getOption = (name: string): HTMLOptionElement => { | ||
return screen.getByRole<HTMLOptionElement>("option", { name }); | ||
}; | ||
|
||
render(<App />); | ||
|
||
let presetUnderTestIndex = 0; | ||
let presetUnderTest = presets[presetUnderTestIndex]; | ||
presets.forEach((preset) => { | ||
if (preset === presetUnderTest) { | ||
expect(screen.getByText(preset.name)).toBeVisible(); | ||
expect(getOption(preset.name).selected).toBe(true); | ||
expect(screen.getByText(preset.description)).toBeVisible(); | ||
} else { | ||
expect(getOption(preset.name).selected).toBe(false); | ||
expect(screen.queryByText(preset.description)).toBeNull(); | ||
} | ||
}); | ||
|
||
// change to preset 1 | ||
presetUnderTestIndex = 1; | ||
presetUnderTest = presets[presetUnderTestIndex]; | ||
fireEvent.change(screen.getByLabelText("Choose preset:"), { | ||
target: { value: presetUnderTestIndex }, | ||
}); | ||
|
||
// assert change preset called the API | ||
expect(alphaBadgerApi.setSelectedPresetIndex).toHaveBeenCalledWith( | ||
presetUnderTestIndex, | ||
); | ||
// this asserts the mocked value has changed, unrelated to the state in App. | ||
// may be useful for catching regressions down the line | ||
expect(alphaBadgerApi.getSelectedPresetIndex()).toBe(presetUnderTestIndex); | ||
|
||
expect(getOption(presetUnderTest.name).selected).toBe(true); | ||
|
||
presets.forEach((preset) => { | ||
if (preset === presetUnderTest) { | ||
expect(getOption(preset.name).selected).toBe(true); | ||
expect(screen.getByText(preset.description)).toBeVisible(); | ||
} else { | ||
expect(getOption(preset.name).selected).toBe(false); | ||
expect(screen.queryByText(preset.description)).toBeNull(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
|
||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "jsdom", | ||
transform: { | ||
"^.+\\.tsx?$": "ts-jest", | ||
}, | ||
testRegex: ".test.(ts|tsx?)$", | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import path from "node:path"; | ||
import type { store } from "../../main/store"; | ||
|
||
import "@testing-library/jest-dom"; | ||
export * from "@testing-library/react"; | ||
|
||
import userEvent from "@testing-library/user-event"; | ||
export const user = userEvent.setup(); | ||
|
||
const mockedStore: typeof store = (() => { | ||
const _store = new Map(); | ||
|
||
return { | ||
getFFmpegPath: jest.fn((): string => { | ||
return _store.get("ffmpegPath") || ""; | ||
}), | ||
setFFmpegPath: jest.fn((ffmpegPath: string): void => { | ||
_store.set("ffmpegPath", ffmpegPath); | ||
}), | ||
getFFprobePath: jest.fn((): string => { | ||
return _store.get("ffprobePath") || ""; | ||
}), | ||
setFFprobePath: jest.fn((ffprobePath: string): void => { | ||
_store.set("ffprobePath", ffprobePath); | ||
}), | ||
getSelectedPresetIndex: jest.fn((): number => { | ||
return _store.get("selectedPresetIndex") || 0; | ||
}), | ||
setSelectedPresetIndex: jest.fn((selectedPresetIndex: number): void => { | ||
_store.set("selectedPresetIndex", selectedPresetIndex); | ||
}), | ||
}; | ||
})(); | ||
|
||
const mockedAlphaBadgerAPI: typeof alphaBadgerApi = { | ||
path, | ||
chooseFile: jest.fn(), | ||
chooseFiles: jest.fn(), | ||
chooseFolder: jest.fn(), | ||
|
||
readMetadata: jest.fn(), | ||
runFFmpegCommand: jest.fn(), | ||
stopAll: jest.fn(), | ||
|
||
// listeners | ||
onError: jest.fn(), | ||
onStart: jest.fn(), | ||
onEnd: jest.fn(), | ||
onProgress: jest.fn(), | ||
onData: jest.fn(), | ||
onCodecData: jest.fn(), | ||
removeListener: jest.fn(), | ||
|
||
// preset | ||
getSelectedPresetIndex: mockedStore.getSelectedPresetIndex, | ||
setSelectedPresetIndex: mockedStore.setSelectedPresetIndex, | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(globalThis as any)["alphaBadgerApi"] = mockedAlphaBadgerAPI; |