Skip to content

Commit

Permalink
ci(main): test include front coverage to sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthym committed Aug 30, 2024
1 parent 0421988 commit a946e2e
Show file tree
Hide file tree
Showing 26 changed files with 582 additions and 52 deletions.
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,19 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.moduleKey>${project.groupId}:${project.artifactId}</sonar.moduleKey>
<sonar.coverage.jacoco.xmlReportPaths>**/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.coverage.exclusions>**/*.html</sonar.coverage.exclusions>
<sonar.exclusions>**/*.html</sonar.exclusions>
<sonar.javascript.lcov.reportPaths>**/lcov.info
</sonar.javascript.lcov.reportPaths>
<sonar.coverage.exclusions>
**/*.html,
**/*.test.*,
**/locales/**,
${project.basedir}/seaside/dist/**
</sonar.coverage.exclusions>
<sonar.exclusions>
**/*.html,
**/locales/**,
**/dist/**
</sonar.exclusions>
<sonar.java.binaries>${project.build.directory}/classes</sonar.java.binaries>
<sonar.java.libraries>${project.build.directory}/dependency</sonar.java.libraries>
</properties>
Expand Down
6 changes: 3 additions & 3 deletions seaside/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.DS_Store
node_modules
/dist
/coverage

dist
coverage
.scannerwork

# local env files
.env.local
Expand Down
4 changes: 3 additions & 1 deletion seaside/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dev": "vite",
"lint": "eslint --fix --ext .js,.vue --ignore-path .gitignore src",
"preview": "vite preview",
"test": "vitest"
"test": "vitest",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@heroicons/vue": "2.1.5",
Expand All @@ -30,6 +31,7 @@
"@typescript-eslint/eslint-plugin": "8.0.1",
"@typescript-eslint/parser": "8.0.1",
"@vitejs/plugin-vue": "5.1.2",
"@vitest/coverage-v8": "2.0.5",
"@vue/test-utils": "2.4.6",
"autoprefixer": "10.4.20",
"eslint": "9.9.0",
Expand Down
15 changes: 14 additions & 1 deletion seaside/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
</goals>
</execution>
<execution>
<id>Webpack build</id>
<id>Vite build</id>
<phase>generate-resources</phase>
<configuration>
<executable>yarn</executable>
Expand All @@ -122,6 +122,19 @@
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>Vitest Coverage</id>
<phase>generate-resources</phase>
<configuration>
<executable>yarn</executable>
<arguments>
<argument>coverage</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
12 changes: 8 additions & 4 deletions seaside/src/configuration/components/feedslist/FeedEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<span class="label-text capitalize">{{ t('config.feeds.editor.form.name') }}</span>
</label>
<input id="feedName" v-model="feed.name" :class="{'input-error': errors.indexOf('name') > -1}"
class="input input-bordered placeholder:capitalize" :placeholder="t('config.feeds.editor.form.name.placeholder')"
:placeholder="t('config.feeds.editor.form.name.placeholder')"
class="input input-bordered placeholder:capitalize"
type="text">

<label class="label" for="feedDescription">
Expand All @@ -29,7 +30,10 @@
</form>
<template v-slot:actions>
<button class="btn capitalize" @click.stop="resetAndCloseModal">{{ t('dialog.cancel') }}</button>
<button class="btn btn-primary capitalize" @click="onSaveFeed">{{ t('config.feeds.editor.form.action.submit') }}</button>
<button class="btn btn-primary capitalize" @click="onSaveFeed">{{
t('config.feeds.editor.form.action.submit')
}}
</button>
</template>
</ModalWindow>
</template>
Expand All @@ -40,7 +44,7 @@ import { Feed } from '@/configuration/model/Feed.type';
import { Observable, Subject } from 'rxjs';
import ModalWindow from '@/common/components/ModalWindow.vue';
import TagInput from '@/common/components/TagInput.vue';
import tagsService from '@/techwatch/services/TagsService';
import { tagsListAll } from '@/techwatch/services/TagsService';
import feedService from '@/configuration/services/FeedService';
import { URL_PATTERN } from '@/common/services/RegexPattern';
import { useI18n } from 'vue-i18n';
Expand Down Expand Up @@ -111,7 +115,7 @@ export default class FeedEditor extends Vue {
}
private listAvailableTags(): Observable<string[]> {
return tagsService.list();
return tagsListAll();
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class ProfileTab extends Vue {
get avatar(): string {
let avatarHash = '0';
const user = this.store.state.user.user;
if (user.mail !== '') {
if (user.mail && user.mail !== '') {
avatarHash = MD5.generate(user.mail);
}
return `https://www.gravatar.com/avatar/${avatarHash}?s=96&d=retro`;
Expand Down
22 changes: 11 additions & 11 deletions seaside/src/layout/components/sidenav/SideNavFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<li>
<label class="label cursor-pointer py-1">
<span class="label-text">{{ t('sidenav.filters.unread') }}</span>
<input type="checkbox" class="toggle"
@change="onChangeUnread" :checked="newsStore.unread">
<input :checked="newsStore.unread" class="toggle"
type="checkbox" @change="onChangeUnread">
</label>
</li>
<li>
<label class="label cursor-pointer py-1">
<span class="label-text">{{ t('sidenav.filters.popular') }}</span>
<input type="checkbox" class="toggle"
@change="onChangePopular" :checked="newsStore.popular">
<input :checked="newsStore.popular" class="toggle"
type="checkbox" @change="onChangePopular">
</label>
</li>
</ul>
Expand All @@ -31,7 +31,7 @@

<ul class="flex flex-wrap list-none mt-4">
<li v-for="tag in tags" v-bind:key="tag">
<button class="badge m-1" :class="{'badge-accent': newsStore.tags[0] && tag === newsStore.tags[0]}"
<button :class="{'badge-accent': newsStore.tags[0] && tag === newsStore.tags[0]}" class="badge m-1"
@click="selectTag">
{{ tag }}
</button>
Expand All @@ -50,7 +50,7 @@

<script lang="ts">
import { Component, Vue } from 'vue-facing-decorator';
import tagsService from '@/techwatch/services/TagsService';
import { tagsListAll } from '@/techwatch/services/TagsService';
import { actionServiceReload } from '@/common/services/ReloadActionService';
import { Router, useRouter } from 'vue-router';
import { useStore } from 'vuex';
Expand Down Expand Up @@ -86,18 +86,18 @@ export default class SideNavFilters extends Vue {
private newsStore: NewsStore;
private tags: string[] = [];
get feedFilter(): FeedFilter | undefined {
return this.newsStore.feed;
}
mounted(): void {
tagsService.list().subscribe({
tagsListAll().subscribe({
next: tags => {
this.tags = tags;
},
});
}
get feedFilter(): FeedFilter | undefined {
return this.newsStore.feed;
}
selectTag(event: MouseEvent): void {
const currentTags = this.newsStore.tags;
const selected = (event.target as HTMLElement).innerText;
Expand Down
2 changes: 1 addition & 1 deletion seaside/src/security/pages/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
type="password"
@keyup="formValidation=false">
</label>
<button class="btn btn-primary mt-4 w-full mt-8" type="submit">{{ t('login.login') }}</button>
<button class="btn btn-primary w-full mt-8" type="submit">{{ t('login.login') }}</button>
</form>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion seaside/src/teams/components/TeamEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class TeamEditor extends Vue {
next: team => {
Object.assign(this.value.data, team);
this.payload.updated = true;
store.commit(USER_ADD_ROLE_MUTATION, `MANAGER:${team._id}`);
this.store.commit(USER_ADD_ROLE_MUTATION, `MANAGER:${team._id}`);
notificationService.pushSimpleOk(`Team ${team.name} saved successfully !`);
},
});
Expand Down
37 changes: 15 additions & 22 deletions seaside/src/techwatch/services/TagsService.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import {switchMap, take} from "rxjs/operators";
import {HttpStatusError} from "@/common/errors/HttpStatusError";
import {from, Observable} from "rxjs";
import { switchMap, take } from 'rxjs/operators';
import { HttpStatusError } from '@/common/errors/HttpStatusError';
import { from, Observable } from 'rxjs';
import rest from '@/common/services/RestWrapper';

export class TagsService {
/**
* List all available tags from backend
*/
list(): Observable<string[]> {
return rest.get('/tags').pipe(
switchMap(response => {
if (response.ok) {
const data: Observable<string[]> = from(response.json());
return data;
} else {
throw new HttpStatusError(response.status, `Error while getting tags.`);
}
}),
take(1)
);
}
export function tagsListAll(): Observable<string[]> {
return rest.get('/tags').pipe(
switchMap(response => {
if (response.ok) {
const data: Observable<string[]> = from(response.json());
return data;
} else {
throw new HttpStatusError(response.status, `Error while getting tags.`);
}
}),
take(1),
);
}

export default new TagsService();
32 changes: 32 additions & 0 deletions seaside/tests/unit/administration/component/UserAdminTab.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, expect, test, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import UserAdminTab from '@/administration/component/UserAdminTab.vue';
import { of } from 'rxjs';
import { userList } from '@/security/services/UserService';

vi.mock('@/security/services/UserService', () => {
return {
userList: vi.fn().mockImplementation(() => of({ data: [] })),
};
});

describe('UserAdminTab', () => {
test('render user admin tab', () => {

const i18n = createI18n({
legacy: false,
missingWarn: false,
messages: { 'en': {} },
});

const wrapper = mount(UserAdminTab, {
global: {
plugins: [i18n],
},
});
expect(wrapper.find('table').exists()).toBe(true);
expect(wrapper.find('table').attributes('aria-describedby')).toEqual('User List');
expect(userList).toHaveBeenCalledWith(0);
});
});
48 changes: 48 additions & 0 deletions seaside/tests/unit/administration/page/AdministrationPage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, test, vi } from 'vitest';
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import AdministrationPage from '@/administration/page/AdministrationPage.vue';
import { createRouter, createWebHashHistory } from 'vue-router';
import { routes as adminRoutes } from '@/administration/router';
import LoginPage from '@/security/pages/LoginPage.vue';
import UserAdminTab from '@/administration/component/UserAdminTab.vue';
import { of } from 'rxjs';

vi.mock('@/security/services/UserService', () => {
return {
userList: vi.fn().mockImplementation(() => of({ data: [] })),
};
});

describe('AdministrationPage', () => {
test('render user /admin page', async () => {

const $store = {
state: { user: { user: { _id: '42' } } },
commit: vi.fn(),
};
const i18n = createI18n({
legacy: false,
missingWarn: false,
messages: { 'en': {} },
});

const router = createRouter({
history: createWebHashHistory(),
routes: [
...adminRoutes,
{ path: '/', component: LoginPage, name: 'test' },
],
});
await router.push('/admin');
await router.isReady();
const wrapper = mount(AdministrationPage, {
global: {
plugins: [i18n, router],
provide: { store: $store },
},
});
expect(wrapper.find('nav').exists()).toBe(true);
expect(wrapper.findComponent(UserAdminTab).isVisible()).toBe(true);
});
});
11 changes: 11 additions & 0 deletions seaside/tests/unit/common/components/BaywatchIcon.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, test } from 'vitest';
import { mount } from '@vue/test-utils';
import BaywatchIcon from '@/common/components/BaywatchIcon.vue';

describe('BaywatchIcon', () => {
test('render Baywatch Icon', async () => {
const wrapper = mount(BaywatchIcon);

expect(wrapper.find('svg').exists()).toBe(true);
});
});
22 changes: 22 additions & 0 deletions seaside/tests/unit/common/components/FileUploadWindow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, test } from 'vitest';
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import FileUploadWindow from '@/common/components/FileUploadWindow.vue';

describe('FileUploadWindow', () => {
test('render file upload window', async () => {
const i18n = createI18n({
legacy: false,
missingWarn: false,
messages: { 'en': {} },
});

const wrapper = mount(FileUploadWindow, {
global: {
plugins: [i18n],
},
});

expect(wrapper.find('button').exists()).toBe(true);
});
});
Loading

0 comments on commit a946e2e

Please sign in to comment.