-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a link API that navigates without duplicating paths
- Loading branch information
Showing
12 changed files
with
171 additions
and
2 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
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
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,63 @@ | ||
import expect from "expect"; | ||
import execSteps from "./execSteps"; | ||
|
||
export default function(history, done) { | ||
const steps = [ | ||
location => { | ||
expect(location).toMatchObject({ | ||
pathname: "/" | ||
}); | ||
|
||
history.link("/home"); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("PUSH"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home" | ||
}); | ||
|
||
history.link("/home"); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("REPLACE"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home" | ||
}); | ||
|
||
history.goBack(); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("POP"); | ||
expect(location).toMatchObject({ | ||
pathname: "/" | ||
}); | ||
|
||
history.link("/home"); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("PUSH"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home" | ||
}); | ||
|
||
history.link("/home", {the: "state"}); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("REPLACE"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home", | ||
state: {the: "state"} | ||
}); | ||
|
||
history.goBack(); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("POP"); | ||
expect(location).toMatchObject({ | ||
pathname: "/" | ||
}); | ||
} | ||
]; | ||
|
||
execSteps(steps, history, done); | ||
} |
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,54 @@ | ||
import expect from "expect"; | ||
import execSteps from "./execSteps"; | ||
|
||
export default function(history, done) { | ||
let prevLocation; | ||
|
||
const steps = [ | ||
location => { | ||
expect(location).toMatchObject({ | ||
pathname: "/" | ||
}); | ||
|
||
history.link("/home"); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("PUSH"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home" | ||
}); | ||
|
||
prevLocation = location; | ||
|
||
history.link("/home"); | ||
}, | ||
(location, action) => { | ||
expect(action).toBe("PUSH"); | ||
expect(location).toMatchObject({ | ||
pathname: "/home" | ||
}); | ||
|
||
// We should get the SAME location object. Nothing | ||
// new was added to the history stack. | ||
expect(location).toBe(prevLocation); | ||
|
||
// We should see a warning message. | ||
expect(warningMessage).toMatch( | ||
"Hash history cannot PUSH the same path; a new entry will not be added to the history stack" | ||
); | ||
} | ||
]; | ||
|
||
let consoleWarn = console.warn; // eslint-disable-line no-console | ||
let warningMessage; | ||
|
||
// eslint-disable-next-line no-console | ||
console.warn = message => { | ||
warningMessage = message; | ||
}; | ||
|
||
execSteps(steps, history, (...args) => { | ||
console.warn = consoleWarn; // eslint-disable-line no-console | ||
done(...args); | ||
}); | ||
} |
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
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