-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): adjust url-builder and add tests
- Loading branch information
1 parent
dd7190e
commit 86c98fa
Showing
5 changed files
with
159 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,97 @@ | ||
import { expect } from 'chai'; | ||
import { | ||
getRouteFromWorkspaceTab, | ||
getWorkspaceTabFromRoute, | ||
} from './url-builder'; | ||
|
||
describe('url builder helpers', function () { | ||
describe('getRouteFromWorkspaceTab', function () { | ||
const specs = [ | ||
['Welcome', '/', null], | ||
['Databases', '/Cluster0', null], | ||
['Collections', '/Cluster0/%23db', { namespace: '#db' }], | ||
['Collection', '/Cluster0/%23db/coll', { namespace: '#db.coll' }], | ||
[ | ||
'Collection', | ||
'/Cluster0/%23db/coll/find', | ||
{ namespace: '#db.coll', initialSubtab: 'Documents' }, | ||
], | ||
[ | ||
'Collection', | ||
'/Cluster0/%23db/coll/aggregation', | ||
{ namespace: '#db.coll', initialSubtab: 'Aggregations' }, | ||
], | ||
[ | ||
'Collection', | ||
'/Cluster0/%23db/coll/schema', | ||
{ namespace: '#db.coll', initialSubtab: 'Schema' }, | ||
], | ||
[ | ||
'Collection', | ||
'/Cluster0/%23db/coll/indexes', | ||
{ namespace: '#db.coll', initialSubtab: 'Indexes' }, | ||
], | ||
[ | ||
'Collection', | ||
'/Cluster0/%23db/coll/validation', | ||
{ namespace: '#db.coll', initialSubtab: 'Validation' }, | ||
], | ||
['Collection', '/Cluster0/%23db/coll/foobar', { namespace: '#db.coll' }], | ||
] as const; | ||
|
||
for (const [type, route, extraParams] of specs) { | ||
it(`should return ${type} workspace when initial route is ${route}`, function () { | ||
expect(getWorkspaceTabFromRoute(route)).to.deep.eq({ | ||
type, | ||
...(type !== 'Welcome' && { connectionId: 'Cluster0' }), | ||
...extraParams, | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
describe('getRouteFromWorkspaceTab', function () { | ||
const specs = [ | ||
['/', { type: 'Welcome' }], | ||
['/Cluster0', { type: 'Databases' }], | ||
['/Cluster0/db', { type: 'Collections', namespace: 'db' }], | ||
['/Cluster0/db/%23coll', { type: 'Collection', namespace: 'db.#coll' }], | ||
[ | ||
'/Cluster0/db/%23coll/find', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'Documents' }, | ||
], | ||
[ | ||
'/Cluster0/db/%23coll/aggregation', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'Aggregations' }, | ||
], | ||
[ | ||
'/Cluster0/db/%23coll/schema', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'Schema' }, | ||
], | ||
[ | ||
'/Cluster0/db/%23coll/indexes', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'Indexes' }, | ||
], | ||
[ | ||
'/Cluster0/db/%23coll/validation', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'Validation' }, | ||
], | ||
[ | ||
'/Cluster0/db/%23coll', | ||
{ type: 'Collection', namespace: 'db.#coll', subTab: 'FooBar' }, | ||
], | ||
] as const; | ||
|
||
for (const [route, workspace] of specs) { | ||
it(`should return ${route} route when workspace is ${workspace.type}`, function () { | ||
expect( | ||
getRouteFromWorkspaceTab( | ||
workspace.type === 'Welcome' | ||
? workspace | ||
: ({ ...workspace, connectionId: 'Cluster0' } as any) | ||
) | ||
).to.eq(route); | ||
}); | ||
} | ||
}); | ||
}); |
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