-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
126 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { expect, test, describe } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { createRouter, createWebHistory } from 'vue-router' | ||
import NavBar from '../../../components/NavBar/NavBar.vue' | ||
|
||
// Mock router | ||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: [ | ||
{ | ||
path: '/', | ||
name: 'home', | ||
component: NavBar | ||
} | ||
] | ||
}) | ||
|
||
describe('NavBar.vue', () => { | ||
test('Renders correctly with no props or slots', () => { | ||
const wrapper = mount(NavBar, { | ||
global: { | ||
plugins: [router] | ||
} | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.exists()).toBe(true) | ||
expect(wrapper.get('[data-test="navbar-left"]').text()).toMatch('') | ||
expect(wrapper.get('[data-test="navbar-right"]').text()).toMatch('') | ||
}) | ||
|
||
test('Title props provided', () => { | ||
// Arrange | ||
const wrapper = mount(NavBar, { | ||
props: { | ||
title: 'This is the Label as prop', | ||
to: '/' | ||
}, | ||
global: { | ||
plugins: [router] | ||
} | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="navbar-left"]').text()).toMatch('This is the Label as prop') | ||
}) | ||
|
||
test('Title slot provided, and it overwrites the props', () => { | ||
// Arrange | ||
const wrapper = mount(NavBar, { | ||
props: { | ||
label: 'This is the Label as prop' | ||
}, | ||
slots: { | ||
title: 'This is the slot content' | ||
}, | ||
global: { | ||
plugins: [router] | ||
} | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="navbar-left"]').text()).toMatch('This is the slot content') | ||
}) | ||
|
||
test('Right slot provided', () => { | ||
// Arrange | ||
const wrapper = mount(NavBar, { | ||
slots: { | ||
default: '<li>This is the right slot content</li>' | ||
}, | ||
global: { | ||
plugins: [router] | ||
} | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="navbar-right"]').text()).toMatch( | ||
'This is the right slot content' | ||
) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,49 +1,51 @@ | ||
import { expect, test } from 'vitest' | ||
import { expect, test, describe } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import MainContent from '../../../components/NavBar/NavBarDropdown.vue' | ||
|
||
test('Label as slot', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
slots: { | ||
label: 'This is the Label as Slot', | ||
default: 'This is the slot content' | ||
} | ||
describe('NavBarDropdown.vue', () => { | ||
test('Label as slot', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
slots: { | ||
label: 'This is the Label as Slot', | ||
default: 'This is the slot content' | ||
} | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content') | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content') | ||
}) | ||
test('Label as prop', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
props: { | ||
label: 'This is the Label as prop' | ||
}, | ||
slots: { | ||
default: 'This is the slot content' | ||
} | ||
}) | ||
|
||
test('Label as prop', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
props: { | ||
label: 'This is the Label as prop' | ||
}, | ||
slots: { | ||
default: 'This is the slot content' | ||
} | ||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as prop') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content') | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as prop') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('This is the slot content') | ||
}) | ||
test('Label slot overwrite prop', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
props: { | ||
label: 'This is the Label as prop' | ||
}, | ||
slots: { | ||
label: 'This is the Label as Slot' | ||
} | ||
}) | ||
|
||
test('Label slot overwrite prop', () => { | ||
// Arrange | ||
const wrapper = mount(MainContent, { | ||
props: { | ||
label: 'This is the Label as prop' | ||
}, | ||
slots: { | ||
label: 'This is the Label as Slot' | ||
} | ||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('') | ||
}) | ||
|
||
// Assert | ||
expect(wrapper.get('[data-test="label"]').text()).toMatch('This is the Label as Slot') | ||
expect(wrapper.get('[data-test="slot"]').text()).toMatch('') | ||
}) |