fix(editor): No need to add click emitting click events, VUE delegates the handler to the root element of the component (#7182)

This commit is contained in:
Csaba Tuncsik 2023-09-15 11:22:30 +02:00 committed by GitHub
parent c18ba370d5
commit 3c055e4d8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -1,11 +1,10 @@
<template> <template>
<div :class="$style.container"> <div :class="$style.container">
<GoogleAuthButton v-if="isGoogleOAuthType" @click.stop="$emit('click')" /> <GoogleAuthButton v-if="isGoogleOAuthType" />
<n8n-button <n8n-button
v-else v-else
:label="$locale.baseText('credentialEdit.oAuthButton.connectMyAccount')" :label="$locale.baseText('credentialEdit.oAuthButton.connectMyAccount')"
size="large" size="large"
@click.stop="$emit('click')"
/> />
</div> </div>
</template> </template>

View file

@ -0,0 +1,24 @@
import userEvent from '@testing-library/user-event';
import { createTestingPinia } from '@pinia/testing';
import { createComponentRenderer } from '@/__tests__/render';
import OauthButton from '@/components/CredentialEdit/OauthButton.vue';
const renderComponent = createComponentRenderer(OauthButton, {
pinia: createTestingPinia(),
});
describe('OauthButton', () => {
test.each([
['GoogleAuthButton', true],
['n8n-button', false],
])('should emit click event only once when %s is clicked', async (name, isGoogleOAuthType) => {
const { emitted, getByRole } = renderComponent({
props: { isGoogleOAuthType },
});
const button = getByRole('button');
await userEvent.click(button);
expect(emitted().click).toHaveLength(1);
});
});