You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe ReactionValidator do
  4. let(:announcement) { Fabricate(:announcement) }
  5. describe '#validate' do
  6. it 'adds error when not a valid unicode emoji' do
  7. reaction = announcement.announcement_reactions.build(name: 'F')
  8. subject.validate(reaction)
  9. expect(reaction.errors).to_not be_empty
  10. end
  11. it 'does not add error when non-unicode emoji is a custom emoji' do
  12. custom_emoji = Fabricate(:custom_emoji)
  13. reaction = announcement.announcement_reactions.build(name: custom_emoji.shortcode, custom_emoji_id: custom_emoji.id)
  14. subject.validate(reaction)
  15. expect(reaction.errors).to be_empty
  16. end
  17. it 'adds error when 8 reactions already exist' do
  18. %w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name|
  19. announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
  20. end
  21. reaction = announcement.announcement_reactions.build(name: '😘')
  22. subject.validate(reaction)
  23. expect(reaction.errors).to_not be_empty
  24. end
  25. it 'does not add error when new reaction is part of the existing ones' do
  26. %w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name|
  27. announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
  28. end
  29. reaction = announcement.announcement_reactions.build(name: '😋')
  30. subject.validate(reaction)
  31. expect(reaction.errors).to be_empty
  32. end
  33. end
  34. end