Selaa lähdekoodia

test component

Vincent GUFFON 4 vuotta sitten
vanhempi
commit
ff2262264b

+ 2 - 5
components/Layout/Breadcrumbs.vue

@@ -1,5 +1,5 @@
 <template>
-  <ol>
+  <ol id="breadcrumbs">
     <li>
       <a class="no-decoration" :href="homeUrl + '/'">
         <span class="ot_green--text">{{$t('welcome')}}</span>
@@ -21,7 +21,6 @@
 <script lang="ts">
   import {defineComponent, computed, useContext, useRouter} from '@nuxtjs/composition-api'
   import {AnyJson} from "~/types/interfaces";
-  import * as _ from "lodash";
 
   export default defineComponent({
     setup() {
@@ -38,8 +37,7 @@
           path = `${path}/${param}`
           const match = $router.match(path)
           if (match.name !== null) {
-            const title = !parseInt(param, 10) ? i18n.t(param.replace(/-/g, ' ') + '_breadcrumbs') : i18n.t('item')
-
+            const title = !parseInt(param, 10) ? i18n.t(param + '_breadcrumbs') : i18n.t('item')
             crumbs.push({
               title: title,
               ...match,
@@ -49,7 +47,6 @@
         return crumbs
       })
 
-
       return {
         crumbs,
         homeUrl

+ 1 - 0
jest.config.js

@@ -11,6 +11,7 @@ module.exports = {
     'vue',
     'json'
   ],
+  testEnvironment: 'jsdom',
   transform: {
     '^.+\\.ts$': 'ts-jest',
     '^.+\\.js$': 'babel-jest',

+ 1 - 1
test/Helpers.ts

@@ -1,6 +1,6 @@
 import Vuex, { Store } from 'vuex'
 import VuexORM from "@vuex-orm/core";
-import { createLocalVue } from "@vue/test-utils"
+import {createLocalVue} from "@vue/test-utils"
 
 const localVue = createLocalVue()
 localVue.use(Vuex)

+ 48 - 0
test/component/Layout/Breadcrumbs.spec.js

@@ -0,0 +1,48 @@
+import Breadcrumbs from "~/components/Layout/Breadcrumbs";
+import {shallowMount, RouterLinkStub} from "@vue/test-utils"
+
+describe("Breadcrumbs", () => {
+  let wrapper
+
+  beforeEach(() => {
+    const $route = {
+      path: '/organization/address/123'
+    }
+
+    const $t = () => { }
+
+    wrapper = shallowMount(Breadcrumbs, {
+      stubs: {
+        NuxtLink: RouterLinkStub
+      },
+      mocks: {
+        $route,
+        $router:{
+          match:()=>{
+            return{
+              name: 'foo',
+              path: 'bar'
+            }
+          }
+        },
+        $nuxt: {
+          context: {
+            $config: {
+              baseURL_adminLegacy: '/'
+            },
+            app: {
+              i18n:{
+                t:() =>{ }
+              }
+            }
+          },
+        },
+        $t
+      }
+    })
+  })
+
+  it("will display 4 li", () => {
+    expect(wrapper.findAll("#breadcrumbs li")).toHaveLength(4);
+  });
+});