-
Notifications
You must be signed in to change notification settings - Fork 495
/
Copy pathfiles.test.js
98 lines (84 loc) · 3.98 KB
/
files.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { test } from './setup/coverage.js'
import { fixtureData } from './fixtures/index.js'
import all from 'it-all'
import filesize from 'filesize'
import * as kuboRpcModule from 'kubo-rpc-client'
test.describe('Files screen', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/#/files')
})
const button = 'button[id="import-button"]'
test('should have the active Add menu', async ({ page }) => {
await page.waitForSelector(button, { state: 'visible' })
await page.click(button, { force: true })
await page.waitForSelector('#add-file', { state: 'visible' })
await page.waitForSelector('text=File')
await page.waitForSelector('text=Folder')
await page.waitForSelector('text=From IPFS')
await page.waitForSelector('text=New folder')
await page.click(button, { force: true })
})
test('should allow for a successful import of two files', async ({ page }) => {
await page.waitForSelector(button, { state: 'visible' })
await page.click(button)
await page.waitForSelector('#add-file', { state: 'visible' })
const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.click('button[id="add-file"]') // menu button that triggers file selection
])
// select a single static text file via fileChooser
const file1 = fixtureData('file.txt')
const file2 = fixtureData('file2.txt')
await fileChooser.setFiles([file1.path, file2.path])
// expect file with matching filename to be added to the file list
await page.waitForSelector('.File')
await page.waitForSelector('text=file.txt')
await page.waitForSelector('text=file2.txt')
// expect valid CID to be present on the page
const ipfs = kuboRpcModule.create(process.env.IPFS_RPC_ADDR)
const [result1, result2] = await all(ipfs.addAll([file1.data, file2.data]))
await page.waitForSelector(`text=${result1.cid.toString()}`)
await page.waitForSelector(`text=${result2.cid.toString()}`)
// expect human readable sizes in format from ./src/lib/files.js#humanSize
// → this ensures metadata was correctly read for each item in the MFS
const human = (b) => (b
? filesize(b, {
standard: 'iec',
base: 2,
round: b >= 1073741824 ? 1 : 0
})
: '-')
for await (const file of ipfs.files.ls('/')) {
await page.waitForSelector(`text=${file.name}`)
await page.waitForSelector(`text=${human(file.size)}`)
}
})
test('should have active Context menu that allows Inspection of the DAG', async ({ page }) => {
// dedicated test file to make this isolated from the rest
const testFilename = 'explorer-context-menu-test.txt'
const testCid = 'bafkqaddjnzzxazldoqwxizltoq'
// first: create a test file
const button = 'button[id="import-button"]'
await page.waitForSelector(button, { state: 'visible' })
await page.click(button)
await page.waitForSelector('#add-by-path', { state: 'visible' })
page.click('button[id="add-by-path"]')
await page.waitForSelector('div[role="dialog"] input[name="name"]')
await page.fill('div[role="dialog"] input[name="path"]', `/ipfs/${testCid}`)
await page.fill('div[role="dialog"] input[name="name"]', testFilename)
await page.keyboard.press('Enter')
// expect file with matching filename to be added to the file list
await page.waitForSelector(`.File:has-text("${testFilename}")`)
// open context menu
const cbutton = `button[aria-label="View more options for ${testFilename}"]`
await page.waitForSelector(cbutton, { state: 'visible' })
await page.click(cbutton, { force: true })
await page.waitForSelector('text=Inspect', { state: 'visible' })
// click on Inspect option
await page.waitForSelector('text=Inspect', { state: 'visible' })
await page.locator('button:has-text("Inspect"):enabled').click({ force: true })
// confirm Explore screen was opened with correct CID
await page.waitForURL(`/#/explore/${testCid}`)
await page.waitForSelector('text="CID info"')
})
})