fix duplicated logout modal (fix )

This commit is contained in:
Pig Fang 2021-08-22 10:50:58 +08:00
parent e8ec0c4c0d
commit 79ec6e206a
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
4 changed files with 2 additions and 58 deletions
resources
assets
src/scripts
tests/scripts
views

View File

@ -1,4 +1,3 @@
import './i18n'
import { getExtraData } from './extra' import { getExtraData } from './extra'
export function scrollHander() { export function scrollHander() {
@ -15,19 +14,6 @@ export function scrollHander() {
} }
} }
export async function logout() {
await fetch(`${blessing.base_url}/auth/logout`, {
method: 'POST',
credentials: 'same-origin',
headers: {
'X-CSRF-TOKEN': document.querySelector<HTMLMetaElement>(
'meta[name="csrf-token"]',
)!.content,
},
})
window.location.href = blessing.base_url
}
/* istanbul ignore next */ /* istanbul ignore next */
if (process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
const { transparent_navbar } = getExtraData() as { const { transparent_navbar } = getExtraData() as {
@ -37,7 +23,3 @@ if (process.env.NODE_ENV !== 'test') {
window.addEventListener('load', scrollHander) window.addEventListener('load', scrollHander)
} }
} }
/* istanbul ignore next */
document
.querySelector<HTMLButtonElement>('#btn-logout')
?.addEventListener('click', logout)

View File

@ -1,22 +1,4 @@
import { scrollHander, logout } from '@/scripts/homePage' import { scrollHander } from '@/scripts/homePage'
test('logout', async () => {
const meta = document.createElement('meta')
meta.name = 'csrf-token'
meta.content = 'token'
document.head.appendChild(meta)
window.fetch = jest.fn()
await logout()
expect(window.fetch).toBeCalledWith('/auth/logout', {
method: 'POST',
credentials: 'same-origin',
headers: {
'X-CSRF-TOKEN': 'token',
},
})
})
describe('scroll handler', () => { describe('scroll handler', () => {
beforeAll(() => { beforeAll(() => {

View File

@ -128,26 +128,6 @@
</div> </div>
{% endif %} {% endif %}
<div id="modal-logout" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ trans('general.notice') }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>{{ trans('front-end.general.confirmLogout') }}</p>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-dismiss="modal">{{ trans('general.cancel') }}</button>
<button class="btn btn-primary" id="btn-logout">{{ trans('front-end.general.confirm') }}</button>
</div>
</div>
</div>
</div>
<script type="application/json" id="blessing-extra"> <script type="application/json" id="blessing-extra">
{{ {transparent_navbar: transparent_navbar}|json_encode|raw }} {{ {transparent_navbar: transparent_navbar}|json_encode|raw }}
</script> </script>

View File

@ -31,7 +31,7 @@
{% endif %} {% endif %}
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
{% endif %} {% endif %}
<a class="dropdown-item" href="#" id="logout-button" data-toggle="modal" data-target="#modal-logout"> <a class="dropdown-item" href="#" id="logout-button">
{{ trans('general.logout') }} {{ trans('general.logout') }}
</a> </a>
</div> </div>