Skip to content

Commit 4ff4661

Browse files
AlecRustjaapmarcus
authored andcommitted
Add install builder tests
1 parent 1a08c10 commit 4ff4661

File tree

8 files changed

+1540
-5
lines changed

8 files changed

+1540
-5
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
**/node_modules/
66
**/vendor/
77

8-
# vitepress
8+
# VitePress
99
**/.vitepress/dist/
10+
!docs/.vitepress/
11+
docs/.vitepress/cache/

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
docs:
11+
name: Docs site
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: "lts/*"
21+
22+
- name: Install Node packages
23+
run: npm ci --ignore-scripts
24+
25+
- name: Run docs site tests
26+
run: npm run docs:test
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2+
import { render, fireEvent, screen, cleanup, waitFor } from '@testing-library/vue';
3+
import CopyToClipboardInput from './CopyToClipboardInput.vue';
4+
5+
// Mock the clipboard API
6+
Object.assign(navigator, {
7+
clipboard: {
8+
writeText: vi.fn(() => Promise.resolve()),
9+
},
10+
});
11+
12+
describe('CopyToClipboardInput', () => {
13+
beforeEach(() => {
14+
render(CopyToClipboardInput, {
15+
props: { value: 'Test text' },
16+
});
17+
});
18+
19+
afterEach(() => {
20+
cleanup();
21+
});
22+
23+
it('renders correctly', () => {
24+
const input = screen.getByRole('textbox');
25+
const button = screen.getByRole('button', { name: 'Copy' });
26+
27+
expect(input).toBeTruthy();
28+
expect(button).toBeTruthy();
29+
});
30+
31+
it('selects text when input is focused', async () => {
32+
const input = screen.getByRole('textbox');
33+
await fireEvent.focus(input);
34+
35+
expect(input.selectionStart).toBe(0);
36+
expect(input.selectionEnd).toBe('Test text'.length);
37+
});
38+
39+
it('copies text to clipboard when button is clicked', async () => {
40+
const button = screen.getByRole('button', { name: 'Copy' });
41+
await fireEvent.click(button);
42+
43+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('Test text');
44+
await waitFor(() => expect(button.textContent).toBe('Copied!'));
45+
});
46+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import { render, fireEvent, screen, cleanup, waitFor } from '@testing-library/vue';
3+
import FloatingVue from 'floating-vue';
4+
import InstallBuilder from './InstallBuilder.vue';
5+
6+
describe('InstallBuilder', () => {
7+
const options = [
8+
{ flag: 'option1', label: 'Option 1', description: 'Description for Option 1', default: 'no' },
9+
{
10+
flag: 'option2',
11+
label: 'Option 2',
12+
description: 'Description for Option 2',
13+
type: 'text',
14+
default: '',
15+
},
16+
{
17+
flag: 'option3',
18+
label: 'Option 3',
19+
description: 'Description for Option 3',
20+
type: 'select',
21+
options: [
22+
{ value: 'val1', label: 'Value 1' },
23+
{ value: 'val2', label: 'Value 2' },
24+
],
25+
default: 'val1',
26+
},
27+
];
28+
29+
beforeEach(() => {
30+
render(InstallBuilder, {
31+
props: { options },
32+
global: {
33+
plugins: [FloatingVue],
34+
},
35+
});
36+
});
37+
38+
afterEach(() => {
39+
cleanup();
40+
});
41+
42+
it('renders all options correctly', () => {
43+
options.forEach((option) => {
44+
expect(screen.getByLabelText(option.label)).toBeTruthy();
45+
});
46+
});
47+
48+
it('toggles an option when clicked', async () => {
49+
const option1 = screen.getByLabelText(options[0].label);
50+
await fireEvent.click(option1);
51+
expect(option1.checked).toBe(true);
52+
});
53+
54+
it('updates the installation command when an option is toggled', async () => {
55+
const option1 = screen.getByLabelText(options[0].label);
56+
await fireEvent.click(option1);
57+
waitFor(() =>
58+
expect(screen.getByDisplayValue(/bash hst-install.sh --option1 yes/)).toBeTruthy(),
59+
);
60+
});
61+
62+
it('updates the installation command when option text input changes', async () => {
63+
const option2 = screen.getByLabelText(options[1].label);
64+
await fireEvent.click(option2);
65+
66+
const textInput = screen.getByLabelText(options[1].description);
67+
await fireEvent.update(textInput, 'custom-value');
68+
69+
expect(screen.getByDisplayValue(/bash hst-install.sh --option2 custom-value/)).toBeTruthy();
70+
});
71+
72+
it('updates the installation command when option select input changes', async () => {
73+
const option3 = screen.getByLabelText(options[2].label);
74+
await fireEvent.click(option3);
75+
76+
const selectInput = screen.getByLabelText(options[2].description);
77+
await fireEvent.update(selectInput, { target: { value: 'val2' } });
78+
79+
waitFor(() =>
80+
expect(screen.getByDisplayValue(/bash hst-install.sh --option3 val2/)).toBeTruthy(),
81+
);
82+
});
83+
});

docs/.vitepress/theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import '@fortawesome/fontawesome-free/css/solid.css';
44
import './styles/base.css';
55
import './styles/vars.css';
66
import 'floating-vue/dist/style.css';
7+
import FloatingVue from 'floating-vue';
78
import FeaturePage from './components/FeaturePage.vue';
89
import InstallPage from './components/InstallPage.vue';
9-
import FloatingVue from 'floating-vue';
1010

1111
export default {
1212
...Theme,

docs/.vitepress/vitest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'vitest/config';
2+
import vue from '@vitejs/plugin-vue';
3+
4+
export default defineConfig({
5+
test: {
6+
environment: 'jsdom',
7+
},
8+
plugins: [vue()],
9+
});

0 commit comments

Comments
 (0)