Skip to content

Commit a5aaf0b

Browse files
committed
Add tests for 'theme' command functionality: verify theme changes, available themes display, and error handling for invalid inputs
1 parent e551f44 commit a5aaf0b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/terminal-commands.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,63 @@ test.describe('React Terminal Emulator - File Operations & Commands', () => {
718718
expect(outputText?.trim()).not.toContain('ls');
719719
});
720720
});
721+
722+
test.describe('Theme command', () => {
723+
test.beforeEach(async ({ page }) => {
724+
await page.goto('/');
725+
await page.waitForLoadState('networkidle');
726+
});
727+
728+
test('should change the theme when using the theme command', async ({ page }) => {
729+
const terminalBodyContainer = page.locator(SELECTORS.terminalBodyContainer);
730+
731+
// The initial theme is 'default', with background '#440a2b' -> rgb(68, 10, 43)
732+
await expect(terminalBodyContainer).toHaveCSS('background-color', 'rgb(68, 10, 43)');
733+
734+
// Change theme to dracula
735+
await page.keyboard.type('theme set dracula');
736+
await page.keyboard.press('Enter');
737+
738+
// Assert that the new color matches the dracula theme's background
739+
// The color value is '#282a36' -> rgb(40, 42, 54)
740+
await expect(terminalBodyContainer).toHaveCSS('background-color', 'rgb(40, 42, 54)');
741+
});
742+
743+
test('should show available themes when no subcommand is provided', async ({ page }) => {
744+
await page.keyboard.type('theme');
745+
await page.keyboard.press('Enter');
746+
747+
const lastCommandOutput = page.locator(SELECTORS.commandOutput).last();
748+
await expect(lastCommandOutput).toContainText('Available themes:');
749+
await expect(lastCommandOutput).toContainText('Usage: theme set {theme_name}');
750+
});
751+
752+
test('should show usage message when "set" is used without a theme name', async ({ page }) => {
753+
await page.keyboard.type('theme set');
754+
await page.keyboard.press('Enter');
755+
756+
const lastCommandOutput = page.locator(SELECTORS.commandOutput).last();
757+
await expect(lastCommandOutput).toContainText('Usage: theme set {theme_name}');
758+
await expect(lastCommandOutput).toContainText('Available themes:');
759+
});
760+
761+
test('should show error for non-existent theme', async ({ page }) => {
762+
await page.keyboard.type('theme set non_existent_theme');
763+
await page.keyboard.press('Enter');
764+
765+
const lastCommandOutput = page.locator(SELECTORS.commandOutput).last();
766+
await expect(lastCommandOutput).toContainText("Theme 'non_existent_theme' not found.");
767+
await expect(lastCommandOutput).toContainText('Available themes:');
768+
});
769+
770+
test('should show error for unknown subcommand', async ({ page }) => {
771+
await page.keyboard.type('theme invalid_subcommand');
772+
await page.keyboard.press('Enter');
773+
774+
const lastCommandOutput = page.locator(SELECTORS.commandOutput).last();
775+
await expect(lastCommandOutput).toContainText(
776+
"theme: unknown subcommand 'invalid_subcommand'"
777+
);
778+
await expect(lastCommandOutput).toContainText('Usage: theme set {theme_name}');
779+
});
780+
});

0 commit comments

Comments
 (0)