Skip to content

Commit 8759de5

Browse files
Merge pull request #26 from webdevnerdstuff/tests
Tests
2 parents cf45a76 + d2f7147 commit 8759de5

File tree

81 files changed

+8608
-2892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+8608
-2892
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trim_trailing_whitespace = false
1313

1414
[*.{yml,yaml}]
1515
indent_size = 2
16+
indent_style = space
1617

1718
[*.{js,ts,mts,vue}]
1819
indent_size = 2

.github/workflows/cypress.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Cypress Tests with Dependency and Artifact Caching
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
install:
9+
runs-on: ubuntu-22.04
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup pnpm
15+
uses: pnpm/action-setup@v4
16+
with:
17+
version: 9
18+
19+
- name: Install dependencies
20+
run: pnpm install
21+
22+
- name: Build application
23+
run: pnpm build
24+
25+
- name: Save build folder
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: build
29+
if-no-files-found: error
30+
path: ./dist
31+
32+
cypress-run:
33+
runs-on: ubuntu-22.04
34+
needs: install
35+
steps:
36+
- name: Setup pnpm
37+
uses: pnpm/action-setup@v4
38+
with:
39+
version: 9
40+
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Download the build folder
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: build
48+
path: ./dist
49+
50+
- name: Install dependencies
51+
run: pnpm install
52+
53+
- name: Cypress run
54+
uses: cypress-io/github-action@v6
55+
with:
56+
start: pnpm cy:run
57+
component: true
58+
browser: chrome

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ dist-ssr
2828

2929
src/plugin/**/*.bk.*
3030

31+
# Temp files and directories
32+
*__TEMP.*
33+
*__TEMP/
3134

35+
# Cypress
36+
cypress/downloads
37+
cypress/screenshots
38+
cypress/videos

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22

3-
npx lint-staged && npm run test:build
3+
# npx lint-staged && npm run test:build
44
npx lint-staged

.husky/prepare-commit-msg

-3
This file was deleted.

cypress.config.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'cypress';
2+
import customViteConfig from './vite.cypress.config';
3+
4+
export default defineConfig({
5+
e2e: {
6+
setupNodeEvents(on, config) {
7+
config.env = {
8+
...process.env,
9+
...config.env,
10+
};
11+
return config;
12+
},
13+
specPattern: './src/**/*.spec.cy.{js,jsx,ts,tsx}',
14+
},
15+
16+
component: {
17+
devServer: {
18+
bundler: 'vite',
19+
framework: 'vue',
20+
viteConfig: customViteConfig,
21+
},
22+
specPattern: './src/**/*.cy.{js,jsx,ts,tsx}',
23+
viewportHeight: 800,
24+
viewportWidth: 1920,
25+
},
26+
});

cypress/fixtures/example.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/plugins/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('path');
2+
const { startDevServer } = require('@cypress/vite-dev-server');
3+
4+
module.exports = (on, config) => {
5+
config.env.tsconfigPath = path.resolve(__dirname, '../../tsconfig.cypress.json'); // Adjust the path as needed
6+
return config;
7+
};

cypress/support/commands.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

cypress/support/component-index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>

cypress/support/component.ts

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import './commands';
2+
import AppTemplate from '../templates/App.vue';
3+
import vuetify from "../../src/plugins/vuetify";
4+
import { h } from "vue";
5+
import { mount } from 'cypress/vue';
6+
import VStepperForm from '../../src/plugin/VStepperForm.vue';
7+
import * as DATA from '../templates/testData';
8+
import type { Component } from 'vue';
9+
import "cypress-real-events";
10+
11+
12+
// declare global {
13+
// namespace Cypress {
14+
// interface Chainable {
15+
// baseIconClass(icon: string): string;
16+
// getBaseStepperElements(excluded: string[]): Chainable;
17+
// getDataCy(value: string): Chainable<JQuery<HTMLElement>>;
18+
// mount: typeof mount;
19+
// mountComponent(options: any): Chainable;
20+
// }
21+
// }
22+
// }
23+
24+
Cypress.Commands.add('mount', (component: Component, options: any = {}) => {
25+
// Ensure global settings are defined
26+
options.global = options.global || {};
27+
options.global.stubs = options.global.stubs || {};
28+
options.global.stubs['transition'] = false;
29+
options.global.components = options.global.components || {};
30+
options.global.plugins = options.global.plugins || [vuetify];
31+
32+
// Process slots to ensure they are functions
33+
const slots = options.slots
34+
? Object.fromEntries(
35+
Object.entries(options.slots).map(([key, value]) => [
36+
key,
37+
// Convert strings or other non-function values into functions
38+
typeof value === 'function'
39+
? value
40+
: () => (typeof value === 'string' ? h('div', value) : h(value as any)),
41+
])
42+
)
43+
: {};
44+
45+
// Mount AppTemplate as the root and render `component` inside it
46+
return mount(AppTemplate, {
47+
...options,
48+
slots: {
49+
// Render the main component in the default slot of AppTemplate
50+
default: () => h(component, options.props, slots),
51+
},
52+
}) as Cypress.Chainable;
53+
});
54+
55+
56+
Cypress.Commands.add('getDataCy', (name: string) => {
57+
return cy.get(`[data-cy="${name}"]`);
58+
});
59+
60+
const answers = {
61+
buttonField: null,
62+
};
63+
64+
const buttonField = DATA.buttonFieldOptions;
65+
66+
const fieldDefault = {
67+
label: 'Button Field Question',
68+
name: 'buttonField',
69+
options: buttonField.options.basic,
70+
type: 'buttons' as const,
71+
};
72+
73+
const globalOptions = {
74+
validateOn: 'blur',
75+
};
76+
77+
interface MountComponentOptions {
78+
modelValue?: Record<string, any>;
79+
field?: Partial<typeof fieldDefault>;
80+
globalProps?: Record<string, any>;
81+
stepperProps?: Record<string, any>;
82+
}
83+
84+
Cypress.Commands.add('mountComponent', (options: MountComponentOptions = {}) => {
85+
const { modelValue = {}, field = {}, globalProps = {}, stepperProps = {} } = options;
86+
87+
const localModelValue = { ...answers, ...modelValue };
88+
89+
return cy.then(() => {
90+
cy.mount(VStepperForm as any, {
91+
props: {
92+
modelValue: localModelValue,
93+
pages: [{ fields: [{ ...fieldDefault, ...field, }], }],
94+
onSubmit: stepperProps.onSubmit ?? undefined,
95+
validationSchema: stepperProps.validationSchema ?? undefined,
96+
...stepperProps,
97+
},
98+
global: { provide: { globalOptions: { ...globalOptions, ...globalProps }, }, },
99+
}).as('wrapper');
100+
});
101+
});
102+
103+
104+
Cypress.Commands.add('getBaseStepperElements', (excluded = []) => {
105+
// Stepper Form //
106+
cy.get('[data-cy="vsf-stepper-form"]').as('stepperForm');
107+
cy.get('@stepperForm')
108+
.should('exist')
109+
.and('be.visible');
110+
111+
// Stepper Header //
112+
cy.getDataCy('vsf-stepper-header').as('stepperHeader');
113+
cy.get('@stepperHeader')
114+
.should('exist')
115+
.and('be.visible');
116+
117+
cy.get('@stepperHeader')
118+
.find('.v-stepper-item')
119+
.as('stepperHeaderItems');
120+
121+
// Application Wrap //
122+
cy.get('.v-application__wrap').as('appWrap');
123+
124+
// Submit Button //
125+
if (!excluded.includes('buttonsField')) {
126+
cy.getDataCy('vsf-submit-button')
127+
.should('exist')
128+
.and('be.visible');
129+
130+
// Field Group and Buttons //
131+
cy.getDataCy('vsf-field-group-buttonField').as('fieldGroup');
132+
cy.getDataCy('vsf-field-group-buttonField').find('button').as('fieldButtons');
133+
}
134+
});
135+
136+
cy.baseIconClass = (icon: string) => {
137+
return icon.replace(/^mdi:/, '');
138+
};
139+
140+
141+
142+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Navigation //
143+
Cypress.Commands.add('navigationMountComponent', (options = {}) => {
144+
const { editable = true, jumpAhead = true, pages, validationSchema = undefined } = options || {};
145+
const answers = DATA.navigationTest.answers;
146+
147+
cy.mount(VStepperForm as any, {
148+
props: {
149+
answers,
150+
editable,
151+
jumpAhead,
152+
modelValue: answers,
153+
pages,
154+
validationSchema,
155+
},
156+
global: DATA.navigationTest.global,
157+
});
158+
});
159+
160+
Cypress.Commands.add('navigationGetButtons', () => {
161+
cy.getBaseStepperElements(['buttonsField']);
162+
cy.getDataCy('vsf-next-button').as('nextButton');
163+
cy.getDataCy('vsf-previous-button').as('previousButton');
164+
});
165+
166+
Cypress.Commands.add('checkedEnabledDisabledHeaderItems', ({ enabled, disabled, pages }) => {
167+
pages.forEach((_, index) => {
168+
if (enabled.includes(index)) {
169+
cy.get('@stepperHeaderItems')
170+
.eq(index)
171+
.should('be.enabled');
172+
}
173+
174+
if (disabled.includes(index)) {
175+
cy.get('@stepperHeaderItems')
176+
.eq(index)
177+
.should('be.disabled');
178+
}
179+
});
180+
});
181+
182+
cy.cloneArray = (array: any[]): any[] => {
183+
return JSON.parse(JSON.stringify(array));
184+
};

cypress/support/e2e.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)