From d192837905d286ee80a17bd6849267dff0b1e0b2 Mon Sep 17 00:00:00 2001 From: Sverre <sverrefh@stud.ntnu.no> Date: Tue, 30 Apr 2024 09:13:29 +0200 Subject: [PATCH] Added rendering unit test to PasswordInfo componenet --- src/components/__tests__/PasswordInfo.spec.ts | 25 +++++++++++++++++++ src/components/profile/PasswordInfo.vue | 6 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/components/__tests__/PasswordInfo.spec.ts diff --git a/src/components/__tests__/PasswordInfo.spec.ts b/src/components/__tests__/PasswordInfo.spec.ts new file mode 100644 index 0000000..f8e6d79 --- /dev/null +++ b/src/components/__tests__/PasswordInfo.spec.ts @@ -0,0 +1,25 @@ +import { mount } from '@vue/test-utils' +import PasswordInfo from '@/components/profile/PasswordInfo.vue' +import { describe, it, expect, beforeEach } from 'vitest' +import { createPinia, setActivePinia } from 'pinia' + +describe('PasswordComponent', () => { + + beforeEach(() => { + setActivePinia(createPinia()); + }); + + it('renders correctly', async () => { + const wrapper = mount(PasswordInfo) + + expect(wrapper.exists()).toBe(true) + + expect(wrapper.find('.title').text()).toBe('Passord') + + expect(wrapper.find('.save-button').exists()).toBe(true) + + expect(wrapper.find('[data-testid="current-password-input"]').exists()).toBe(true) + + expect(wrapper.find('[data-testid="new-password-input"]').exists()).toBe(true) + }) +}) diff --git a/src/components/profile/PasswordInfo.vue b/src/components/profile/PasswordInfo.vue index dff3599..29dbbce 100644 --- a/src/components/profile/PasswordInfo.vue +++ b/src/components/profile/PasswordInfo.vue @@ -73,7 +73,8 @@ const clearInput = () => { <input class="input" :class="{'error': currentPasswordError}" type="password" - v-model="currentPassword"> + v-model="currentPassword" + data-testid="current-password-input"> <div class="alert-box"> <h4 v-if="currentPasswordError" class="error-message">{{currentPasswordError}}</h4> </div> @@ -84,7 +85,8 @@ const clearInput = () => { <input class="input" :class="{'error': newPasswordError}" type="password" - v-model="newPassword"> + v-model="newPassword" + data-testid="new-password-input"> <div class="alert-box"> <h4 v-if="newPasswordError" class="error-message">{{newPasswordError}}</h4> <h4 v-if="passwordError" class="error-message">{{passwordError}}</h4> -- GitLab