Skip to content

Commit

Permalink
SPSH 1719 FE: Test Coverage auf 70% erhöhen (#426)
Browse files Browse the repository at this point in the history
* increased thresholds to 70

* added coverage for view functions

* Sorting providers

* Fixed linting

* Calling the method specifically for Email

* removed unnecessary checks

* added more coverage

* Covering dirtiness for KlasseCreation

* covering dirtiness and form submission for schule creation

* cancel import test

* clear autocomplete fields test

* add reset password test

* lock the user test

* trying to cover dirtiness for person creation

* fixed tests

* test change klasse

* more coverage

* chhange klasse refactoring

* delete zuordnung test

* display delete kontext success and test it

* more tests

* review comms

---------

Co-authored-by: godtierbatuhan <[email protected]>
Co-authored-by: Timo K <[email protected]>
  • Loading branch information
3 people authored Feb 24, 2025
1 parent 057227f commit 5249f27
Show file tree
Hide file tree
Showing 26 changed files with 1,482 additions and 386 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import { VueWrapper, mount } from '@vue/test-utils';
import SuccessTemplate from './SuccessTemplate.vue';
import KlasseSuccessTemplate from './KlasseSuccessTemplate.vue';

let wrapper: VueWrapper | null = null;

Expand All @@ -11,7 +11,7 @@ beforeEach(() => {
</div>
`;

wrapper = mount(SuccessTemplate, {
wrapper = mount(KlasseSuccessTemplate, {
attachTo: document.getElementById('app') || '',
props: {
successMessage: 'Klasse updated successfully',
Expand All @@ -25,13 +25,13 @@ beforeEach(() => {
},
global: {
components: {
SuccessTemplate,
KlasseSuccessTemplate,
},
},
});
});

describe('SuccessTemplate', () => {
describe('KlasseSuccessTemplate', () => {
test('it displays the success message and data correctly', () => {
expect(wrapper?.get('[data-testid="klasse-success-text"]').text()).toBe('Klasse updated successfully');
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/admin/personen/PersonLock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
) && !selectedOrganisation
"
@click.stop="isEditMode = true"
data-testid="lock-user-button"
data-testid="edit-user-lock-button"
>
{{ $t('admin.person.editLock') }}
</v-btn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from 'vitest';
import { VueWrapper, mount } from '@vue/test-utils';
import SuccessTemplate from './SuccessTemplate.vue';
import RolleSuccessTemplate from './RolleSuccessTemplate.vue';

let wrapper: VueWrapper | null = null;

Expand All @@ -11,7 +11,7 @@ beforeEach(() => {
</div>
`;

wrapper = mount(SuccessTemplate, {
wrapper = mount(RolleSuccessTemplate, {
attachTo: document.getElementById('app') || '',
props: {
successMessage: 'Role updated successfully',
Expand All @@ -20,7 +20,7 @@ beforeEach(() => {
{ label: 'Role Name', value: 'Test Role', testId: 'updated-rolle-name' },
{ label: 'Merkmale', value: 'Merkmal 1, Merkmal 2', testId: 'updated-rolle-merkmale' },
{ label: 'Assigned Service Providers', value: 'Service Provider 1', testId: 'updated-rolle-angebote' },
{ label: 'System Rights', value: 'Systemrecht 1', testId: 'updated-rolle-systemrecht' },
{ label: 'System Rights', value: 'Systemrecht 1', testId: 'updated-rolle-systemrechte' },
],
backButtonText: 'Back to List',
createAnotherRolleButtonText: 'Create Another',
Expand All @@ -30,13 +30,13 @@ beforeEach(() => {
},
global: {
components: {
SuccessTemplate,
RolleSuccessTemplate,
},
},
});
});

describe('SuccessTemplate', () => {
describe('RolleSuccessTemplate', () => {
test('it displays the success message and data correctly', () => {
expect(wrapper?.get('[data-testid="rolle-success-text"]').text()).toBe('Role updated successfully');
});
Expand Down
10 changes: 9 additions & 1 deletion src/views/ProfileView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type TwoFactorAuthentificationStore,
} from '@/stores/TwoFactorAuthentificationStore';
import { DOMWrapper, VueWrapper, mount } from '@vue/test-utils';
import { beforeEach, describe, expect, test } from 'vitest';
import { beforeEach, describe, expect, test, type MockInstance } from 'vitest';
import { nextTick } from 'vue';
import { createMemoryHistory, createRouter, useRoute, type Router } from 'vue-router';
import ProfileView from './ProfileView.vue';
Expand Down Expand Up @@ -278,6 +278,14 @@ describe('ProfileView', () => {
expect(wrapper?.find('[data-testid="profile-headline"]').isVisible()).toBe(true);
});

test('it goes back to the previous page', () => {
const push: MockInstance = vi.spyOn(router, 'push');

wrapper?.find('[data-testid="back-to-previous-page-button"]').trigger('click');

expect(push).toHaveBeenCalledTimes(1);
});

test('it displays personal data', () => {
personInfoStore.personInfo = mockLehrer;
personStore.personenuebersicht = mockLehrerUebersicht;
Expand Down
55 changes: 46 additions & 9 deletions src/views/StartView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { nextTick } from 'vue';
import StartView from './StartView.vue';
import { type PersonStore, usePersonStore, type PersonWithUebersicht } from '@/stores/PersonStore';
import { usePersonInfoStore, type PersonInfoResponse, type PersonInfoStore } from '@/stores/PersonInfoStore';
import { OrganisationsTyp, RollenArt, RollenMerkmal } from '@/api-client/generated/api';
import { OrganisationsTyp, RollenArt, RollenMerkmal, ServiceProviderKategorie } from '@/api-client/generated/api';

let wrapper: VueWrapper | null = null;
let authStore: AuthStore;
Expand All @@ -21,16 +21,25 @@ let personInfoStore: PersonInfoStore;

const mockProviders: Array<ServiceProvider> = [
{
id: '1',
id: '2',
name: 'Spongebob Squarepants',
target: 'URL',
url: 'https://de.wikipedia.org/wiki/SpongeBob_Schwammkopf',
kategorie: 'EMAIL',
hasLogo: false,
requires2fa: true,
requires2fa: false,
},
{
id: '2',
id: '3',
name: 'Not Squarepants',
target: 'URL',
url: 'https://de.wikipedia.org/wiki/SpongeBob_Schwammkopf',
kategorie: 'EMAIL',
hasLogo: false,
requires2fa: false,
},
{
id: '1',
name: 'Schulportal-Administration',
target: 'SCHULPORTAL_ADMINISTRATION',
url: '',
Expand Down Expand Up @@ -170,7 +179,7 @@ describe('StartView', () => {
authStore.hasPersonenverwaltungPermission = true;
await nextTick();

const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-2"]');
const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-1"]');

expect(adminCard?.isVisible()).toBe(true);
expect(adminCard?.attributes('href')).toEqual('/admin/personen');
Expand All @@ -180,7 +189,7 @@ describe('StartView', () => {
authStore.hasSchulverwaltungPermission = true;
await nextTick();

const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-2"]');
const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-1"]');

expect(adminCard?.isVisible()).toBe(true);
expect(adminCard?.attributes('href')).toEqual('/admin/schulen');
Expand All @@ -190,7 +199,7 @@ describe('StartView', () => {
authStore.hasRollenverwaltungPermission = true;
await nextTick();

const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-2"]');
const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-1"]');

expect(adminCard?.isVisible()).toBe(true);
expect(adminCard?.attributes('href')).toEqual('/admin/rollen');
Expand All @@ -200,17 +209,45 @@ describe('StartView', () => {
authStore.hasKlassenverwaltungPermission = true;
await nextTick();

const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-2"]');
const adminCard: WrapperLike | undefined = wrapper?.findComponent('[data-testid="service-provider-card-1"]');

expect(adminCard?.isVisible()).toBe(true);
expect(adminCard?.attributes('href')).toEqual('/admin/klassen');
});

test('banner has correct color', async () => {
test('it displays correct banner color', async () => {
await nextTick();

const banner: WrapperLike | undefined = wrapper?.find('[data-testid="KOPERS-banner"]');

expect(banner?.classes()).toContain('bg-errorLight');
});

test('it dismisses the banner', async () => {
await nextTick();
const banner: VueWrapper | undefined = wrapper?.findComponent({ ref: 'spsh-banner' });

expect(banner?.find('[data-testid="banner-close-icon"]').isVisible()).toBe(true);
banner?.find('[data-testid="banner-close-icon"]').trigger('click');
await nextTick();
expect(banner?.emitted('dismissBanner')).toBeTruthy();
});

test('filterSortProviders sorts service providers alphabetically', () => {
serviceProviderStore.availableServiceProviders = mockProviders;

interface StartViewComponent {
filterSortProviders: (providers: ServiceProvider[], kategorie: ServiceProviderKategorie) => ServiceProvider[];
}

const filteredSortProviders: ServiceProvider[] = (wrapper?.vm as unknown as StartViewComponent).filterSortProviders(
mockProviders,
ServiceProviderKategorie.Email,
);

expect(filteredSortProviders.map((p: ServiceProvider) => p.name)).toEqual([
'Not Squarepants',
'Spongebob Squarepants',
]);
});
});
5 changes: 3 additions & 2 deletions src/views/StartView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@
v-bind:key="alert.id"
v-for="alert in alerts"
:id="alert.id.toString()"
:visible="alert.visible"
ref="spsh-banner"
:text="alert.message"
:type="alert.type"
@dismiss-banner="dismissBannerForSession"
:visible="alert.visible"
@dismissBanner="dismissBannerForSession"
></SpshBanner>
</v-col>
</v-row>
Expand Down
Loading

0 comments on commit 5249f27

Please sign in to comment.