This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #859 from Alhadis/entry-stats
Store filesystem stats on tree-view entries
- Loading branch information
Showing
4 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
_ = require 'underscore-plus' | ||
{$, $$} = require 'atom-space-pen-views' | ||
fs = require 'fs-plus' | ||
path = require 'path' | ||
temp = require('temp').track() | ||
|
||
describe "FileStats", -> | ||
[file1Data, file2Data, timeStarted, treeView] = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789"] | ||
|
||
beforeEach -> | ||
timeStarted = Date.now() | ||
rootDirPath = fs.absolute(temp.mkdirSync("tree-view")) | ||
subdirPath = path.join(rootDirPath, "subdir") | ||
filePath1 = path.join(rootDirPath, "file1.txt") | ||
filePath2 = path.join(subdirPath, "file2.txt") | ||
|
||
fs.makeTreeSync(subdirPath) | ||
fs.writeFileSync(filePath1, file1Data) | ||
fs.writeFileSync(filePath2, file2Data) | ||
atom.project.setPaths([rootDirPath]) | ||
|
||
waitsForPromise -> | ||
atom.packages.activatePackage("tree-view") | ||
|
||
runs -> | ||
treeView = $(atom.workspace.getLeftPanels()[0].getItem()).view() | ||
|
||
afterEach -> | ||
temp.cleanup() | ||
|
||
describe "provision of filesystem stats", -> | ||
it "passes stats to File instances", -> | ||
stats = treeView.roots[0].directory.entries["file1.txt"].stats | ||
expect(stats).toBeDefined() | ||
expect(stats.mtime).toBeDefined() | ||
expect(stats.size).toEqual(file1Data.length) | ||
|
||
it "passes stats to Directory instances", -> | ||
stats = treeView.roots[0].directory.entries["subdir"].stats | ||
expect(stats).toBeDefined() | ||
expect(stats.mtime).toBeDefined() | ||
|
||
it "passes stats to a root directory when initialised", -> | ||
expect(treeView.roots[0].directory.stats).toBeDefined() | ||
|
||
it "passes stats to File instances in subdirectories", -> | ||
treeView.find(".entries > li:contains(subdir)")[0].expand() | ||
subdir = treeView.roots[0].directory.entries["subdir"] | ||
stats = subdir.entries["file2.txt"].stats | ||
expect(stats).toBeDefined() | ||
expect(stats.size).toEqual(file2Data.length) | ||
|
||
it "converts date-stats to timestamps", -> | ||
stats = treeView.roots[0].directory.entries["file1.txt"].stats | ||
stamp = stats.mtime | ||
expect(_.isDate stamp).toBe(false) | ||
expect(typeof stamp).toBe("number") | ||
expect(Number.isNaN stamp).toBe(false) | ||
|
||
it "accurately converts timestamps", -> | ||
stats = treeView.roots[0].directory.entries["file1.txt"].stats | ||
# Two minutes should be enough | ||
expect(Math.abs stats.mtime - timeStarted).toBeLessThan(120000) |