# frozen_string_literal: true describe "chat bbcode quoting in posts" do fab!(:post) { Fabricate(:post) } before { SiteSetting.chat_enabled = true } it "can render the simplest version" do post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
martin

This is a chat message.

COOKED end it "renders the channel name if provided with multiQuote" do post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\" channel=\"Cool Cats Club\" channelId=\"1234\" multiQuote=\"true\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
Originally sent in Cool Cats Club
martin

This is a chat message.

COOKED end it "renders the channel name if provided without multiQuote" do post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\" channel=\"Cool Cats Club\" channelId=\"1234\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
martin
#Cool Cats Club

This is a chat message.

COOKED end it "renders with the chained attribute for more compact quotes" do post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\" channel=\"Cool Cats Club\" channelId=\"1234\" chained=\"true\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
martin
#Cool Cats Club

This is a chat message.

COOKED end it "renders with the noLink attribute to remove the links to the individual messages from the datetimes" do post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\" channel=\"Cool Cats Club\" channelId=\"1234\" multiQuote=\"true\" noLink=\"true\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
Originally sent in Cool Cats Club
martin

This is a chat message.

COOKED end it "renders with the reactions attribute" do reactions_attr = "+1:martin;heart:martin,eviltrout" post.update!( raw: "[chat quote=\"martin;2321;2022-01-25T05:40:39Z\" channel=\"Cool Cats Club\" channelId=\"1234\" reactions=\"#{reactions_attr}\"]\nThis is a chat message.\n[/chat]", ) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
martin
#Cool Cats Club

This is a chat message.

+1 1
heart 2
COOKED end it "correctly renders inline and non-inline oneboxes combined with chat quotes" do full_onebox_html = <<~HTML.chomp HTML SiteSetting.enable_inline_onebox_on_all_domains = true Oneboxer .stubs(:cached_onebox) .with("https://en.wikipedia.org/wiki/Hyperlink") .returns(full_onebox_html) stub_request(:get, "https://en.wikipedia.org/wiki/Hyperlink").to_return( status: 200, body: "Hyperlink - Wikipedia", ) post.update!(raw: <<~MD) https://en.wikipedia.org/wiki/Hyperlink [chat quote=\"martin;2321;2022-01-25T05:40:39Z\"] This is a chat message. [/chat] https://en.wikipedia.org/wiki/Hyperlink This is an inline onebox https://en.wikipedia.org/wiki/Hyperlink. MD expect(post.cooked.chomp).to eq(<<~COOKED.chomp) #{full_onebox_html}
martin

This is a chat message.

#{full_onebox_html}

This is an inline onebox https://en.wikipedia.org/wiki/Hyperlink.

COOKED ensure InlineOneboxer.invalidate("https://en.wikipedia.org/wiki/Hyperlink") end it "handles nested chat transcripts in posts" do SiteSetting.external_system_avatars_enabled = false freeze_time channel = Fabricate(:chat_channel) message1 = Fabricate(:chat_message, chat_channel: channel, user: post.user) message2 = Fabricate(:chat_message, chat_channel: channel, user: post.user) md = Chat::TranscriptService.new( channel, message2.user, messages_or_ids: [message2.id], ).generate_markdown message1.update!(message: md) md_for_post = Chat::TranscriptService.new( channel, message1.user, messages_or_ids: [message1.id], ).generate_markdown post.update!(raw: md_for_post) expect(post.cooked.chomp).to eq(<<~COOKED.chomp)
#{message1.user.username}
##{channel.name}
#{message2.user.username}
##{channel.name}

#{message2.message}

COOKED end end