Apply Mentions everywhere (#595)

* variables and mentions

* fix lint

* add missing changes

* fix tests

* update quilly, fix bugs

* fix lint

* apply fixes

* apply fixes

* Fix MentionParser

* Apply Mentions everywhere

* Fix MentionParserTest

* Small refactoring

* Fixing quill import issues

* Polished email integration, added customer sender mail

* Add missing changes

* improve migration command

---------

Co-authored-by: Frank <csskfaves@gmail.com>
Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala
2024-10-22 14:04:29 +05:30
committed by GitHub
parent 2fdf2a439b
commit dad5c825b1
50 changed files with 1903 additions and 874 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace Tests\Unit;
use App\Console\Commands\EmailNotificationMigration;
use App\Models\Integration\FormIntegration;
use Tests\TestCase;
uses(TestCase::class);
beforeEach(function () {
$this->command = new EmailNotificationMigration();
});
it('updates email integration correctly', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
$integration = FormIntegration::create([
'integration_id' => 'email',
'form_id' => $form->id,
'status' => FormIntegration::STATUS_ACTIVE,
'data' => [
'notification_emails' => 'test@example.com',
'notification_reply_to' => 'reply@example.com',
],
]);
$this->command->updateIntegration($integration);
expect($integration->fresh())
->integration_id->toBe('email')
->data->toMatchArray([
'send_to' => 'test@example.com',
'sender_name' => 'OpnForm',
'subject' => 'New form submission',
'email_content' => 'Hello there 👋 <br>New form submission received.',
'include_submission_data' => true,
'include_hidden_fields_submission_data' => false,
'reply_to' => 'reply@example.com',
]);
});
it('updates submission confirmation integration correctly', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
$emailProperty = collect($form->properties)->filter(function ($property) {
return $property['type'] == 'email';
})->first();
$integration = FormIntegration::create([
'integration_id' => 'submission_confirmation',
'form_id' => $form->id,
'status' => FormIntegration::STATUS_ACTIVE,
'data' => [
'notification_sender' => 'Sender Name',
'notification_subject' => 'Thank you for your submission',
'notification_body' => 'We received your submission.',
'notifications_include_submission' => true,
'confirmation_reply_to' => 'reply@example.com',
],
]);
$this->command->updateIntegration($integration);
expect($integration->fresh())
->integration_id->toBe('email')
->data->toMatchArray([
'send_to' => '<span mention-field-id="' . $emailProperty['id'] . '" mention-field-name="' . $emailProperty['name'] . '" mention-fallback="" contenteditable="false" mention="true">' . $emailProperty['name'] . '</span>',
'sender_name' => 'Sender Name',
'subject' => 'Thank you for your submission',
'email_content' => 'We received your submission.',
'include_submission_data' => true,
'include_hidden_fields_submission_data' => false,
'reply_to' => 'reply@example.com',
]);
});

View File

@@ -0,0 +1,86 @@
<?php
use App\Open\MentionParser;
test('it replaces mention elements with their corresponding values', function () {
$content = '<p>Hello <span mention mention-field-id="123">Placeholder</span></p>';
$data = [['id' => '123', 'value' => 'World']];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>Hello World</p>');
});
test('it handles multiple mentions', function () {
$content = '<p><span mention mention-field-id="123">Name</span> is <span mention mention-field-id="456">Age</span> years old</p>';
$data = [
['id' => '123', 'value' => 'John'],
['id' => '456', 'value' => 30],
];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>John is 30 years old</p>');
});
test('it uses fallback when value is not found', function () {
$content = '<p>Hello <span mention mention-field-id="123" mention-fallback="Friend">Placeholder</span></p>';
$data = [];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>Hello Friend</p>');
});
test('it removes mention element when no value and no fallback', function () {
$content = '<p>Hello <span mention mention-field-id="123">Placeholder</span></p>';
$data = [];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>Hello </p>');
});
test('it handles array values', function () {
$content = '<p>Tags: <span mention mention-field-id="123">Placeholder</span></p>';
$data = [['id' => '123', 'value' => ['PHP', 'Laravel', 'Testing']]];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>Tags: PHP, Laravel, Testing</p>');
});
test('it preserves HTML structure', function () {
$content = '<div><p>Hello <span mention mention-field-id="123">Placeholder</span></p><p>How are you?</p></div>';
$data = [['id' => '123', 'value' => 'World']];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<div><p>Hello World</p><p>How are you?</p></div>');
});
test('it handles UTF-8 characters', function () {
$content = '<p>こんにちは <span mention mention-field-id="123">Placeholder</span></p>';
$data = [['id' => '123', 'value' => '世界']];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('<p>こんにちは 世界</p>');
});
test('it handles content without surrounding paragraph tags', function () {
$content = 'some text <span contenteditable="false" mention="" mention-field-id="123" mention-field-name="Post excerpt" mention-fallback="">Post excerpt</span> dewde';
$data = [['id' => '123', 'value' => 'replaced text']];
$parser = new MentionParser($content, $data);
$result = $parser->parse();
expect($result)->toBe('some text replaced text dewde');
});