Introduce basic js unit tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-12-02 11:19:39 +01:00
parent 88cba1629d
commit 2f25fa0ca6
23 changed files with 2345 additions and 185 deletions

View File

@@ -1,12 +1,13 @@
<template>
<MobilizonLogo />
<mobilizon-logo />
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import MobilizonLogo from "../assets/mobilizon_logo.svg?inline";
import MobilizonLogo from "../assets/mobilizon_logo.svg";
// TODO: Jest does not like the ?inline after the import path
@Component({
components: {

View File

@@ -2,6 +2,7 @@ import Vue from "vue";
import Router, { Route } from "vue-router";
import VueScrollTo from "vue-scrollto";
import { PositionResult } from "vue-router/types/router.d";
import { EsModuleComponent } from "vue/types/options";
import Home from "../views/Home.vue";
import { eventRoutes } from "./event";
import { actorRoutes } from "./actor";
@@ -34,125 +35,125 @@ function scrollBehavior(
return { x: 0, y: 0 };
}
export const routes = [
...userRoutes,
...eventRoutes,
...settingsRoutes,
...actorRoutes,
...groupsRoutes,
...discussionRoutes,
...errorRoutes,
{
path: "/search",
name: RouteName.SEARCH,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "search" */ "../views/Search.vue"),
props: true,
meta: { requiredAuth: false },
},
{
path: "/",
name: RouteName.HOME,
component: Home,
meta: { requiredAuth: false },
},
{
path: "/about",
name: RouteName.ABOUT,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "about" */ "@/views/About.vue"),
meta: { requiredAuth: false },
redirect: { name: RouteName.ABOUT_INSTANCE },
children: [
{
path: "instance",
name: RouteName.ABOUT_INSTANCE,
component: (): Promise<EsModuleComponent> =>
import(
/* webpackChunkName: "about" */ "@/views/About/AboutInstance.vue"
),
},
{
path: "/terms",
name: RouteName.TERMS,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "cookies" */ "@/views/About/Terms.vue"),
meta: { requiredAuth: false },
},
{
path: "/privacy",
name: RouteName.PRIVACY,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "cookies" */ "@/views/About/Privacy.vue"),
meta: { requiredAuth: false },
},
{
path: "/rules",
name: RouteName.RULES,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "cookies" */ "@/views/About/Rules.vue"),
meta: { requiredAuth: false },
},
{
path: "/glossary",
name: RouteName.GLOSSARY,
component: (): Promise<EsModuleComponent> =>
import(
/* webpackChunkName: "cookies" */ "@/views/About/Glossary.vue"
),
meta: { requiredAuth: false },
},
],
},
{
path: "/interact",
name: RouteName.INTERACT,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "cookies" */ "@/views/Interact.vue"),
meta: { requiredAuth: false },
},
{
path: "/auth/:provider/callback",
name: "auth-callback",
component: (): Promise<EsModuleComponent> =>
import(
/* webpackChunkName: "ProviderValidation" */ "@/views/User/ProviderValidation.vue"
),
},
{
path: "/welcome/:step?",
name: RouteName.WELCOME_SCREEN,
component: (): Promise<EsModuleComponent> =>
import(
/* webpackChunkName: "WelcomeScreen" */ "@/views/User/SettingsOnboard.vue"
),
meta: { requiredAuth: true },
props: (route: Route): Record<string, unknown> => {
const step = Number.parseInt(route.params.step, 10);
if (Number.isNaN(step)) {
return { step: 1 };
}
return { step };
},
},
{
path: "/404",
name: RouteName.PAGE_NOT_FOUND,
component: (): Promise<EsModuleComponent> =>
import(/* webpackChunkName: "search" */ "../views/PageNotFound.vue"),
meta: { requiredAuth: false },
},
{
path: "*",
redirect: { name: RouteName.PAGE_NOT_FOUND },
},
];
const router = new Router({
scrollBehavior,
mode: "history",
base: "/",
routes: [
...userRoutes,
...eventRoutes,
...settingsRoutes,
...actorRoutes,
...groupsRoutes,
...discussionRoutes,
...errorRoutes,
{
path: "/search",
name: RouteName.SEARCH,
component: () =>
import(/* webpackChunkName: "search" */ "../views/Search.vue"),
props: true,
meta: { requiredAuth: false },
},
{
path: "/",
name: RouteName.HOME,
component: Home,
meta: { requiredAuth: false },
},
{
path: "/about",
name: RouteName.ABOUT,
component: () =>
import(/* webpackChunkName: "about" */ "@/views/About.vue"),
meta: { requiredAuth: false },
redirect: { name: RouteName.ABOUT_INSTANCE },
children: [
{
path: "instance",
name: RouteName.ABOUT_INSTANCE,
component: () =>
import(
/* webpackChunkName: "about" */ "@/views/About/AboutInstance.vue"
),
},
{
path: "/terms",
name: RouteName.TERMS,
component: () =>
import(/* webpackChunkName: "cookies" */ "@/views/About/Terms.vue"),
meta: { requiredAuth: false },
},
{
path: "/privacy",
name: RouteName.PRIVACY,
component: () =>
import(
/* webpackChunkName: "cookies" */ "@/views/About/Privacy.vue"
),
meta: { requiredAuth: false },
},
{
path: "/rules",
name: RouteName.RULES,
component: () =>
import(/* webpackChunkName: "cookies" */ "@/views/About/Rules.vue"),
meta: { requiredAuth: false },
},
{
path: "/glossary",
name: RouteName.GLOSSARY,
component: () =>
import(
/* webpackChunkName: "cookies" */ "@/views/About/Glossary.vue"
),
meta: { requiredAuth: false },
},
],
},
{
path: "/interact",
name: RouteName.INTERACT,
component: () =>
import(/* webpackChunkName: "cookies" */ "@/views/Interact.vue"),
meta: { requiredAuth: false },
},
{
path: "/auth/:provider/callback",
name: "auth-callback",
component: () =>
import(
/* webpackChunkName: "ProviderValidation" */ "@/views/User/ProviderValidation.vue"
),
},
{
path: "/welcome/:step?",
name: RouteName.WELCOME_SCREEN,
component: () =>
import(
/* webpackChunkName: "WelcomeScreen" */ "@/views/User/SettingsOnboard.vue"
),
meta: { requiredAuth: true },
props: (route) => {
const step = Number.parseInt(route.params.step, 10);
if (Number.isNaN(step)) {
return 1;
}
return { step };
},
},
{
path: "/404",
name: RouteName.PAGE_NOT_FOUND,
component: () =>
import(/* webpackChunkName: "search" */ "../views/PageNotFound.vue"),
meta: { requiredAuth: false },
},
{
path: "*",
redirect: { name: RouteName.PAGE_NOT_FOUND },
},
],
routes,
});
router.beforeEach(authGuardIfNeeded);

View File

@@ -5,3 +5,10 @@ declare module "*.vue" {
const component: DefineComponent<{}, {}, any>;
export default component;
}
declare module "*.svg" {
import Vue, { VueConstructor } from "vue";
const content: VueConstructor<Vue>;
export default content;
}

View File

@@ -17,4 +17,5 @@ export interface IPost {
author?: IActor;
attributedTo?: IActor;
publishAt?: Date;
insertedAt?: Date;
}

View File

@@ -18,6 +18,7 @@ import { Socket as PhoenixSocket } from "phoenix";
import * as AbsintheSocket from "@absinthe/socket";
import { createAbsintheSocketLink } from "@absinthe/socket-apollo-link";
import { getMainDefinition } from "apollo-utilities";
import fetch from "unfetch";
import { GRAPHQL_API_ENDPOINT, GRAPHQL_API_FULL_PATH } from "./api/_entrypoint";
import { fragmentMatcher, refreshAccessToken } from "./apollo/utils";
@@ -56,6 +57,7 @@ const authMiddleware = new ApolloLink((operation, forward) => {
const uploadLink = createLink({
uri: httpEndpoint,
fetch,
});
const phoenixSocket = new PhoenixSocket(wsEndpoint, {