Skip to content

Commit

Permalink
Dynamic Navigation Component
Browse files Browse the repository at this point in the history
- Create dyanmic nci-nav vue component
- Create Storybook story for nci-nav component
- Create test for nci-nnav component

[Ticket: NCI-11]
  • Loading branch information
ryanmstokes committed Aug 9, 2021
1 parent d20e064 commit 2de41ff
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 117 deletions.
10 changes: 7 additions & 3 deletions nci/app/components/nci-anchor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ const nciAnchor = defineComponent({
type: String as PropType<string>,
required: false,
},
active: {
selected: {
type: String as PropType<string>,
required: false,
default: "",
},
},
setup: (props) => {
console.log("props selected:", props.selected);
let componentType: string = "";
let pointer: string = "";
let styles: string = "";
props.href.includes("http")
? ((componentType = "a"), (pointer = "href"))
: ((componentType = "nuxt-link"), (pointer = "to"));
props.active
? (styles = props.styles! + props.active)
props.selected
? (styles = props.styles! + props.selected)
: (styles = props.styles!);
console.log("componentType:", componentType, pointer, "styles:", styles);
return () =>
Expand All @@ -52,6 +53,9 @@ const nciAnchor = defineComponent({
[pointer]: props.href,
class: styles,
},
on: {
mouseOver: () => console.log("over"),
},
},
props.title
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// tests/unit/Button.spec.js

import { mount } from '@vue/test-utils';

import nciAnchor from '@/nci/app/components/nci-anchor/index.vue';
Expand Down
3 changes: 2 additions & 1 deletion nci/app/components/nci-nav/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('nci-nav test', () => {
propsData: {
routes: routes,
styles: "nav",
childStyles: "item"
childStyles: "item",
currentRoute: "/home"
},
stubs: ['nuxt-link']
})
Expand Down
13 changes: 9 additions & 4 deletions nci/app/components/nci-nav/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const nciNav = defineComponent({
type: String as PropType<string>,
required: true,
},
selected: {
/** Rename this to selectedClass */
type: String as PropType<string>,
required: false,
},
},
setup(props) {
const createComponent = (component: ButtonCompiled) => {
Expand All @@ -40,21 +45,21 @@ const nciNav = defineComponent({
});
};
let active: string;
let active: string | undefined;
let navComponentArray = [] as object[];
props.routes.map((route: Route) => {
route.path === "/" + props.currentRoute
? (active = "active")
: (active = "");
? (active = props.selected!)
: (active = undefined);
route.path !== "/:index"
? navComponentArray.push(
createComponent({
href: route.path,
title: route.name,
styles: props.childStyles,
active: active,
selected: active,
})
)
: null;
Expand Down
15 changes: 15 additions & 0 deletions nci/app/components/nci-nav/stories/nav/__test__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mount } from '@vue/test-utils';

import nciNav from '@/nci/app/components/nci-nav/index.vue';

//👇 Imports a specific story for the test
import { nav } from '@/nci/app/components/nci-nav/stories/nav/index.stories';

it('renders the button in the primary state', () => {
const wrapper = mount(nciNav, {
propsData: nav.args,
stubs: ['nuxt-link']
});

expect(wrapper).toBeTruthy();
});
1 change: 1 addition & 0 deletions nci/app/components/nci-nav/stories/nav/index.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const data = {
styles: "nav",
childStyles: props.styles,
routes: routes,
currentRoute: "/home"
}

console.log('generateprops', generateProps(data), data)
Expand Down
50 changes: 15 additions & 35 deletions nci/app/components/nci-page/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ import { Pages, Page } from '@/nci/app/interfaces';
import Config from '@/nci/data/demo';

import registerComponents from '@/nci/app/testing/registerComponents'
import { useRoute } from '@nuxtjs/composition-api';
import createMemoryHistory from 'vue-router'


const {
VueRouterMock,
createRouterMock,
injectRouterMock,
} = require('vue-router-mock')

/** Slide Component Tests */
/**
Expand All @@ -32,42 +23,31 @@ describe('nci-page component', () => {
registerComponents();
});

const router = createRouterMock({ value: { params: { index: '/home' } } })
beforeEach(() => {
// inject it globally to ensure `useRoute()`, `$route`, etc work
// properly and give you access to test specific functions
injectRouterMock(router)
})

const pages = Config.pages as Pages;
const nav = {
design: {
styles: "nav",
childStyles: "blah",
size: "sm",
color: "primary",
},
routes: [{
path: "/about",
name: "route"
}]
}

Object.keys(pages).forEach(key => {
test('Testing page:' + key, () => {

/*jest.mock('vue-router', () => ({
useRoute: jest.fn(() => ({ value: { params: { index: '/home' } } }))
}))*/
const nav = {
design: {
styles: "nav",
childStyles: "blah",
size: "sm",
color: "primary",
},
routes: [{
path: "/about",
name: "route"
}],
route: key
}
let wrapper = shallowMount(nciPage, {
propsData: {
page: pages[key] as Page,
nav: nav,
},
stubs: ['nuxt-link'],
history: createMemoryHistory,
mocks: {
getCurrentRoute: jest.fn(() => ({ value: { params: { index: '/home' } } }))
}
stubs: ['nuxt-link']
})
/** Check the component mounted */
expect(wrapper.vm).toBeTruthy();
Expand Down
26 changes: 14 additions & 12 deletions nci/app/components/nci-page/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { defineComponent, h } from "@nuxtjs/composition-api";
import buildSections from "@/nci/app/factories/sections";
import nav from "@/nci/app/factories/nav";
import { useRoute } from "@nuxtjs/composition-api";
/** NCI-PAGE */
/**
* Setup the Index page of the application
Expand All @@ -27,15 +23,21 @@ export default defineComponent({
required: true,
},
},
methods: {},
setup(props) {
const getCurrentRoute = useRoute().value.params.index;
return () =>
h("div", { class: "page" }, [
nav(props.nav.routes, getCurrentRoute, props.nav.design.styles),
buildSections(props.page.sections),
]);
console.log("nci-page component loaded");
/** Render navigation */
const nav = h("nci-nav", {
props: {
routes: props.nav.routes,
styles: "nav",
childStyles: props.nav.design.styles,
currentRoute: props.nav.route,
selected: props.nav.design.selected,
},
});
/** Render page sections */
const sections = buildSections(props.page.sections);
return () => h("div", { class: "page" }, [nav, sections]);
},
});
</script>
17 changes: 0 additions & 17 deletions nci/app/factories/nav/index.ts

This file was deleted.

20 changes: 13 additions & 7 deletions nci/app/injectors/injectObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ const injectObject = (themeObject: ThemeObject, componentObject: any) => { //**

if (componentObject[key2] == key3) {
if (componentObject)

/** Inject the value of the theme property into the component */
if (!componentObject.styles) { componentObject.styles = '' }

componentObject.styles = themeObject[key2][key3] + " " + componentObject.styles
delete componentObject[key2]
if (key2 !== 'selected') {
/** Inject the value of the theme property into the component */
if (!componentObject.styles) { componentObject.styles = '' }

componentObject.styles = themeObject[key2][key3] + " " + componentObject.styles
delete componentObject[key2]
} else {
componentObject.selected = themeObject[key2][key3]
}
}
}
}
}
}

console.log('componentObject', componentObject)
return componentObject
}

export default injectObject



2 changes: 1 addition & 1 deletion nci/app/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ interface ButtonCompiled {
href: string
title: string,
styles: string,
active?: string
selected?: string
}

/**
Expand Down
17 changes: 1 addition & 16 deletions nci/data/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ConfigFile = {
type: "anchor",
size: "sm",
color: "nav",
selected: "primary",
styles: ""
},
pages: {
Expand Down Expand Up @@ -55,22 +56,6 @@ const ConfigFile = {
color: "primary",
styles: "button"
},
buttonInfo: {
type: "anchor",
href: "/about",
title: "Contact Us",
size: "sm",
color: "primary",
styles: "button"
},
buttonInfoB: {
type: "anchor",
href: "/about",
title: "Contact Us",
size: "sm",
color: "primary",
styles: "button"
}
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions nci/theme/default-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Theme = {
},
section: {
layout: {
container: "m-auto flex flex-col justify-center items-center max-w-screen-lg",
container: "m-auto flex flex-col justify-center items-center max-w-screen-lg xx-r",
centered: "m-auto flex flex-col justify-center items-center text-center sm:w-5/6 md:w-2/3 lg:w-1/2",
left: "m-auto flex flex-col justify-center items-center text-center sm:w-4/6 md:grid md:grid-rows-1 md:grid-flow-col md:gap-4 md:text-left md:items-left md:justify-left sm:w-5/6 md:w-2/3 lg:w-1/2"
}
Expand Down Expand Up @@ -72,21 +72,25 @@ const Theme = {
},
anchor: {
size: {
xs: "text-xs py-2 px-7 my-4",
sm: "text-sm py-3 px-8 my-5",
md: "text-md py-4 px-9 my-6",
lg: "text-lg py-5 px-10 my-7",
xl: "text-xl py-6 px-11 my-8",
xl2: "text-xl2 py-7 px-12 my-9",
xl3: "text-xl3 py-8 px-13 my-10",
xl4: "text-xl4 py-9 px-14 my-11",
xs: "text-xs py-2 px-7 my-4 mx-1",
sm: "text-sm py-3 px-8 my-5 mx-2",
md: "text-md py-4 px-9 my-6 mx-3",
lg: "text-lg py-5 px-10 my-7 mx-4",
xl: "text-xl py-6 px-11 my-8 mx-5",
xl2: "text-xl2 py-7 px-12 my-9 mx-6",
xl3: "text-xl3 py-8 px-13 my-10 mx-7",
xl4: "text-xl4 py-9 px-14 my-11 mx-8",
},
color: {
primary: "bg-transparent uppercase rounded border border-primary text-primary hover:bg-gray-300 hover:border-transparent hover:text-white",
secondary: "bg-transparent uppercase rounded text-green-700 border border-green-500 hover:bg-green-500 hover:border-transparent hover:text-white",
tertiary: "bg-transparent uppercase rounded text-red-700 border border-red-500 hover:bg-red-500 hover:border-transparent hover:text-white",
nav: "text-primary hover:text-secondary"
nav: "text-primary border-b border-double border-transparent hover:border-current cursor-pointer select-none"
},
selected: {
primary: "border-0 border-b border-current border-solid",
secondary: "background-black text-white-500"
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NuxtConfig } from "@nuxt/types";
import ConfigFile from './nci/data/demo'
const config: NuxtConfig = {
// Target: https://go.nuxtjs.dev/config-target
target: 'static',
target: 'server',

// Global page headers: https://go.nuxtjs.dev/config-head
head: {
Expand Down Expand Up @@ -38,6 +38,11 @@ const config: NuxtConfig = {
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],
generate: {
// choose to suit your project
interval: 12000,
},
env: { NODE_ENV: 'dev' },
storybook: {
addons: [
'@storybook/addon-controls',
Expand Down
Loading

0 comments on commit 2de41ff

Please sign in to comment.