Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
fix: Fixed Side Nav
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKienle committed Jun 16, 2019
1 parent 1bdd546 commit e27f200
Show file tree
Hide file tree
Showing 31 changed files with 664 additions and 772 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ module.exports = {
jest: true
}
}
]
],

extends: ["plugin:vue/essential", "@vue/prettier"]
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:bili": "bili --bundle-node-modules --file-name FundamentalVue.[format].js --format cjs --format umd-min --format es --module-name FundamentalVue --env.NODE_ENV production -d dist",
"serve:demo": "cd demo && cross-env FD_E2E=true vue-cli-service serve index.js --port 10000 --mode production",
"serve:demo:dev": "cd demo && cross-env FD_E2E=true vue-cli-service serve index.js --port 10000 --mode development",
"serve": "yarn generate-api && vue-cli-service serve src/docs/index.js",
"serve": "yarn generate-api && yarn serve:no-api-generate",
"serve:no-api-generate": "vue-cli-service serve src/docs/index.js",
"generate-api": "node src/tools",
"test": "vue-cli-service test:unit",
"lint": "vue-cli-service lint --no-fix --max-warnings 0 --max-errors 0 src",
Expand Down
5 changes: 0 additions & 5 deletions src/components/SideNav/Model/Config.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/components/SideNav/Model/Item.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/SideNav/Model/Mode.js

This file was deleted.

97 changes: 0 additions & 97 deletions src/components/SideNav/Model/Store.js

This file was deleted.

73 changes: 0 additions & 73 deletions src/components/SideNav/Model/__tests__/Store.test.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/components/SideNav/Model/__tests__/normalize-items.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import normalizeItems from "./../normalize-items";
import { normalizeItem } from "./../normalize-items";

// foo is a mock function
describe("item normalizer", () => {
describe("normalizeItem", () => {
it("works with {}", () => {
const normalized = normalizeItem({});
expect(normalized).toHaveProperty("$_fdId");
expect(normalized).toHaveProperty("$_fdChildren", []);
});
it("works with null", () => {
const normalized = normalizeItem(null);
expect(normalized).toHaveProperty("$_fdId");
expect(normalized).toHaveProperty("$_fdChildren", []);
});
it("works with undefined", () => {
const normalized = normalizeItem(undefined);
expect(normalized).toHaveProperty("$_fdId");
expect(normalized).toHaveProperty("$_fdChildren", []);
});

it("works with simple object", () => {
const normalized = normalizeItem({ firstName: "chris" });
expect(normalized).toHaveProperty("$_fdId");
expect(normalized).toHaveProperty("$_fdChildren", []);
expect(normalized).toHaveProperty("firstName", "chris");
});

it("re-uses id", () => {
const normalized = normalizeItem({ id: "123" });
expect(normalized).toHaveProperty("$_fdId", "123");
expect(normalized).toHaveProperty("id", "123");
expect(normalized).toHaveProperty("$_fdChildren", []);
});

it("re-uses children", () => {
const normalized = normalizeItem({
children: [{ firstName: "chris" }]
});
expect(normalized).toHaveProperty("$_fdId");
const children = normalized["$_fdChildren"];
expect(children).toMatchObject([{ firstName: "chris" }]);
});
});
describe("normalizeItems", () => {
it("works with empty array", () => {
const normalized = normalizeItems([]);
expect(normalized).toEqual([]);
});

it("works with array with single object", () => {
const [normalized] = normalizeItems([{}]);
expect(normalized).toHaveProperty("id");
});

it("works with array with children", () => {
const [normalized] = normalizeItems([
{
fn: "chris",
children: [
{
fn: "andi"
}
]
}
]);
expect(normalized).toHaveProperty("fn");
expect(normalized).toHaveProperty("id");
expect(normalized).toHaveProperty("children");
const { children } = normalized;
const [child] = children;
expect(child).toHaveProperty("fn");
expect(child).toHaveProperty("id");
});
});
});
4 changes: 0 additions & 4 deletions src/components/SideNav/Model/index.js

This file was deleted.

47 changes: 47 additions & 0 deletions src/components/SideNav/Model/normalize-items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @ts-check
import { shortUuid } from "./../../../lib";

const $_FDID = "$_fdId";
const $_FDCHILDREN = "$_fdChildren";

/**
* @typedef {object} NormalizedItem
* @prop {string} $_fdId;
* @prop {NormalizedItem[]} $_fdChildren;
*/

/**
* @param {NormalizedItem} item
* @returns {string}
*/
export const normalizedId = item => item[$_FDID];
/**
* @param {NormalizedItem} item
* @returns {NormalizedItem[]}
*/
export const normalizedChildren = item => item[$_FDCHILDREN];

/**
* @param {any} raw
* @returns {NormalizedItem}
*/
export function normalizeItem(raw) {
if (raw == null) {
return normalizeItem({});
}
const id = raw.id || shortUuid();
const children = normalizeItems(raw.children || []);
return {
...raw,
id,
children,
[$_FDID]: id,
[$_FDCHILDREN]: children
};
}

function normalizeItems(items) {
return items.map(normalizeItem);
}

export default normalizeItems;
Loading

0 comments on commit e27f200

Please sign in to comment.