Skip to content

Commit 821ec9b

Browse files
committed
Add tests for database uri fixing
1 parent b0328b0 commit 821ec9b

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'vscode-test';
2+
import 'mocha';
3+
import * as tmp from 'tmp';
4+
import * as path from 'path';
5+
import * as fs from 'fs-extra';
6+
import { expect } from 'chai';
7+
import { Uri } from 'vscode';
8+
9+
import { DatabaseUI } from '../../databases-ui';
10+
11+
describe('databases-ui', () => {
12+
describe('fixDbUri', () => {
13+
const fixDbUri = (DatabaseUI.prototype as any).fixDbUri;
14+
it('should choose current directory direcory normally', async () => {
15+
const dir = tmp.dirSync().name;
16+
const uri = await fixDbUri(Uri.file(dir));
17+
expect(uri.toString()).to.eq(Uri.file(dir).toString());
18+
});
19+
20+
it('should choose parent direcory when file is selected', async () => {
21+
const file = tmp.fileSync().name;
22+
const uri = await fixDbUri(Uri.file(file));
23+
expect(uri.toString()).to.eq(Uri.file(path.dirname(file)).toString());
24+
});
25+
26+
it('should choose parent direcory when db-* is selected', async () => {
27+
const dir = tmp.dirSync().name;
28+
const dbDir = path.join(dir, 'db-hucairz');
29+
await fs.mkdirs(dbDir);
30+
31+
const uri = await fixDbUri(Uri.file(dbDir));
32+
expect(uri.toString()).to.eq(Uri.file(dir).toString());
33+
});
34+
35+
it('should choose parent\'s parent direcory when file selected is in db-*', async () => {
36+
const dir = tmp.dirSync().name;
37+
const dbDir = path.join(dir, 'db-hucairz');
38+
const file = path.join(dbDir, 'nested');
39+
await fs.mkdirs(dbDir);
40+
await fs.createFile(file);
41+
42+
const uri = await fixDbUri(Uri.file(file));
43+
expect(uri.toString()).to.eq(Uri.file(dir).toString());
44+
});
45+
});
46+
47+
});

0 commit comments

Comments
 (0)