Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit b5aab0e

Browse files
committed
add tests
1 parent f8bd3fe commit b5aab0e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

spec/get-active-path-spec.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const path = require('path')
2+
const getActivePath = require('../lib/get-active-path')
3+
4+
const { it, fit, beforeEach, afterEach } = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
5+
6+
const projectPath = path.resolve(__dirname, './fixtures/project/')
7+
const file1 = path.resolve(__dirname, './fixtures/project/file1.txt')
8+
const file2 = path.resolve(__dirname, './fixtures/project/file2.txt')
9+
const img1 = path.resolve(__dirname, './fixtures/project/img1.png')
10+
11+
describe('getActivePath', function () {
12+
let workspaceElement
13+
beforeEach(async function () {
14+
workspaceElement = atom.views.getView(atom.workspace)
15+
await atom.packages.activatePackage('tabs')
16+
await atom.packages.activatePackage('tree-view')
17+
atom.project.setPaths([projectPath])
18+
})
19+
20+
it('returns project path when no target', function () {
21+
const itemPath = getActivePath()
22+
expect(itemPath).toBe(projectPath)
23+
})
24+
25+
it('returns project path when nothing open', function () {
26+
const itemPath = getActivePath(workspaceElement)
27+
expect(itemPath).toBe(projectPath)
28+
})
29+
30+
it('returns active file path when workspace is selected', async function () {
31+
await atom.workspace.open(file1)
32+
await atom.workspace.open(file2)
33+
34+
const itemPath = getActivePath(workspaceElement)
35+
expect(itemPath).toBe(file2)
36+
})
37+
38+
it('returns file path when tree view is selected', async function () {
39+
await atom.workspace.open(file1)
40+
await atom.workspace.open(file2)
41+
42+
const { treeView } = atom.packages.getLoadedPackage('tree-view').mainModule
43+
const file1Target = treeView.selectEntryForPath(file1)
44+
45+
const itemPath = getActivePath(file1Target)
46+
expect(itemPath).toBe(file1)
47+
})
48+
49+
it('returns file path when tab is selected', async function () {
50+
await atom.workspace.open(file1)
51+
await atom.workspace.open(file2)
52+
const file1Target = workspaceElement.querySelector(".tab-bar [data-name='file1.txt']")
53+
54+
const itemPath = getActivePath(file1Target)
55+
expect(itemPath).toBe(file1)
56+
})
57+
58+
it('returns project when active pane is not a file', async function () {
59+
await atom.packages.activatePackage('settings-view')
60+
await atom.workspace.open(file1)
61+
await atom.workspace.open('atom://config')
62+
63+
const itemPath = getActivePath(workspaceElement)
64+
expect(itemPath).toBe(projectPath)
65+
})
66+
67+
it('returns active pane path when it is not a text file', async function () {
68+
await atom.packages.activatePackage('image-view')
69+
await atom.workspace.open(file1)
70+
await atom.workspace.open(img1)
71+
72+
const itemPath = getActivePath(workspaceElement)
73+
expect(itemPath).toBe(img1)
74+
})
75+
})

0 commit comments

Comments
 (0)