-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Créer la page de téléchargement des résultats de session (P…
- Loading branch information
Showing
9 changed files
with
195 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import PixBackgroundHeader from '@1024pix/pix-ui/components/pix-background-header'; | ||
import PixBlock from '@1024pix/pix-ui/components/pix-block'; | ||
import PixButton from '@1024pix/pix-ui/components/pix-button'; | ||
import PixMessage from '@1024pix/pix-ui/components/pix-message'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { t } from 'ember-intl'; | ||
import ENV from 'mon-pix/config/environment'; | ||
import PixWindow from 'mon-pix/utils/pix-window'; | ||
|
||
export default class DownloadSessionResults extends Component { | ||
@tracked showErrorMessage = false; | ||
@service requestManager; | ||
|
||
@action | ||
async downloadSessionResults(event) { | ||
event.preventDefault(); | ||
this.showErrorMessage = false; | ||
|
||
try { | ||
const token = decodeURIComponent(PixWindow.getLocationHash().slice(1)); | ||
await this.requestManager.request({ | ||
url: `${ENV.APP.API_HOST}/api/sessions/download-all-results`, | ||
method: 'POST', | ||
body: JSON.stringify({ token }), | ||
}); | ||
} catch { | ||
this.showErrorMessage = true; | ||
} | ||
} | ||
|
||
<template> | ||
<PixBackgroundHeader id="main"> | ||
<PixBlock class="download-session-results"> | ||
<form class="download-session-results__form" autocomplete="off"> | ||
|
||
<h1 class="form__title"> | ||
{{t "pages.download-session-results.title"}} | ||
</h1> | ||
|
||
<PixButton @type="submit" @triggerAction={{this.downloadSessionResults}} @size="large" class="form__actions"> | ||
{{t "pages.download-session-results.button.label"}} | ||
</PixButton> | ||
|
||
{{#if this.showErrorMessage}} | ||
<PixMessage @type="error" class="form__error"> | ||
{{t "pages.download-session-results.errors.expiration"}} | ||
</PixMessage> | ||
{{/if}} | ||
</form> | ||
</PixBlock> | ||
</PixBackgroundHeader> | ||
</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
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,3 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class DownloadSessionResults extends Route {} |
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,29 @@ | ||
.download-session-results { | ||
max-width: max-content; | ||
margin: 0 auto 32px; | ||
padding: 48px 24px; | ||
|
||
@include device-is('tablet') { | ||
padding: 48px 60px; | ||
} | ||
|
||
&__form { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
.form__title { | ||
@extend %pix-title-m; | ||
|
||
margin-bottom: var(--pix-spacing-4x); | ||
} | ||
|
||
.form__actions { | ||
margin-top: var(--pix-spacing-6x); | ||
} | ||
|
||
.form__error { | ||
margin-top: var(--pix-spacing-4x); | ||
} | ||
} | ||
} |
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,11 @@ | ||
{{page-title (t "pages.download-session-results.title")}} | ||
|
||
<header role="banner"> | ||
<NavbarHeader /> | ||
</header> | ||
|
||
<main role="main"> | ||
<DownloadSessionResults /> | ||
</main> | ||
|
||
<Footer /> |
69 changes: 69 additions & 0 deletions
69
mon-pix/tests/integration/components/download-session-results-test.gjs
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,69 @@ | ||
import { render } from '@1024pix/ember-testing-library'; | ||
import { click } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { t } from 'ember-intl/test-support'; | ||
import DownloadSessionResults from 'mon-pix/components/download-session-results'; | ||
import ENV from 'mon-pix/config/environment'; | ||
import PixWindow from 'mon-pix/utils/pix-window'; | ||
import { module, test } from 'qunit'; | ||
import sinon from 'sinon'; | ||
|
||
import setupIntlRenderingTest from '../../helpers/setup-intl-rendering'; | ||
|
||
module('Integration | Component | download-session-results', function (hooks) { | ||
setupIntlRenderingTest(hooks); | ||
|
||
let requestManagerService; | ||
|
||
hooks.beforeEach(function () { | ||
requestManagerService = this.owner.lookup('service:requestManager'); | ||
sinon.stub(requestManagerService, 'request'); | ||
}); | ||
|
||
hooks.afterEach(function () { | ||
sinon.restore(); | ||
}); | ||
|
||
test('should display component', async function (assert) { | ||
// given | ||
// when | ||
const screen = await render(<template><DownloadSessionResults /></template>); | ||
|
||
// then | ||
assert.dom(screen.getByRole('heading', { name: t('pages.download-session-results.title'), level: 1 })).exists(); | ||
assert.dom(screen.getByRole('button', { name: t('pages.download-session-results.button.label') })).exists(); | ||
}); | ||
|
||
test('should display the expiration error message', async function (assert) { | ||
// given | ||
requestManagerService.request.rejects({ status: 500 }); | ||
|
||
// when | ||
const screen = await render(hbs`<DownloadSessionResults />`); | ||
const downloadButton = screen.getByRole('button', { name: t('pages.download-session-results.button.label') }); | ||
await click(downloadButton); | ||
|
||
// then | ||
assert.dom(screen.getByText(t('pages.download-session-results.errors.expiration'))).exists(); | ||
}); | ||
|
||
test('should trigger the download', async function (assert) { | ||
// given | ||
requestManagerService.request.resolves({ status: 200 }); | ||
const tokenHash = 'mytoken'; | ||
sinon.stub(PixWindow, 'getLocationHash').returns(`#${tokenHash}`); | ||
|
||
// when | ||
const screen = await render(hbs`<DownloadSessionResults />`); | ||
const downloadButton = screen.getByRole('button', { name: t('pages.download-session-results.button.label') }); | ||
await click(downloadButton); | ||
|
||
// then | ||
sinon.assert.calledWithExactly(requestManagerService.request, { | ||
url: `${ENV.APP.API_HOST}/api/sessions/download-all-results`, | ||
method: 'POST', | ||
body: `{"token":"${tokenHash}"}`, | ||
}); | ||
assert.ok(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
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