Niklas
Niklas
NNuxt
Created by Niklas on 10/2/2024 in #❓・help
Testing Scenario
This is what my test file looks like right now but I get some unhead dom errors
// @vitest-environment nuxt
import { expect, describe, test } from 'vitest';
import { createPage } from '@nuxt/test-utils/e2e';
import { setup, $fetch } from '@nuxt/test-utils/e2e';
import fs from 'node:fs/promises';
import { registerEndpoint } from '@nuxt/test-utils/runtime';

registerEndpoint('/api/document/test-external', {
method: 'POST',
handler: () => {
console.log('test-external called');
return { success: true };
},
});

describe('documents', async () => {
await setup({
env: {
annotationURL: '/api/document/test-external',
},
},
});

test('upload external document', async () => {
const formData = new FormData();

const file = await fs.readFile('tests/data/documents/sample.pdf');

formData.append(
'file',
new File([file], 'sample.pdf', { type: 'application/pdf' }),
);

const res = await $fetch<{ id: string }>('/api/document/prepare', {
method: 'POST',
body: formData,
});

expect(res).toHaveProperty('id');

console.log(res);

const page = await createPage(`/pdf/viewer/${res.id}?external=true`);

await page.mouse.move(650, 350);
await page.mouse.down({ button: 'left' });
await page.mouse.move(750, 1000);
await page.mouse.up({ button: 'left' });

await page.getByRole('button', { name: 'Save' }).click();

await expect(page.getByRole('heading')).toContain(
'PDF successfully saved.',
);
});
});
// @vitest-environment nuxt
import { expect, describe, test } from 'vitest';
import { createPage } from '@nuxt/test-utils/e2e';
import { setup, $fetch } from '@nuxt/test-utils/e2e';
import fs from 'node:fs/promises';
import { registerEndpoint } from '@nuxt/test-utils/runtime';

registerEndpoint('/api/document/test-external', {
method: 'POST',
handler: () => {
console.log('test-external called');
return { success: true };
},
});

describe('documents', async () => {
await setup({
env: {
annotationURL: '/api/document/test-external',
},
},
});

test('upload external document', async () => {
const formData = new FormData();

const file = await fs.readFile('tests/data/documents/sample.pdf');

formData.append(
'file',
new File([file], 'sample.pdf', { type: 'application/pdf' }),
);

const res = await $fetch<{ id: string }>('/api/document/prepare', {
method: 'POST',
body: formData,
});

expect(res).toHaveProperty('id');

console.log(res);

const page = await createPage(`/pdf/viewer/${res.id}?external=true`);

await page.mouse.move(650, 350);
await page.mouse.down({ button: 'left' });
await page.mouse.move(750, 1000);
await page.mouse.up({ button: 'left' });

await page.getByRole('button', { name: 'Save' }).click();

await expect(page.getByRole('heading')).toContain(
'PDF successfully saved.',
);
});
});
2 replies
NNuxt
Created by w7a9q on 7/10/2024 in #❓・help
async Nitro middleware
can you show an example what you are doing in that middleware?
8 replies
NNuxt
Created by Nin on 7/11/2024 in #❓・help
server error
I believe you could create a custom error page and make it user friendly: https://nuxt.com/docs/guide/directory-structure/error Or if you have client side errrors you could catch them via a hook in a plugin: https://nuxt.com/docs/guide/directory-structure/error
12 replies
NNuxt
Created by Jon 久世 on 6/24/2024 in #❓・help
How Do I Access AuthForm Internal State?
You should be able to access the internal state via an ref Found in the ui-pro repo: https://github.com/nuxt/ui-pro/blob/16019a71156144d1351aad52ee3fdca41a21bc2a/components/auth/AuthForm.vue#L202
<UAuthForm
ref="authForm"
...
/>

<script setup lang="ts">
const authForm = ref();

forgetPassword() {
authForm.value.state. //...
}
</script>
<UAuthForm
ref="authForm"
...
/>

<script setup lang="ts">
const authForm = ref();

forgetPassword() {
authForm.value.state. //...
}
</script>
8 replies
NNuxt
Created by Niklas on 3/14/2024 in #❓・help
How to hook into the nuxt consola instance
@pi0 sorry for the ping, would you be up to push me in the right direction?
2 replies