diff --git a/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts b/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts new file mode 100644 index 0000000000..98a2e80572 --- /dev/null +++ b/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts @@ -0,0 +1,71 @@ +import * as assert from 'assert/strict'; +import {GenerateCodeOptions, generateCode} from '../../../src/utils/generateEmbedCode'; + +describe('generateCode', function () { + let genOptions: GenerateCodeOptions; + + beforeEach(function () { + genOptions = { + preview: false, + config: { + blogUrl: 'https://example.com', + signupForm: { + url: 'https://example.com', + version: 'v3' + } + }, + settings: { + accentColor: '#000000' + }, + labels: [], + backgroundColor: '#000000', + layout: 'minimal', + i18nEnabled: false + }; + }); + + it('generates a basic embed script', function () { + assert.equal(generateCode(genOptions), '
'); + }); + + it('generates a basic embed script with i18n', function () { + genOptions.i18nEnabled = true; + genOptions.settings.locale = 'af'; + assert.equal(generateCode(genOptions), '
'); + }); + + it('generates a basic embed script with labels', function () { + genOptions.labels = [{name: 'label1'}, {name: 'label2'}]; + assert.equal(generateCode(genOptions), '
'); + }); + + it('generated an embed with an icon', function () { + genOptions.settings.icon = 'https://example.com/content/images/size/w256h256/2023/09/snoopy.png'; + genOptions.layout = 'all-in-one'; + assert.equal(generateCode(genOptions), '
'); + }); + + it('renders a full preview', function () { + genOptions.preview = true; + genOptions.layout = 'all-in-one'; + assert.equal(generateCode(genOptions), '
'); + }); + + it('renders a preview with a minimal layout', function () { + genOptions.preview = true; + genOptions.layout = 'minimal'; + assert.equal(generateCode(genOptions), '
'); + }); + + it('generates text color based on background color - light background, black text', function () { + genOptions.backgroundColor = '#ffffff'; + genOptions.layout = 'all-in-one'; + assert.equal(generateCode(genOptions), '
'); + }); + + it('generates text color based on background color - black background, light text', function () { + genOptions.backgroundColor = '#000000'; + genOptions.layout = 'all-in-one'; + assert.equal(generateCode(genOptions), '
'); + }); +});