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

fix: Force highlighted code language registration #32507

Merged
merged 9 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/weak-books-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Forces the highlight code language registration, preventing it to not being available when trying to use on the UI
16 changes: 14 additions & 2 deletions apps/meteor/client/hooks/useHighlightedCode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';

import hljs from '../../app/markdown/lib/hljs';
import hljs, { register } from '../../app/markdown/lib/hljs';

export function useHighlightedCode(language: string, text: string): string {
return useMemo(() => hljs.highlight(language, text).value, [language, text]);
const t = useTranslation();
const { isLoading } = useQuery(['register-highlight-language', language], async () => {
try {
await register(language);
return true;
} catch (error) {
console.error('Not possible to register the provided language');
}
});

return useMemo(() => (isLoading ? t('Loading') : hljs.highlight(language, text).value), [isLoading, language, text, t]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const IntegrationsTable = ({ type }: { type?: string }) => {
)}
{isSuccess && data && data.integrations.length > 0 && (
<>
<GenericTable>
<GenericTable aria-label={t('Integrations_table')}>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{isSuccess &&
Expand Down
49 changes: 47 additions & 2 deletions apps/meteor/tests/e2e/administration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { faker } from '@faker-js/faker';
import { IS_EE } from './config/constants';
import { Users } from './fixtures/userStates';
import { Admin, Utils } from './page-objects';
import { createTargetChannel } from './utils';
import { setSettingValueById } from './utils/setSettingValueById';
import { createTargetChannel, setSettingValueById } from './utils';
import { test, expect } from './utils/test';

test.use({ storageState: Users.admin.state });
Expand Down Expand Up @@ -275,6 +274,52 @@ test.describe.parallel('administration', () => {
});
});

test.describe('Integrations', () => {
const messageCodeHighlightDefault =
'javascript,css,markdown,dockerfile,json,go,rust,clean,bash,plaintext,powershell,scss,shell,yaml,vim';
const incomingIntegrationName = faker.string.uuid();

test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Code_highlight', '');
});

test.beforeEach(async ({ page }) => {
await page.goto('/admin/integrations');
});

test.afterAll(async ({ api }) => {
await setSettingValueById(api, 'Message_Code_highlight', messageCodeHighlightDefault);
});

test('should display the example payload correctly', async () => {
await poAdmin.btnNew.click();
await poAdmin.btnInstructions.click();

await expect(poAdmin.codeExamplePayload('Loading')).not.toBeVisible();
});

test('should be able to create new incoming integration', async () => {
await poAdmin.btnNew.click();
await poAdmin.inputName.fill(incomingIntegrationName);
await poAdmin.inputPostToChannel.fill('#general');
await poAdmin.inputPostAs.fill(Users.admin.data.username);
await poAdmin.btnSave.click();

await expect(poAdmin.inputWebhookUrl).not.toHaveValue('Will be available here after saving.');

await poAdmin.btnBack.click();
await expect(poAdmin.getIntegrationByName(incomingIntegrationName)).toBeVisible();
});

test('should be able to delete an incoming integration', async () => {
await poAdmin.getIntegrationByName(incomingIntegrationName).click();
await poAdmin.btnDelete.click();
await poUtils.btnModalConfirmDelete.click();

await expect(poAdmin.getIntegrationByName(incomingIntegrationName)).not.toBeVisible();
});
});

test.describe('Settings', () => {
test.describe('General', () => {
test.beforeEach(async ({ page }) => {
Expand Down
40 changes: 38 additions & 2 deletions apps/meteor/tests/e2e/page-objects/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,47 @@ export class Admin {
return this.page.getByRole('button', { name: 'Add' });
}

getUserRowByUsername(username: string): Locator {
return this.page.locator('tr', { hasText: username });
}

get btnBack(): Locator {
return this.page.getByRole('button', { name: 'Back' });
}

getUserRowByUsername(username: string): Locator {
return this.page.locator('tr', { hasText: username });
get btnNew(): Locator {
return this.page.getByRole('button', { name: 'New' });
}

get btnDelete(): Locator {
return this.page.getByRole('button', { name: 'Delete' });
}

get btnInstructions(): Locator {
return this.page.getByRole('button', { name: 'Instructions' });
}

get inputName(): Locator {
return this.page.getByRole('textbox', { name: 'Name' });
}

get inputPostToChannel(): Locator {
return this.page.getByRole('textbox', { name: 'Post to Channel' });
}

get inputPostAs(): Locator {
return this.page.getByRole('textbox', { name: 'Post as' });
}

codeExamplePayload(text: string): Locator {
return this.page.locator('code', { hasText: text });
}

getIntegrationByName(name: string): Locator {
return this.page.getByRole('table', { name: 'Integrations table' }).locator('tr', { hasText: name });
}

get inputWebhookUrl(): Locator {
return this.page.getByRole('textbox', { name: 'Webhook URL' });
}
}
1 change: 1 addition & 0 deletions apps/meteor/tests/e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './create-target-channel';
export * from './setSettingValueById';
export * from './getSettingValueById';
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2763,6 +2763,7 @@
"Integrations_Outgoing_Type_RoomLeft": "User Left Room",
"Integrations_Outgoing_Type_SendMessage": "Message Sent",
"Integrations_Outgoing_Type_UserCreated": "User Created",
"Integrations_table": "Integrations table",
"InternalHubot": "Internal Hubot",
"InternalHubot_EnableForChannels": "Enable for Public Channels",
"InternalHubot_EnableForDirectMessages": "Enable for Direct Messages",
Expand Down
Loading