Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add index property to BrowserHistory, HashHistory and Update #957 #958

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export default (history, done) => {
let unblock;

let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
Expand All @@ -26,7 +28,8 @@ export default (history, done) => {

window.history.go(-1);
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("POP");
expect(location).toMatchObject({
pathname: "/",
Expand Down
4 changes: 3 additions & 1 deletion packages/history/__tests__/TestSequences/BlockEverything.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});
Expand All @@ -13,6 +14,7 @@ export default (history, done) => {

history.push("/home");

expect(history.index).toBe(0);
expect(history.location).toMatchObject({
pathname: "/",
});
Expand Down
9 changes: 6 additions & 3 deletions packages/history/__tests__/TestSequences/GoBack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toEqual("PUSH");
expect(location).toMatchObject({
pathname: "/home",
});

history.back();
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toEqual("POP");
expect(location).toMatchObject({
pathname: "/",
Expand Down
12 changes: 8 additions & 4 deletions packages/history/__tests__/TestSequences/GoForward.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toEqual("PUSH");
expect(location).toMatchObject({
pathname: "/home",
});

history.back();
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toEqual("POP");
expect(location).toMatchObject({
pathname: "/",
});

history.forward();
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toEqual("POP");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home?the=query#the-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
Expand All @@ -21,7 +23,8 @@ export default (history, done) => {

history.push("?another=query#another-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(2);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
6 changes: 4 additions & 2 deletions packages/history/__tests__/TestSequences/PushNewLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home?the=query#the-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/the/path?the=query#the-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/the/path",
Expand All @@ -21,7 +23,8 @@ export default (history, done) => {

history.push("../other/path?another=query#another-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(2);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/other/path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps, spyOn } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/the/path?the=query#the-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/the/path",
Expand All @@ -29,7 +31,8 @@ export default (history, done) => {

destroy();
},
({ location }) => {
({ index, location }) => {
expect(index).toBe(2);
expect(location).toMatchObject({
pathname: "../other/path",
search: "?another=query",
Expand Down
12 changes: 8 additions & 4 deletions packages/history/__tests__/TestSequences/PushSamePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
});

history.push("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(2);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
});

history.back();
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("POP");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
6 changes: 4 additions & 2 deletions packages/history/__tests__/TestSequences/PushState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.push("/home?the=query#the-hash", { the: "state" });
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(1);
expect(action).toBe("PUSH");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.replace("/home?the=query#the-hash");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("REPLACE");
expect(location).toMatchObject({
pathname: "/home",
Expand All @@ -23,7 +25,8 @@ export default (history, done) => {

history.replace("/");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("REPLACE");
expect(location).toMatchObject({
pathname: "/",
Expand Down
9 changes: 6 additions & 3 deletions packages/history/__tests__/TestSequences/ReplaceSamePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ export default (history, done) => {
let prevLocation;

let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.replace("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("REPLACE");
expect(location).toMatchObject({
pathname: "/home",
Expand All @@ -23,7 +25,8 @@ export default (history, done) => {

history.replace("/home");
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("REPLACE");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
6 changes: 4 additions & 2 deletions packages/history/__tests__/TestSequences/ReplaceState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { execSteps } from "./utils.js";

export default (history, done) => {
let steps = [
({ location }) => {
({ index, location }) => {
expect(index).toBe(0);
expect(location).toMatchObject({
pathname: "/",
});

history.replace("/home?the=query#the-hash", { the: "state" });
},
({ action, location }) => {
({ index, action, location }) => {
expect(index).toBe(0);
expect(action).toBe("REPLACE");
expect(location).toMatchObject({
pathname: "/home",
Expand Down
1 change: 1 addition & 0 deletions packages/history/__tests__/TestSequences/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function execSteps(steps, history, done) {
unlisten = history.listen(execNextStep);

execNextStep({
index: history.index,
action: history.action,
location: history.location,
});
Expand Down
4 changes: 4 additions & 0 deletions packages/history/__tests__/browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe("a browser history", () => {
history = createBrowserHistory();
});

it("has an index property", () => {
expect(typeof history.index).toBe("number");
});

it("knows how to create hrefs from location objects", () => {
const href = history.createHref({
pathname: "/the/path",
Expand Down
4 changes: 4 additions & 0 deletions packages/history/__tests__/hash-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe("a hash history", () => {
history = createHashHistory();
});

it("has an index property", () => {
expect(typeof history.index).toBe("number");
});

it("knows how to create hrefs from location objects", () => {
const href = history.createHref({
pathname: "/the/path",
Expand Down
Loading