summaryrefslogtreecommitdiff
path: root/lua/tests/automated/pickers/find_files_spec.lua
blob: f285d4f62b0fc349b428a496047abf3a0e2e5c27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
-- Just skip on mac, it has flaky CI for some reason
if vim.fn.has "mac" == 1 then
  return
end

local tester = require "telescope.testharness"

local disp = function(val)
  return vim.inspect(val, { newline = " ", indent = "" })
end

describe("builtin.find_files", function()
  it("should find the readme", function()
    tester.run_file "find_files__readme"
  end)

  it("should handle cycling for full list", function()
    tester.run_file "find_files__scrolling_descending_cycle"
  end)

  for _, configuration in ipairs {
    { sorting_strategy = "descending" },
    { sorting_strategy = "ascending" },
  } do
    it("should not display devicons when disabled: " .. disp(configuration), function()
      tester.run_string(string.format(
        [[
        local max_results = 5

        runner.picker('find_files', 'README.md', {
          post_typed = {
            { "> README.md", GetPrompt },
            { "> README.md", GetBestResult },
          },
          post_close = {
            { 'README.md', GetFile },
            { 'README.md', GetFile },
          }
        }, vim.tbl_extend("force", {
          disable_devicons = true,
          sorter = require('telescope.sorters').get_fzy_sorter(),
          layout_strategy = 'center',
          layout_config = {
            height = max_results + 1,
            width = 0.9,
          },
        }, vim.json.decode([==[%s]==])))
      ]],
        vim.json.encode(configuration)
      ))
    end)

    pending("use devicons, if it has it when enabled", function()
      if not pcall(require, "nvim-web-devicons") then
        return
      end

      local md = require("nvim-web-devicons").get_icon "md"
      tester.run_string(string.format(
        [[
        runner.picker('find_files', 'README.md', {
          post_typed = {
            { "> README.md", GetPrompt },
            { "> %s README.md", GetBestResult }
          },
          post_close = {
            { 'README.md', GetFile },
            { 'README.md', GetFile },
          }
        }, vim.tbl_extend("force", {
          disable_devicons = false,
          sorter = require('telescope.sorters').get_fzy_sorter(),
        }, vim.json.decode([==[%s]==])))
      ]],
        md,
        vim.json.encode(configuration)
      ))
    end)
  end

  it("should find the readme, using lowercase", function()
    tester.run_string [[
      runner.picker('find_files', 'readme.md', {
        post_close = {
          { 'README.md', GetFile },
        }
      })
    ]]
  end)

  it("should find the pickers.lua, using lowercase", function()
    tester.run_string [[
      runner.picker('find_files', 'pickers.lua', {
        post_close = {
          { 'pickers.lua', GetFile },
        }
      })
    ]]
  end)

  it("should find the pickers.lua", function()
    tester.run_string [[
      runner.picker('find_files', 'pickers.lua', {
        post_close = {
          { 'pickers.lua', GetFile },
          { 'pickers.lua', GetFile },
        }
      })
    ]]
  end)

  it("should be able to c-n the items", function()
    tester.run_string [[
      runner.picker('find_files', 'fixtures/find_files/file<c-n>', {
        post_typed = {
          {
            {
              "  lua/tests/fixtures/find_files/file_a.txt",
              "> lua/tests/fixtures/find_files/file_abc.txt",
            }, GetResults
          },
        },
        post_close = {
          { 'file_abc.txt', GetFile },
        },
      }, {
        sorter = require('telescope.sorters').get_fzy_sorter(),
        sorting_strategy = "ascending",
        disable_devicons = true,
      })
    ]]
  end)

  it("should be able to get the current selection", function()
    tester.run_string [[
      runner.picker('find_files', 'fixtures/find_files/file_abc', {
        post_typed = {
          { 'lua/tests/fixtures/find_files/file_abc.txt', GetSelectionValue },
        }
      })
    ]]
  end)
end)