# This macro takes one single argument, called "repo", which must contain the name of
# the repo owner and the repo itself, separated by a "/" (e.g. "facebook/react").
description: Verify that a GitHub repo has a wiki section with content in it
actions:
  - description: Navigate to the wiki page
    action: org.getopentest.selenium.NavigateTo
    args:
      url: $format("https://github.com/{0}/wiki", $macroArgs.repo)

  - description: Verify there is no button that says "Create the first page"
    action: org.getopentest.selenium.AssertElementNotVisible
    args:
      locator: {xpath: "//a[contains(text(), 'Create the first page')]"}

  - description: Read the URL of the current page
    action: org.getopentest.selenium.ReadCurrentUrl
    args:
      $localData:
        wikiPageUrl: $output.url

  # For some repos, GitHub will redirect the user to the repo's homepage if the repo
  # has no wiki page, so we must make sure to fail the test if that's the case
  - description: Verify that we are at the wiki URL
    script: |
      if ($localData.wikiPageUrl.indexOf("/wiki") == -1) {
        $fail("The wiki page doesn't exist");
      }

  # For most repos, if no wiki page exists, the default wiki page will show a button
  # saying "Create the first page"
  - description: Verify there is no button that says "Create the first page"
    action: org.getopentest.selenium.AssertElementNotVisible
    args:
      locator: {xpath: "//a[contains(text(), 'Create the first page')]"}