Skip to content

Commit

Permalink
test: pages (#176)
Browse files Browse the repository at this point in the history
* test: settings page

* test: stats page

* test: performance page

* test: donate view

* test: mock calengrade view

* test: confirmation view

* test: recovery page

* test: sign up page

* refactor: remove comments and correct import

* feat: highcharts acessibility module

* fix: signup page as confirmed route

---------

Co-authored-by: FusiDaniel <[email protected]>
  • Loading branch information
RenanLorijola and FusiDaniel authored Nov 17, 2023
1 parent 85a373d commit 7bd654f
Show file tree
Hide file tree
Showing 40 changed files with 3,464 additions and 343 deletions.
4 changes: 3 additions & 1 deletion apps/container/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { computed, onMounted } from 'vue';
import create from 'vue-zustand';
import { ElMessage } from 'element-plus';
import router from './router';
import { useRouter } from 'vue-router';
const router = useRouter();
import { AppBar } from '@/layouts/AppBar';
Expand Down
20 changes: 3 additions & 17 deletions apps/container/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@tanstack/vue-query';
import client from './queryClient';

import { ThemeDefinition } from 'vuetify/lib/framework.mjs';
import { createVuetify } from 'vuetify';
import * as components from 'vuetify/components';
import * as directives from 'vuetify/directives';
Expand All @@ -22,26 +21,13 @@ import '@mdi/font/css/materialdesignicons.css';
import HighchartsVue from 'highcharts-vue';
import Highcharts from 'highcharts';
import annotationsInit from 'highcharts/modules/annotations';
import accessibility from "highcharts/modules/accessibility";
import { QueryClient } from '@tanstack/query-core';
import { theme } from './theme';

accessibility(Highcharts);
annotationsInit(Highcharts);

export const theme: ThemeDefinition = {
dark: false,
colors: {
navigation: '#215096',
primary: '#2e7eed',
secondary: '#f3f6f7',
'ufabcnext-green': '#37bba3',
'next-gray': '#404040',
'next-light-gray': '#848687',
'ufabcnext-yellow': '#FFCB17',
'ufabcnext-red': '#E17472',
error: '#f45576',
background: '#ffffff',
},
};

const vuetify = createVuetify({
components,
directives,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

<script setup lang="ts">
import { PropType, computed, ref } from 'vue';
import { Enrollment } from 'services';
import { ReviewDialog } from '@/components/ReviewDialog';
import { checkEAD, conceptsColor, formatSeason } from 'utils';
import { Enrollment } from 'types';
const showDialog = ref(false);
const conceptStyle = computed(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:class="`pa-0 py-2 ${index % 2 === 0 ? '' : 'pl-md-4'}`"
:key="enrollment._id"
>
<PendingReviewEnrollment class="mt-4" :enrollment="enrollment" />
<PendingReviewEnrollment :enrollment="enrollment" />
</v-col>
</v-row>
</v-container>
Expand All @@ -23,11 +23,12 @@

<script setup lang="ts">
import { PaperCard } from '@/components/PaperCard';
import { Enrollment, Enrollments } from 'services';
import { Enrollments } from 'services';
import { useQuery } from '@tanstack/vue-query';
import { PendingReviewEnrollment } from '@/components/PendingReviewEnrollment';
import { FeedbackAlert } from '@/components/FeedbackAlert';
import { computed } from 'vue';
import { Enrollment } from 'types';
const { data: enrollments, isError: isErrorEnrollment } = useQuery({
refetchOnWindowFocus: false,
Expand Down
4 changes: 3 additions & 1 deletion apps/container/src/components/ReviewDialog/ReviewDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@click="showDialog = false"
variant="tonal"
icon="mdi-window-close"
aria-label="Fechar"
/>
</div>
<v-container class="pa-0 my-2" style="max-width: none">
Expand Down Expand Up @@ -83,7 +84,7 @@

<script setup lang="ts">
import { PropType, computed, ref } from 'vue';
import { Comments, Enrollment, Enrollments } from 'services';
import { Comments, Enrollments } from 'services';
import { PaperCard } from '@/components/PaperCard';
import { conceptsColor } from 'utils';
Expand All @@ -92,6 +93,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query';
import { ElMessage } from 'element-plus';
import { FeedbackAlert } from '@/components/FeedbackAlert';
import { watch } from 'vue';
import type { Enrollment } from 'types';
const selectedSubject = ref<string>('Todas as matérias');
const props = defineProps({
Expand Down
13 changes: 7 additions & 6 deletions apps/container/src/components/SearchBar/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ import debounce from 'lodash.debounce';
import { Reviews } from 'services';
import { computed, onMounted, ref, watch } from 'vue';
import { FeedbackAlert } from '@/components/FeedbackAlert';
import router from '@/router';
import { SearchTeacherItem, SearchSubjectItem } from 'types';
import type { SearchTeacherItem, SearchSubjectItem } from 'types';
import { useRouter } from 'vue-router';
const router = useRouter();
const searchTerm = ref('');
Expand Down Expand Up @@ -148,14 +150,13 @@ const search = (e: InputEvent) => {
const mapSearchResults = (
type: string,
results?: SearchTeacherItem[] | SearchSubjectItem[],
) => {
return results?.map((result: SearchTeacherItem | SearchSubjectItem) => ({
results?: (SearchTeacherItem | SearchSubjectItem)[],
) =>
results?.map((result) => ({
name: result.name,
id: result._id,
type: type,
})) || [];
};
const processedResults = computed(() => [
...mapSearchResults('teacher', searchResultsTeachers.value?.data.data),
Expand Down
24 changes: 10 additions & 14 deletions apps/container/src/layouts/AppBar/AppBar.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { render, screen, userEvent, waitFor } from '@/test-utils';
import { AppBar } from '.';
import { user as userMock } from '@/mocks/users';
import { user as mockedUser } from '@/mocks/users';
import { useAuth } from '@/stores/useAuth';
import { HttpResponse, http } from 'msw';
import { server } from '@/mocks/server';

describe('<AppBar />', () => {
const originalUseAuthValue = useAuth.getState();
beforeEach(() => {
useAuth.setState({
...originalUseAuthValue,
token: 'token',
user: userMock,
user: mockedUser,
});
});
afterEach(() => {
Expand All @@ -38,23 +36,21 @@ describe('<AppBar />', () => {
);
expect(await screen.findByText(/sair/i)).toBeInTheDocument();
expect(
await screen.findByText(userMock.email.replace(/(.*)@.*/, '$1')),
await screen.findByText(mockedUser.email.replace(/(.*)@.*/, '$1')),
).toBeInTheDocument();
expect(
screen.getByText(
new RegExp(`^${userMock.email[0]}${userMock.email[1]}$`, 'i'),
new RegExp(`^${mockedUser.email[0]}${mockedUser.email[1]}$`, 'i'),
),
).toBeInTheDocument();
});
test('render user initials if user email has two names', async () => {
server.use(
http.get(/.*\/users\/info/, () =>
HttpResponse.json({
...userMock,
email: '[email protected]',
}),
),
);
useAuth.setState({
user: {
...mockedUser,
email: '[email protected]',
},
});
const user = userEvent.setup();

render(AppBar);
Expand Down
22 changes: 3 additions & 19 deletions apps/container/src/layouts/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@
}
</style>
<script setup lang="ts">
import { useQuery } from '@tanstack/vue-query';
import { Users } from 'services';
import dayjs from 'dayjs';
import { computed, ref } from 'vue';
import { useAuth } from '@/stores/useAuth';
import { useAliasInitials } from '@/utils/composables/aliasInitials';
const props = defineProps({
showAppBar: {
Expand All @@ -131,31 +130,16 @@ const props = defineProps({
},
});
const { logOut } = useAuth();
const { logOut, user } = useAuth();
const handleLogout = () => {
logOut.value();
};
const { data: user } = useQuery({
queryKey: ['users', 'info'],
queryFn: Users.info,
select: (response) => response.data,
});
const drawer = ref(true);
const userLogin = computed(
() => user.value?.email.replace('@aluno.ufabc.edu.br', ''),
);
const userInitials = computed(() => {
if (userLogin.value) {
const names = userLogin.value.split('.');
if (names.length === 1) {
return userLogin.value[0] + userLogin.value[1];
}
return names[0][0] + names[1][0];
}
return '';
});
const userInitials = useAliasInitials();
const internalNavigationItems = [
{
Expand Down
4 changes: 3 additions & 1 deletion apps/container/src/mocks/enrollments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const enrollments = [
import { Enrollment } from 'types';

export const enrollments: Enrollment[] = [
{
_id: '5f4db7d2a62affac151a1f4e',
conceito: 'B',
Expand Down
43 changes: 42 additions & 1 deletion apps/container/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
import { http, HttpResponse } from 'msw';
import { user } from './users';
import { user, userGrades } from './users';
import { enrollments } from './enrollments';
import {
usage,
courses,
classes,
overview,
courseNames,
classesPage1,
subjects,
grades,
} from './stats';
import { historiesGraduations } from './performance';

const baseUrl = 'https://api.ufabcnext.com/v1';

export const handlers = [
http.get(`${baseUrl}/users/info`, () => HttpResponse.json(user)),
http.get(`${baseUrl}/enrollments`, () => HttpResponse.json(enrollments)),
http.get(`${baseUrl}/stats/usage`, () => HttpResponse.json(usage)),
http.get(`${baseUrl}/stats/disciplinas/courses`, () =>
HttpResponse.json(courses),
),
http.get(`${baseUrl}/stats/disciplinas`, ({ request }) => {
const url = new URL(request.url);
if (url.searchParams.get('page') === '1') {
return HttpResponse.json(classesPage1);
}
return HttpResponse.json(classes);
}),
http.get(`${baseUrl}/stats/disciplinas/overview`, () =>
HttpResponse.json(overview),
),
http.get(`${baseUrl}/stats/disciplinas/disciplines`, () =>
HttpResponse.json(subjects),
),
http.get(`${baseUrl}/histories/courses`, () =>
HttpResponse.json(courseNames),
),
http.get(`${baseUrl}/users/me/grades`, () => HttpResponse.json(userGrades)),
http.get(`${baseUrl}/stats/grades`, () => HttpResponse.json(grades)),
http.get(`${baseUrl}/historiesGraduations`, () =>
HttpResponse.json(historiesGraduations),
),
http.delete(`${baseUrl}/users/me/delete`, () => HttpResponse.json({})),
http.post(`${baseUrl}/account/confirm`, () => HttpResponse.json({})),
http.post(`${baseUrl}/users/me/recover`, () => HttpResponse.json({})),
http.post(`${baseUrl}/users/me/resend`, () => HttpResponse.json({})),
http.put(`${baseUrl}/users/complete`, () => HttpResponse.json({})),
];
Loading

0 comments on commit 7bd654f

Please sign in to comment.