-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* polish and front end test. * Rework post to use ajax and finish api testing, pending repo tests. * finish repo testing.
- Loading branch information
1 parent
6c4fcbb
commit ec0e11d
Showing
13 changed files
with
471 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"Loginless", | ||
"nanostores", | ||
"pydantic", | ||
"sqlalchemy", | ||
"USWDS", | ||
"Vuelidate" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<script setup> | ||
import { useStore } from '@nanostores/vue' | ||
import { profile} from '../stores/user' | ||
import { computed } from "vue" | ||
import USWDSAlert from './USWDSAlert.vue' | ||
const user = useStore(profile) | ||
const isAdminUser = computed(() => user.value.roles.includes('Admin')) | ||
Check failure on line 8 in training-front-end/src/components/AdminReportDownload.vue GitHub Actions / unit-tests-and-lintUnhandled error
Check failure on line 8 in training-front-end/src/components/AdminReportDownload.vue GitHub Actions / unit-tests-and-lintUnhandled error
|
||
const base_url = import.meta.env.PUBLIC_API_BASE_URL | ||
const gspc_report_url = `${base_url}/api/v1/gspc/download-gspc-completion-report` | ||
async function downloadGspcReport() { | ||
const response = await fetch( gspc_report_url, { | ||
method: 'POST', | ||
headers: { 'Authorization': `Bearer ${user.value.jwt}` }, | ||
}); | ||
if (response.ok) { | ||
const blob = await response.blob(); | ||
downloadBlobAsFile(blob, 'GspcCompletionReport.csv') | ||
} else { | ||
console.error('Failed to download report', response.statusText); | ||
} | ||
} | ||
async function downloadBlobAsFile(blob, filename){ | ||
const url = window.URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.style.display = 'none'; | ||
a.href = url; | ||
a.download = filename; | ||
document.body.appendChild(a); | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
} | ||
</script> | ||
<template> | ||
<section | ||
v-if="isAdminUser" | ||
class="usa-prose" | ||
> | ||
<h2>Download GSPC Report</h2> | ||
<p> | ||
We’ve created a report for you in CSV format. You can open it in the spreadsheet | ||
application of your choice (e.g. Microsoft Excel, Google Sheets, Apple Numbers). | ||
</p> | ||
<button | ||
class="usa-button" | ||
@click="downloadGspcReport" | ||
> | ||
Download Report | ||
</button> | ||
</section> | ||
<section v-else> | ||
<USWDSAlert | ||
status="error" | ||
class="usa-alert" | ||
heading="You are not authorized to receive reports." | ||
> | ||
Your email account is not authorized to access admin reports. If you should be authorized, you can | ||
<a | ||
class="usa-link" | ||
href="mailto:[email protected]" | ||
> | ||
contact the GSA SmartPay team | ||
</a> to gain access. | ||
</USWDSAlert> | ||
</section> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script setup> | ||
import { ref, onErrorCaptured } from "vue" | ||
import AdminReportDownload from "./AdminReportDownload.vue"; | ||
import USWDSAlert from './USWDSAlert.vue' | ||
const error = ref() | ||
function setError(event){ | ||
error.value = event | ||
} | ||
onErrorCaptured((err) => { | ||
if (err.message == 'Unauthorized'){ | ||
err = { | ||
name: 'You are not authorized to receive admin reports.', | ||
message: 'Your email account is not authorized to access admin reports. If you should be authorized, you can <a class="usa-link" href="mailto:[email protected]">contact the GSA SmartPay® team</a> to gain access.' | ||
} | ||
setError(err) | ||
} | ||
return false | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="padding-top-4 padding-bottom-4 grid-container"> | ||
<div class="grid-row"> | ||
<div class="tablet:grid-col-12"> | ||
<USWDSAlert | ||
v-if="error" | ||
class="tablet:grid-col-12 margin-bottom-4" | ||
status="error" | ||
:heading="error.name" | ||
> | ||
<!-- eslint-disable-next-line vue/no-v-html --> | ||
<span v-html="error.message" /> | ||
</USWDSAlert> | ||
<AdminReportDownload /> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
28 changes: 28 additions & 0 deletions
28
training-front-end/src/components/__tests__/AdminReportIndex.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { describe, it, expect, afterEach, vi } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { cleanStores } from 'nanostores' | ||
import { profile } from '../../stores/user.js' | ||
|
||
import AdminReportIndex from '../AdminReportIndex.vue' | ||
|
||
|
||
describe("AdminReportIndex", async () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
cleanStores() | ||
profile.set({}) | ||
}) | ||
|
||
it('Shows download screen', async () => { | ||
profile.set({name:"Amelia Sedley", jwt:"some-token-value", roles:["Admin"]}) | ||
const wrapper = await mount(AdminReportIndex) | ||
expect(wrapper.text()).toContain('Download GSPC Report') | ||
}) | ||
|
||
it('shows error when user is know but does not have correct roles', async () => { | ||
profile.set({name:"Amelia Sedley", jwt:"some-token-value", roles:["SomeOtherRole"]}) | ||
const wrapper = await mount(AdminReportIndex) | ||
expect(wrapper.text()).toContain('You are not authorized') | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
import BaseLayout from '@layouts/BaseLayout.astro'; | ||
import HeroTraining from '@components/HeroTraining.astro'; | ||
import AdminReportIndex from '@components/AdminReportIndex.vue'; | ||
import AuthRequired from '@components/AuthRequired.vue'; | ||
const pageTitle = "Reports"; | ||
--- | ||
<BaseLayout title={pageTitle} description="Admin Reports"> | ||
<HeroTraining background_class='bg_smartpay_cool_grey'> | ||
Admin Reports | ||
</HeroTraining> | ||
<AuthRequired client:only> | ||
<AdminReportIndex client:only /> | ||
</AuthRequired> | ||
</BaseLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import datetime | ||
from pydantic import BaseModel, ConfigDict | ||
from training.schemas.user import UserBase | ||
|
||
|
||
class UserQuizCompletionReportData(UserBase): | ||
agency: str | ||
bureau: str | None = None | ||
quiz: str | ||
completion_date: datetime | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
||
class GspcCompletionReportData(BaseModel): | ||
invitedEmail: str | None = None | ||
registeredEmail: str | None = None | ||
username: str | None = None | ||
agency: str | None = None | ||
bureau: str | None = None | ||
passed: bool | None = None | ||
completionDate: datetime | None = None | ||
model_config = ConfigDict(from_attributes=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.