<commit_before>import {
  emptyResults,
  failsResultsWithoutMessages,
  warnResults,
  failsResults,
  summaryResults,
  messagesResults,
  markdownResults,
} from "../../_tests/fixtures/ExampleDangerResults"
import { template, inlineTemplate } from "../bitbucketServerTemplate"

const noEntryEmoji = "\u274C"
const warningEmoji = "⚠️"
const messageEmoji = "\u2728"

describe("generating messages for BitBucket server", () => {
  it("shows no sections for empty results", () => {
    const issues = template("blankID", emptyResults)
    expect(issues).not.toContain("Fails")
    expect(issues).not.toContain("Warnings")
    expect(issues).not.toContain("Messages")
  })

  it("shows no sections for results without messages", () => {
    const issues = template("blankID", failsResultsWithoutMessages)
    expect(issues).not.toContain("Fails")
    expect(issues).not.toContain("Warnings")
    expect(issues).not.toContain("Messages")
  })

  it("Shows the failing messages in a section", () => {
    const issues = template("blankID", failsResults)
    expect(issues).toContain("Fails")
    expect(issues).not.toContain("Warnings")
  })

  it("Shows the warning messages in a section", () => {
    const issues = template("blankID", warnResults)
    expect(issues).toContain("Warnings")
    expect(issues).not.toContain("Fails")
  })

  it("summary result matches snapshot", () => {
    expect(template("blankID", summaryResults)).toMatchSnapshot()
  })
})

describe("generating inline messages", () => {
  it("Shows the failing message", () => {
    const issues = inlineTemplate("blankID", failsResults, "File.swift", 5)
    expect(issues).toContain("- ${noEntryEmoji} Failing message")
    expect(issues).not.toContain("- ${warningEmoji}")
    expect(issues).not.toContain("- ${messageEmoji}")
  })

  it("Shows the warning message", () => {
    const issues = inlineTemplate("blankID", warnResults, "File.swift", 5)
    expect(issues).toContain("- ${warningEmoji} Warning message")
    expect(issues).not.toContain("- ${noEntryEmoji}")
    expect(issues).not.toContain("- ${messageEmoji}")
  })

  it("Shows the message", () => {
    const issues = inlineTemplate("blankID", messagesResults, "File.swift", 5)
    expect(issues).toContain("- ${messageEmoji} Message")
    expect(issues).not.toContain("- ${noEntryEmoji}")
    expect(issues).not.toContain("- ${warningEmoji}")
  })

  it("Shows markdowns one after another", () => {
    const issues = inlineTemplate("blankID", markdownResults, "File.swift", 5)
    const expected = `
### Short Markdown Message1
<commit_msg>Fix tests<commit_after>import {
  emptyResults,
  failsResultsWithoutMessages,
  warnResults,
  failsResults,
  summaryResults,
  messagesResults,
  markdownResults,
} from "../../_tests/fixtures/ExampleDangerResults"
import { template, inlineTemplate } from "../bitbucketServerTemplate"

const noEntryEmoji = "\u274C"
const warningEmoji = "⚠️"
const messageEmoji = "\u2728"

describe("generating messages for BitBucket server", () => {
  it("shows no sections for empty results", () => {
    const issues = template("blankID", emptyResults)
    expect(issues).not.toContain("Fails")
    expect(issues).not.toContain("Warnings")
    expect(issues).not.toContain("Messages")
  })

  it("shows no sections for results without messages", () => {
    const issues = template("blankID", failsResultsWithoutMessages)
    expect(issues).not.toContain("Fails")
    expect(issues).not.toContain("Warnings")
    expect(issues).not.toContain("Messages")
  })

  it("Shows the failing messages in a section", () => {
    const issues = template("blankID", failsResults)
    expect(issues).toContain("Fails")
    expect(issues).not.toContain("Warnings")
  })

  it("Shows the warning messages in a section", () => {
    const issues = template("blankID", warnResults)
    expect(issues).toContain("Warnings")
    expect(issues).not.toContain("Fails")
  })

  it("summary result matches snapshot", () => {
    expect(template("blankID", summaryResults)).toMatchSnapshot()
  })
})

describe("generating inline messages", () => {
  it("Shows the failing message", () => {
    const issues = inlineTemplate("blankID", failsResults, "File.swift", 5)
    expect(issues).toContain(`- ${noEntryEmoji} Failing message`)
    expect(issues).not.toContain(`- ${warningEmoji}`)
    expect(issues).not.toContain(`- ${messageEmoji}`)
  })

  it("Shows the warning message", () => {
    const issues = inlineTemplate("blankID", warnResults, "File.swift", 5)
    expect(issues).toContain(`- ${warningEmoji} Warning message`)
    expect(issues).not.toContain(`- ${noEntryEmoji}`)
    expect(issues).not.toContain(`- ${messageEmoji}`)
  })

  it("Shows the message", () => {
    const issues = inlineTemplate("blankID", messagesResults, "File.swift", 5)
    expect(issues).toContain(`- ${messageEmoji} Message`)
    expect(issues).not.toContain(`- ${noEntryEmoji}`)
    expect(issues).not.toContain(`- ${warningEmoji}`)
  })

  it("Shows markdowns one after another", () => {
    const issues = inlineTemplate("blankID", markdownResults, "File.swift", 5)
    const expected = `
### Short Markdown Message1

{'fraction_non_alphanumeric': 0.1653726708074534, 'fraction_numerical': 0.004658385093167702, 'mean_word_length': 4.67511013215859, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4153106', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1599, 'n_words': 319}