-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from JHWelch/cleanup
Cleanup
- Loading branch information
Showing
4 changed files
with
205 additions
and
44 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,26 @@ | ||
<script setup lang="ts"> | ||
withDefaults(defineProps<{ | ||
title: string | ||
value: string | ||
style?: 'small' | 'large' | ||
}>(), { | ||
style: 'small', | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div | ||
:class="{ | ||
'flex flex-col items-center w-full p-3 rounded-md bg-brat-300': true, | ||
'col-span-2': style === 'large', | ||
}" | ||
> | ||
<div class="font-semibold"> | ||
{{ title }} | ||
</div> | ||
|
||
<div :class="{ 'text-6xl': style === 'small' }"> | ||
{{ value }} | ||
</div> | ||
</div> | ||
</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,55 @@ | ||
/** @vitest-environment jsdom */ | ||
|
||
import { expect, it } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import Info from '@components/admin/Info.vue' | ||
|
||
it('shows the input', () => { | ||
const wrapper = mount(Info, { | ||
props: { | ||
title: 'Title', | ||
value: 'Value', | ||
}, | ||
}) | ||
|
||
expect(wrapper.text()).toContain('Title') | ||
expect(wrapper.text()).toContain('Value') | ||
}) | ||
|
||
it('defaults to small style', () => { | ||
const wrapper = mount(Info, { | ||
props: { | ||
title: 'Title', | ||
value: 'Value', | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.text-6xl').exists()).toBe(true) | ||
expect(wrapper.find('.col-span-2').exists()).toBe(false) | ||
}) | ||
|
||
it('can specify small style', () => { | ||
const wrapper = mount(Info, { | ||
props: { | ||
title: 'Title', | ||
value: 'Value', | ||
style: 'small', | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.text-6xl').exists()).toBe(true) | ||
expect(wrapper.find('.col-span-2').exists()).toBe(false) | ||
}) | ||
|
||
it('can be large', () => { | ||
const wrapper = mount(Info, { | ||
props: { | ||
title: 'Title', | ||
value: 'Value', | ||
style: 'large', | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('.text-6xl').exists()).toBe(false) | ||
expect(wrapper.find('.col-span-2').exists()).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** @vitest-environment jsdom */ | ||
|
||
import { beforeEach, describe, expect, it } from 'vitest' | ||
import { mount, VueWrapper } from '@vue/test-utils' | ||
import AdminPage from '@pages/AdminPage.vue' | ||
|
||
let wrapper: VueWrapper | ||
|
||
describe('unauthed page', () => { | ||
it('shows password form', () => { | ||
wrapper = mount(AdminPage) | ||
|
||
expect(wrapper.byTestId('unlock-button').exists()).toBe(true) | ||
expect(wrapper.byTestId('input-password').exists()).toBe(true) | ||
}) | ||
|
||
it('does not show admin content', () => { | ||
wrapper = mount(AdminPage) | ||
|
||
expect(wrapper.text()).not.toContain('Sync Weeks') | ||
}) | ||
}) | ||
|
||
describe('authentication problems', () => { | ||
describe('401', () => { | ||
beforeEach(async () => { | ||
window.fetch.mockResponseOnce(JSON.stringify({ | ||
error: 'Something went wrong authenticating you', | ||
}), { | ||
status: 401, | ||
}) | ||
wrapper = mount(AdminPage) | ||
await wrapper.byTestId('input-password').setValue('password') | ||
await wrapper.byTestId('unlock-button').trigger('click') | ||
}) | ||
|
||
it('does not shows admin content', async () => { | ||
expect(wrapper.text()).not.toContain('Sync Weeks') | ||
expect(wrapper.text()).toContain('Something went wrong authenticating you') | ||
}) | ||
}) | ||
|
||
describe('403', () => { | ||
beforeEach(async () => { | ||
window.fetch.mockResponseOnce(JSON.stringify({ | ||
error: 'Password incorrect', | ||
}), { | ||
status: 403, | ||
}) | ||
wrapper = mount(AdminPage) | ||
await wrapper.byTestId('input-password').setValue('password') | ||
await wrapper.byTestId('unlock-button').trigger('click') | ||
}) | ||
|
||
it('does not shows admin content', async () => { | ||
expect(wrapper.text()).not.toContain('Sync Weeks') | ||
expect(wrapper.text()).toContain('Password incorrect') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('correct password - logged in', () => { | ||
beforeEach(async () => { | ||
window.fetch.mockResponseOnce(JSON.stringify({ | ||
updatedWeeks: 15, | ||
previousLastUpdated: '2021-01-01T00:00:00.000Z', | ||
newLastUpdated: '2021-01-01T00:00:00.000Z', | ||
tmdbMoviesSynced: Array.from({ length: 32 }, () => {}), | ||
})) | ||
|
||
wrapper = mount(AdminPage) | ||
await wrapper.byTestId('input-password').setValue('password') | ||
await wrapper.byTestId('unlock-button').trigger('click') | ||
}) | ||
|
||
it('shows admin content', async () => { | ||
expect(wrapper.text()).toContain('Sync Weeks') | ||
}) | ||
|
||
it('shows updated weeks metadata', async () => { | ||
expect(wrapper.text()).toContain('15') | ||
expect(wrapper.text()) | ||
.toContain(new Date('2021-01-01T00:00:00.000Z').toLocaleString()) | ||
expect(wrapper.text()) | ||
.toContain(new Date('2021-01-01T00:00:00.000Z').toLocaleString()) | ||
expect(wrapper.text()).toContain('32') | ||
}) | ||
}) |