Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add new tests for components #2383

Merged
merged 40 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
21d82f6
test: add new tests for accordion and button
nmerget Mar 22, 2024
51d2c21
chore: update tests
nmerget Mar 22, 2024
8435c21
fix: issue with missing slot for vue components
nmerget Mar 27, 2024
99967ee
chore: update tabs, checkbox, radio, tag and tooltip tests
nmerget Mar 27, 2024
416ed30
chore: update select, textarea, input component tests
nmerget Mar 27, 2024
49403a3
Merge branch 'main' into test-add-new-compontent-tests
nmerget Mar 27, 2024
c8cf524
fix: issue with onInput for playwright tests
nmerget Mar 28, 2024
e37f7d6
fix: issue with typings for react
nmerget Mar 28, 2024
f8098ab
Update README.md
mfranzke Apr 3, 2024
e50ca63
Merge branch 'main' of github.com:db-ui/mono into test-add-new-compon…
nmerget Apr 9, 2024
5eb0982
chore: update snapshots
nmerget Apr 9, 2024
eafe2a5
fix: issue with component test for tabs
nmerget Apr 9, 2024
c0638a2
fix: issue with component test for tabs
nmerget Apr 9, 2024
bb7fc12
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 10, 2024
9841f9e
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 10, 2024
d10c8ee
Merge branch 'main' into test-add-new-compontent-tests
nmerget Apr 11, 2024
c3fd112
chore: update snapshots
nmerget Apr 11, 2024
eb2567f
Merge remote-tracking branch 'origin/test-add-new-compontent-tests' i…
nmerget Apr 11, 2024
3dc02a4
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 11, 2024
e758469
fix: issue headline for accordion
nmerget Apr 11, 2024
fa9b7fa
Merge branch 'main' into test-add-new-compontent-tests
nmerget Apr 11, 2024
7dd5178
Merge branch 'main' of github.com:db-ui/mono into test-add-new-compon…
nmerget Apr 15, 2024
0647746
chore: update from main
nmerget Apr 15, 2024
5430245
fix: issues with build
nmerget Apr 15, 2024
b9807e3
Update README.md
mfranzke Apr 16, 2024
bcf44e3
Merge branch 'main' of github.com:db-ui/mono into test-add-new-compon…
nmerget Apr 16, 2024
f473e47
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 16, 2024
c79111e
Merge branch 'main' of github.com:db-ui/mono into test-add-new-compon…
nmerget Apr 16, 2024
f43d972
Merge remote-tracking branch 'origin/test-add-new-compontent-tests' i…
nmerget Apr 16, 2024
0c40c1d
fix: issues with tests
nmerget Apr 16, 2024
60a4ec4
Merge branch 'main' into test-add-new-compontent-tests
nmerget Apr 16, 2024
690a47d
Update README.md
mfranzke Apr 17, 2024
4d96e8d
refactor: necessary renaming
mfranzke Apr 17, 2024
641177a
fix: issue with checkbox component test
nmerget Apr 17, 2024
7a7480d
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 17, 2024
8534963
chore: update snapshots
nmerget Apr 17, 2024
78a094d
fix: issue from merge
nmerget Apr 17, 2024
9ce7022
fix: issue with tag
nmerget Apr 17, 2024
13f7efd
Merge branch 'main' into test-add-new-compontent-tests
nmerget Apr 17, 2024
908e6e6
Merge branch 'main' into test-add-new-compontent-tests
mfranzke Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"regenerate:screenshots:rebuild": "npm run rm:builds && node scripts/rebuild-e2e.js",
"rm:builds": "npm run rm:builds --workspace=scripts",
"start": "npm run start --workspace=patternhub",
"test:react-components": "playwright test -c output/react/playwright.config.ts --ui",
"test:vue-components": "playwright test -c output/vue/playwright.config.ts --ui",
"update:dependency:playwright": "node .github/scripts/update-playwright.js",
"update:icon-fonts": "npm run update:icon-fonts --workspace=scripts"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DB<%= h.changeCase.pascal(name) %> } from "./index";
// @ts-ignore - vue can only find it with .ts as file ending
import { DEFAULT_VIEWPORT } from '../../shared/constants.ts';

const comp = <DB<%= h.changeCase.pascal(name) %>>Test</DB<%= h.changeCase.pascal(name) %>>;
const comp: any = <DB<%= h.changeCase.pascal(name) %>>Test</DB<%= h.changeCase.pascal(name) %>>;

const testComponent = () =>{
test('should contain text', async ({ mount }) => {
Expand All @@ -22,12 +22,7 @@ const testComponent = () =>{
});
}

test.describe('DB<%= h.changeCase.pascal(name) %>', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
});

test.describe('DB<%= h.changeCase.pascal(name) %>', () => {
const testA11y = () =>{
test('should not have any A11y issues', async ({
page,
mount
Expand All @@ -39,5 +34,11 @@ test.describe('DB<%= h.changeCase.pascal(name) %>', () => {

expect(accessibilityScanResults.violations).toEqual([]);
});
}

test.describe('DB<%= h.changeCase.pascal(name) %>', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
testA11y();
});

10 changes: 2 additions & 8 deletions packages/components/_templates/mitosis/new/component/tsx.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DB<%= h.changeCase.pascal(name) %>State, DB<%= h.changeCase.pascal(name
import { cls } from "../../utils";
<% if(formValue!=="no"){ -%>
import {ChangeEvent, InteractionEvent} from "../../shared/model";
import { handleFrameworkEvent } from "../../utils/form-components";
<% } -%>

useMetadata({
Expand All @@ -27,14 +28,7 @@ export default function DB<%= h.changeCase.pascal(name) %>(props: DB<%= h.change
props.change(event);
}

const target = event.target as HTMLInputElement;

// TODO: Replace this with the solution out of https://github.com/BuilderIO/mitosis/issues/833 after this has been "solved"
// VUE:this.$emit("update:<%= formValue %>", target.<%= formValue %>);

// Change event to work with reactive and template driven forms
// ANGULAR: this.propagateChange(target.<%= formValue %>);
// ANGULAR: this.writeValue(target.<%= formValue %>);
handleFrameworkEvent(this, event, <%= formValue %>);
},
handleBlur: (event: InteractionEvent<HTMLInputElement>) => {
if (props.onBlur) {
Expand Down
11 changes: 6 additions & 5 deletions packages/components/scripts/post-build/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ const setControlValueAccessorReplacements = (
// for native angular support (e.g. reactive forms) we have to implement
// the ControlValueAccessor interface with all impacts :/

replacements.push({
from: /\/\/ ANGULAR:/g,
to: ''
});

replacements.push({
from: '} from "@angular/core";',
to:
Expand Down Expand Up @@ -182,6 +177,12 @@ export class ${directive.name}Directive {}

module.exports = (tmp) => {
const outputFolder = `${tmp ? 'output/tmp' : 'output'}`;
// Activate vue specific event handling
Replace.sync({
files: `../../${outputFolder}/angular/src/utils/form-components.ts`,
from: /\/\/ ANGULAR:/g,
to: ''
});
for (const component of components) {
const componentName = component.name;
const upperComponentName = `DB${transformToUpperComponentName(component.name)}`;
Expand Down
5 changes: 5 additions & 0 deletions packages/components/scripts/post-build/copy-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module.exports = () => {
from: ['{/*', '*/}'],
to: ''
});
Replace({
files: `../../output/${framework}/src/components/${name}/${name}.spec.tsx`,
from: /\/\/ VUE:/g,
to: ''
});
}
}
Fse.copySync(
Expand Down
8 changes: 8 additions & 0 deletions packages/components/scripts/post-build/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const overwriteEvents = (tmp) => {
'export type ChangeEvent<T> = Event;',
'export type ChangeEvent<T> = React.ChangeEvent<T>;'
);
modelFileContent = modelFileContent.replace(
'export type InputEvent<T> = Event;',
'export type InputEvent<T> = React.FormEvent<T>;'
);
modelFileContent = modelFileContent.replace(
'export type InteractionEvent<T> = FocusEvent;',
'export type InteractionEvent<T> = React.FocusEvent<T>;'
Expand Down Expand Up @@ -48,6 +52,10 @@ module.exports = (tmp) => {
from: /= useState/g,
to: '= useState<any>'
},
{
from: `handleFrameworkEvent(this`,
to: `// handleFrameworkEvent(this`
},
{
from: ` } from "react"`,
to: `, forwardRef, HTMLAttributes } from "react"`
Expand Down
67 changes: 22 additions & 45 deletions packages/components/scripts/post-build/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,6 @@ const updateNestedComponents = (input, rootComponentName) => {
.join('\n');
};

/**
*
* @param input {string}
* @param bindings {{modelValue:string, binding:string}[]}
* @returns {*}
*/
const updateVModelBindings = (input, bindings) => {
let fileContent = input;

// Add emits to component config

fileContent = fileContent.replace(
'props: [',
`emits: ${JSON.stringify(
bindings.map((bin) => `update:${bin.modelValue}`)
)},\nprops: [`
);

return fileContent
.split('\n')
.map((line) => {
return line.replace('// VUE:', '');
})
.join('\n');
};

module.exports = (tmp) => {
const outputFolder = `${tmp ? 'output/tmp' : 'output'}`;
// Rewire imports in Playwright config
Expand All @@ -59,6 +33,12 @@ module.exports = (tmp) => {
from: /react/g,
to: `vue`
});
// Activate vue specific event handling
Replace.sync({
files: `../../${outputFolder}/vue/vue3/src/utils/form-components.ts`,
from: `// VUE:`,
to: ``
});
for (const component of components) {
const componentName = component.name;
const vueFile = `../../${outputFolder}/vue/src/components/${componentName}/${componentName}.vue`;
Expand All @@ -76,6 +56,14 @@ module.exports = (tmp) => {
from: `./${componentName}`,
to: `./${componentName}.vue`
});

const replacements = [
{
from: /immediate: true,/g,
to: 'immediate: true,\nflush: "post"'
}
];

Replace.sync({
files: vueFile,
processor(input) {
Expand All @@ -84,28 +72,17 @@ module.exports = (tmp) => {
});

if (component?.config?.vue?.vModel) {
Replace.sync({
files: vueFile,
processor(input) {
return updateVModelBindings(
input,
component.config.vue.vModel
);
}
replacements.push({
from: 'props: [',
to: `emits: ${JSON.stringify(
component?.config?.vue?.vModel.map(
(bin) => `update:${bin.modelValue}`
)
)},\nprops: [`
});
}

runReplacements(
[
{
from: /immediate: true,/g,
to: 'immediate: true,\nflush: "post"'
}
],
component,
'vue',
vueFile
);
runReplacements(replacements, component, 'vue', vueFile);
} catch (error) {
console.error('Error occurred:', error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DBAccordionItem } from './index';
// @ts-ignore - vue can only find it with .ts as file ending
import { DEFAULT_VIEWPORT } from '../../shared/constants.ts';

const comp = <DBAccordionItem headlinePlain="Test">Test</DBAccordionItem>;
const comp: any = <DBAccordionItem headlinePlain="Test">Test</DBAccordionItem>;

const testComponent = () => {
test('should contain text', async ({ mount }) => {
Expand All @@ -19,12 +19,7 @@ const testComponent = () => {
});
};

test.describe('DBAccordionItem', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
});

test.describe('DBAccordionItem', () => {
const testA11y = () => {
test('should not have any A11y issues', async ({ page, mount }) => {
await mount(comp);
const accessibilityScanResults = await new AxeBuilder({ page })
Expand All @@ -33,4 +28,10 @@ test.describe('DBAccordionItem', () => {

expect(accessibilityScanResults.violations).toEqual([]);
});
};

test.describe('DBAccordionItem', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
testA11y();
});
86 changes: 80 additions & 6 deletions packages/components/src/components/accordion/accordion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,43 @@ import { DBAccordion } from './index';
// @ts-ignore - vue can only find it with .ts as file ending
import { DEFAULT_VIEWPORT } from '../../shared/constants.ts';
import { DBAccordionItem } from '../accordion-item';
import { DBButton } from '../button';
import { DBTextarea } from '../textarea';

const comp = (
const comp: any = (
<DBAccordion>
<DBAccordionItem headlinePlain="Test" content="Content 1" />
<DBAccordionItem headlinePlain="Test 2" content="Content 2" />
<DBAccordionItem headlinePlain="Test 3" content="Content 3" />
</DBAccordion>
);

const openAccordion: any = (
<DBAccordion initOpenIndex={[1, 2]}>
<DBAccordionItem headlinePlain="Test" content="Content 1" />
<DBAccordionItem headlinePlain="Test 2">
<span data-testid="item2">Test2</span>
</DBAccordionItem>
<DBAccordionItem headlinePlain="Test 3">
<span data-testid="item3">Test3</span>
</DBAccordionItem>
</DBAccordion>
);

const actionAccordion: any = (
<DBAccordion behaviour="single">
<DBAccordionItem data-testid="item1" headline="Test">
<DBButton data-testid="button">Click me</DBButton>
</DBAccordionItem>
<DBAccordionItem data-testid="item2" headline="Test 2">
<DBTextarea data-testid="textarea" />
</DBAccordionItem>
<DBAccordionItem disabled={true} data-testid="item3" headline="Test 3">
<DBButton data-testid="button2">Click me</DBButton>
</DBAccordionItem>
</DBAccordion>
);

const testComponent = () => {
test('should contain text', async ({ mount }) => {
const component = await mount(comp);
Expand All @@ -26,12 +54,50 @@ const testComponent = () => {
});
};

test.describe('DBAccordion', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
});
const testOpen = () => {
test('items should be visible', async ({ mount }) => {
const component = await mount(openAccordion);
await expect(component.getByTestId('item2')).toBeVisible();
await expect(component.getByTestId('item3')).toBeVisible();
});

test.describe('DBAccordion', () => {
test('open items should match screenshot', async ({ mount }) => {
const component = await mount(openAccordion);
await expect(component).toHaveScreenshot();
});
};

const testAction = () => {
test('single behaviour should work', async ({ mount }) => {
const component = await mount(actionAccordion);
await component.getByTestId('item1').click();
await expect(component.getByTestId('button')).toBeVisible();
await component.getByTestId('item2').click();
await expect(component.getByTestId('button')).toBeHidden();
await expect(component.getByTestId('textarea')).toBeVisible();
await expect(component.getByTestId('item3')).toBeDisabled();
});

test('click inside item works', async ({ mount }) => {
const component = await mount(actionAccordion);
await component.getByTestId('item1').click();
const button = component.getByTestId('button');
await expect(button).toBeVisible();
await button.click();
await expect(button).toBeVisible();
});

test('textarea inside item works', async ({ mount }) => {
const component = await mount(actionAccordion);
await component.getByTestId('item2').click();
const textArea = component.getByRole('textbox');
await expect(textArea).toBeVisible();
await textArea.fill('Test');
await expect(textArea).toHaveValue('Test');
});
};

const testA11y = () => {
test('should not have any A11y issues', async ({ page, mount }) => {
await mount(comp);
const accessibilityScanResults = await new AxeBuilder({ page })
Expand All @@ -40,4 +106,12 @@ test.describe('DBAccordion', () => {

expect(accessibilityScanResults.violations).toEqual([]);
});
};

test.describe('DBAccordion', () => {
test.use({ viewport: DEFAULT_VIEWPORT });
testComponent();
testOpen();
testAction();
testA11y();
});
Loading
Loading