UpdatedBaseEmailLayout.test.mjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { vi, expect } from 'vitest'
  2. import { load } from 'cheerio'
  3. import path from 'node:path'
  4. const LAYOUT_PATH = path.join(
  5. import.meta.dirname,
  6. '../../../../app/src/Features/Email/Layouts/UpdatedBaseEmailLayout'
  7. )
  8. async function buildLayoutWithEnv(env) {
  9. vi.resetModules()
  10. vi.doMock('@overleaf/settings', () => ({
  11. default: {
  12. appName: 'TestApp',
  13. siteUrl: 'https://www.example.com',
  14. env,
  15. },
  16. }))
  17. const { default: layout } = await import(LAYOUT_PATH)
  18. return layout({ body: 'Test body', footerMessage: '' })
  19. }
  20. describe('UpdatedBaseEmailLayout branding', function () {
  21. afterEach(function () {
  22. vi.restoreAllMocks()
  23. vi.resetModules()
  24. })
  25. describe('on SaaS', function () {
  26. it('should show the logo image', async function () {
  27. const html = await buildLayoutWithEnv('saas')
  28. const dom = load(html)
  29. const logoImg = dom('img[alt="TestApp"]')
  30. expect(logoImg.length).to.equal(1)
  31. expect(logoImg.attr('src')).to.contain('email-logo@2x.png')
  32. })
  33. it('should show the tagline image', async function () {
  34. const html = await buildLayoutWithEnv('saas')
  35. expect(html).to.contain('email-footer-tagline@2x.png')
  36. })
  37. })
  38. describe('on server-ce', function () {
  39. it('should show the app name as text instead of logo', async function () {
  40. const html = await buildLayoutWithEnv('server-ce')
  41. const dom = load(html)
  42. const logoImg = dom('img[alt="TestApp"]')
  43. expect(logoImg.length).to.equal(0)
  44. expect(html).to.contain('TestApp')
  45. expect(html).to.not.contain('email-logo@2x.png')
  46. })
  47. it('should not show the tagline image', async function () {
  48. const html = await buildLayoutWithEnv('server-ce')
  49. expect(html).to.not.contain('email-footer-tagline@2x.png')
  50. })
  51. })
  52. describe('on server-pro', function () {
  53. it('should show the app name as text instead of logo', async function () {
  54. const html = await buildLayoutWithEnv('server-pro')
  55. const dom = load(html)
  56. const logoImg = dom('img[alt="TestApp"]')
  57. expect(logoImg.length).to.equal(0)
  58. expect(html).to.contain('TestApp')
  59. expect(html).to.not.contain('email-logo@2x.png')
  60. })
  61. it('should not show the tagline image', async function () {
  62. const html = await buildLayoutWithEnv('server-pro')
  63. expect(html).to.not.contain('email-footer-tagline@2x.png')
  64. })
  65. })
  66. })