-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathipfs-import.test.js
74 lines (63 loc) · 2.48 KB
/
ipfs-import.test.js
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
'use strict'
const { describe, it, before, after } = require('mocha')
const { expect } = require('chai')
const { useFakeTimers } = require('sinon')
const browser = require('sinon-chrome')
describe('ipfs-import.js', function () {
let createIpfsImportHandler
let ipfsImportHandler
let clock
before(function () {
global.document = {}
global.browser = browser
// ipfs-import depends on webextension/polyfill which can't be imported
// in a non-browser environment unless global.browser is stubbed
// need to force Date to return a particular date
createIpfsImportHandler = require('../../../add-on/src/lib/ipfs-import')
clock = useFakeTimers({
now: new Date(2017, 10, 5, 12, 1, 1)
})
})
describe('formatImportDirectory', function () {
let formatImportDirectory
before(function () {
ipfsImportHandler = createIpfsImportHandler(() => {}, {}, {}, {})
formatImportDirectory = ipfsImportHandler.formatImportDirectory
})
it('should change nothing if path is properly formatted and date wildcards are not provided', function () {
const path = '/ipfs-companion-imports/my-directory/'
expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/my-directory/')
})
it('should replace two successive slashes with a single slash', function () {
const path = '/ipfs-companion-imports//my-directory/'
expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/my-directory/')
})
it('should replace multiple slashes with a single slash', function () {
const path = '/ipfs-companion-imports/////////my-directory/'
expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/my-directory/')
})
it('should add trailing slash if not present', function () {
const path = '/ipfs-companion-imports/my-directory'
expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/my-directory/')
})
it('should replace date wildcards with padded dates', function () {
const path = '/ipfs-companion-imports/%Y-%M-%D_%h%m%s/'
expect(formatImportDirectory(path)).to.equal('/ipfs-companion-imports/2017-11-05_120101/')
})
})
// TODO: complete tests
// describe('openFilesAtWebUI', function () {
// })
//
// describe('openFilesAtGateway', function () {
// })
//
// describe('importFiles', function () {
// })
after(function () {
clock.restore()
delete global.document
delete global.browser
browser.flush()
})
})