-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement missing router functions (#2393)
* Implement missing router functions - Implement `Router.setQueryParam()` - Fix `Router.getRouteName()` * Fix function name for `setQueryParams` * Fixes and tests - Added jest config to package.json - Added some jest unit tests for Router - Added mocks for some dependencies - Fixed route matching in Router.isActiveClassName method * fix package.json to run tests (#2396) * Removed comment * Remove duplicated setQueryParams function Fixed variable
- Loading branch information
1 parent
6d88f3c
commit 133e764
Showing
9 changed files
with
159 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const Blaze = { | ||
remove() {}, | ||
renderWithData() {} | ||
}; |
1 change: 1 addition & 0 deletions
1
imports/plugins/core/router/__mocks__/meteor/gadicc:blaze-react-component.js
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 @@ | ||
export default class BlazeComponent {} |
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,4 @@ | ||
export const Meteor = { | ||
isClient: false, | ||
isServer: true | ||
}; |
Empty file.
Empty file.
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,9 @@ | ||
|
||
class Dependency { | ||
depend() {} | ||
changed() {} | ||
} | ||
|
||
export const Tracker = { | ||
Dependency | ||
}; |
100 changes: 100 additions & 0 deletions
100
imports/plugins/core/router/lib/__tests__/router.spec.js
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,100 @@ | ||
jest.mock("/lib/collections", () => { | ||
return { | ||
Packages: {}, | ||
Shops: {} | ||
}; | ||
}); | ||
|
||
import Router from "../router.js"; | ||
|
||
beforeEach(() => { | ||
// Set some default routes | ||
Router.setCurrentRoute({}); | ||
Router.routes = [ | ||
{ | ||
fullPath: "/test?filter=red", | ||
query: { | ||
filter: "red" | ||
}, | ||
route: { | ||
name: "test", | ||
path: "/test", | ||
route: "/test" | ||
} | ||
}, | ||
{ | ||
params: { | ||
id: "a12345" | ||
}, | ||
query: { | ||
filter: "green" | ||
}, | ||
route: { | ||
fullPath: "/reaction/test/1234?filter=green", | ||
group: { | ||
prefix: "/reaction" | ||
}, | ||
name: "singleTestItem", | ||
path: "/reaction/test/12345", | ||
route: "/reaction/test/:id" | ||
} | ||
} | ||
]; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
|
||
test("Route name to equal test", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[0]); | ||
|
||
expect(Router.getRouteName()).toBe("test"); | ||
}); | ||
|
||
test("Route query param 'filter' to equal 'red'", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[0]); | ||
|
||
const queryValue = Router.getQueryParam("filter"); | ||
|
||
expect(queryValue).toBe("red"); | ||
}); | ||
|
||
test("Route /test/:id param 'id' to equal '12345'", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[1]); | ||
|
||
const received = Router.getParam("id"); | ||
|
||
expect(received).toBe("a12345"); | ||
}); | ||
|
||
test("Route is active with name 'singleTestItem'", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[1]); | ||
|
||
const received = Router.isActiveClassName("singleTestItem"); | ||
|
||
expect(received).toBe("active"); | ||
}); | ||
|
||
test("Route /test/:id is active with prefixed path '/reaction/test/12345'", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[1]); | ||
|
||
const received = Router.isActiveClassName("/reaction/test/12345"); | ||
|
||
expect(received).toBe("active"); | ||
}); | ||
|
||
test("Route /test is active with un-prefixed path '/test'", () => { | ||
// TODO: Update test when server router is implemented to use Router.go() | ||
Router.setCurrentRoute(Router.routes[0]); | ||
|
||
const received = Router.isActiveClassName("/test"); | ||
|
||
expect(received).toBe("active"); | ||
}); |
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