diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cc8846e..8fb196fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,8 @@ jobs: with: path: ./package.json + - uses: pnpm/action-setup@v4 + - name: Cache PNPM modules uses: actions/cache@v4 id: cache-modules @@ -43,13 +45,11 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: ${{ runner.os }}-node- - - uses: pnpm/action-setup@v4 - - uses: actions/setup-node@v4 with: # use the version found in `.nvmrc` node-version-file: '.nvmrc' - cache: 'pnpm' + # cache: 'pnpm' - name: Install `node_modules` if: steps.cache-modules.outputs.cache-hit != 'true' diff --git a/components/blocks/ResendConfirmationBar/ResendConfirmationBar.vue b/components/blocks/ResendConfirmationBar/ResendConfirmationBar.vue index beebe576..4dc4d029 100644 --- a/components/blocks/ResendConfirmationBar/ResendConfirmationBar.vue +++ b/components/blocks/ResendConfirmationBar/ResendConfirmationBar.vue @@ -1,6 +1,8 @@ diff --git a/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts b/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts index 8bdad174..8721d5f0 100644 --- a/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts +++ b/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts @@ -1,21 +1,12 @@ -import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime' +import { mountSuspended } from '@nuxt/test-utils/runtime' import { getByTestId } from 'root/testUtils' import ForgotPasswordCard from './ForgotPasswordCard.vue' -import type { RecoverAccountRequest } from 'lib/api/data-contracts' - -mockNuxtImport('useRecoverAccount', () => { - return async ( - _requestData: RecoverAccountRequest, - opts: optionalParameters = {}, - ) => { - const { onOkay } = opts - if (onOkay) { - await onOkay() - } - } -}) -afterAll(() => { +const mockSuccessAccountRecoverCreate = vi.fn(() => + Promise.resolve({ ok: true }), +) + +afterEach(() => { vi.restoreAllMocks() }) @@ -52,6 +43,14 @@ describe('', () => { const username = 'strongbad' const emailAddress = `strongbad@homestarrunner.com` + beforeEach(() => { + vi.mock('lib/api/Account', () => ({ + Account: function Account() { + this.recoverCreate = mockSuccessAccountRecoverCreate + }, + })) + }) + it('should emit the close event', async () => { const wrapper = await mountSuspended(ForgotPasswordCard) @@ -63,6 +62,7 @@ describe('', () => { await getByTestId(wrapper, 'reset-password-button').trigger('click') + expect(mockSuccessAccountRecoverCreate).toHaveBeenCalled() expect(wrapper.emitted().close).toBeTruthy() }) }) diff --git a/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.vue b/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.vue index b4d07bd3..55377900 100644 --- a/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.vue +++ b/components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.vue @@ -7,6 +7,8 @@ import CardBody from 'elements/cards/CardBody/CardBody.vue' import CardHeader from 'elements/cards/CardHeader/CardHeader.vue' import BaseInput from 'elements/inputs/BaseInput/BaseInput.vue' import { isEmailValid, isUsernameValid } from 'lib/form_helpers' +import { useModalAlert } from '#imports' +import { useRecoverAccount } from '~/composables/api' interface ForgotPasswordCardPops { modal?: boolean @@ -21,7 +23,7 @@ const emit = defineEmits<{ (event: 'close' | 'cancelClick'): void }>() -const props = withDefaults(defineProps(), { +withDefaults(defineProps(), { modal: false, }) @@ -76,7 +78,7 @@ function resetPassword() {
Forgot Password
diff --git a/components/blocks/cards/LogInCard/LogInCard.test.ts b/components/blocks/cards/LogInCard/LogInCard.test.ts index 43cfba74..e4fd859c 100644 --- a/components/blocks/cards/LogInCard/LogInCard.test.ts +++ b/components/blocks/cards/LogInCard/LogInCard.test.ts @@ -1,10 +1,10 @@ import { mountSuspended } from '@nuxt/test-utils/runtime' -import { getByTestId, getHTMLElement } from 'root/testUtils' +import { getById, getByTestId, getHTMLElement } from 'root/testUtils' import LogInCard from './LogInCard.vue' import * as apiComposables from 'composables/api' const token = 'jwt-token' -const mockSuccessUsersLoginCreate = vi.fn(() => +const mockSuccessAccountLoginCreate = vi.fn(() => Promise.resolve({ data: { token }, ok: true }), ) const mockSuccessUsersMeList = vi.fn(() => @@ -20,9 +20,13 @@ afterEach(() => { describe('', () => { beforeEach(() => { + vi.mock('lib/api/Account', () => ({ + Account: function Account() { + this.loginCreate = mockSuccessAccountLoginCreate + }, + })) vi.mock('lib/api/Users', () => ({ Users: function Users() { - this.usersLoginCreate = mockSuccessUsersLoginCreate this.usersMeList = mockSuccessUsersMeList }, })) @@ -46,8 +50,7 @@ describe('', () => { }) }) - // TODO: skip this for now - describe.skip('when enter key is released on the password input field', () => { + describe('when enter key is released on the password input field', () => { it('emits the close event', async () => { const wrapper = await mountSuspended(LogInCard) @@ -57,8 +60,7 @@ describe('', () => { }) }) - // TODO: skip this for now - describe.skip('when the login button is clicked', () => { + describe('when the login button is clicked', () => { const emailAddress = 'strongbad@homestarrunner.com' const password = 'homestarsux' @@ -66,7 +68,7 @@ describe('', () => { const wrapper = await mountSuspended(LogInCard) const emailInput = getByTestId(wrapper, 'email-input') - const passwordInput = getByTestId(wrapper, 'password-input') + const passwordInput = getById(wrapper, 'password') await emailInput.setValue(emailAddress) await passwordInput.setValue(password) @@ -80,7 +82,7 @@ describe('', () => { const wrapper = await mountSuspended(LogInCard) const emailInput = getByTestId(wrapper, 'email-input') - const passwordInput = getByTestId(wrapper, 'password-input') + const passwordInput = getById(wrapper, 'password') await emailInput.setValue(emailAddress) await passwordInput.setValue(password) @@ -99,14 +101,13 @@ describe('', () => { expect(passwordInputElement.value).toBe('') }) - // this test is still failing it('calls the api', async () => { const useLoginUserSpy = vi.spyOn(apiComposables, 'useLoginUser') const wrapper = await mountSuspended(LogInCard) const emailInput = getByTestId(wrapper, 'email-input') - const passwordInput = getByTestId(wrapper, 'password-input') + const passwordInput = getById(wrapper, 'password') await emailInput.setValue(emailAddress) await passwordInput.setValue(password) @@ -114,6 +115,7 @@ describe('', () => { await getByTestId(wrapper, 'login-button').trigger('click') expect(useLoginUserSpy).toBeCalledTimes(1) + expect(mockSuccessAccountLoginCreate).toBeCalledTimes(1) }) }) diff --git a/components/blocks/cards/LogInCard/LogInCard.vue b/components/blocks/cards/LogInCard/LogInCard.vue index 3878bebc..d40af3d8 100644 --- a/components/blocks/cards/LogInCard/LogInCard.vue +++ b/components/blocks/cards/LogInCard/LogInCard.vue @@ -8,6 +8,7 @@ import CardBody from 'elements/cards/CardBody/CardBody.vue' import CardHeader from 'elements/cards/CardHeader/CardHeader.vue' import Card from 'elements/cards/Card/Card.vue' import HideShowPassword from 'elements/buttons/HideShowPassword/HideShowPassword.vue' +import { useLoginUser } from '~/composables/api' interface LogInCardProps { modal?: boolean @@ -23,7 +24,7 @@ const emit = defineEmits<{ (event: 'close' | 'forgotPasswordClick' | 'signUpClick'): void }>() -const props = withDefaults(defineProps(), { +withDefaults(defineProps(), { modal: false, }) @@ -51,6 +52,7 @@ async function login() { state.email.value = '' state.password.value = '' state.showPassword.value = false + emit('close') }, }, ) @@ -72,7 +74,7 @@ async function login() { diff --git a/components/blocks/cards/SignUpCard/SignUpCard.test.ts b/components/blocks/cards/SignUpCard/SignUpCard.test.ts index 5eee1b79..ba9cd4b1 100644 --- a/components/blocks/cards/SignUpCard/SignUpCard.test.ts +++ b/components/blocks/cards/SignUpCard/SignUpCard.test.ts @@ -1,6 +1,7 @@ import { mountSuspended } from '@nuxt/test-utils/runtime' -import { getByTestId, getHTMLElement } from 'root/testUtils' +import { getByQuery, getByTestId, getHTMLElement } from 'root/testUtils' import SignUpCard from './SignUpCard.vue' +import { useRuntimeConfig } from '#imports' afterEach(() => { fetchMock.resetMocks() @@ -24,16 +25,15 @@ describe('', () => { }) }) - // TODO: Update this test once the inputs can be controlled together - describe.skip('when the hide/show button is clicked', () => { + describe('when the hide/show button is clicked', () => { it('changes the password input type to be text', async () => { const wrapper = await mountSuspended(SignUpCard) const passwordInputElement = getHTMLElement( - getByTestId(wrapper, 'password-input'), + getByQuery(wrapper, '[data-testid="password-input"] #password'), ) as HTMLInputElement const passwordConfirmInputElement = getHTMLElement( - getByTestId(wrapper, 'password-confirm-input'), + getByQuery(wrapper, '[data-testid="password-confirm-input"] #password'), ) as HTMLInputElement expect(passwordInputElement.type).toBe('password') diff --git a/components/blocks/cards/SignUpCard/SignUpCard.vue b/components/blocks/cards/SignUpCard/SignUpCard.vue index 1badfbf8..5b2b0649 100644 --- a/components/blocks/cards/SignUpCard/SignUpCard.vue +++ b/components/blocks/cards/SignUpCard/SignUpCard.vue @@ -15,6 +15,7 @@ import CloseButton from 'elements/buttons/CloseButton/CloseButton.vue' import Card from 'elements/cards/Card/Card.vue' import CardHeader from 'elements/cards/CardHeader/CardHeader.vue' import CardBody from 'elements/cards/CardBody/CardBody.vue' +import { useLoginUser, useRegisterUser } from '~/composables/api' interface SignUpCardProps { modal?: boolean @@ -31,7 +32,7 @@ const emit = defineEmits<{ (event: 'close' | 'logInClick' | 'signUpClick'): void }>() -const props = withDefaults(defineProps(), { +withDefaults(defineProps(), { modal: false, }) @@ -124,7 +125,7 @@ function validatePasswordInputs() { diff --git a/components/blocks/nav/SiteNavbar/SiteNavbar.test.ts b/components/blocks/nav/SiteNavbar/SiteNavbar.test.ts index 9ade2086..c468539a 100644 --- a/components/blocks/nav/SiteNavbar/SiteNavbar.test.ts +++ b/components/blocks/nav/SiteNavbar/SiteNavbar.test.ts @@ -2,6 +2,7 @@ import { mountSuspended } from '@nuxt/test-utils/runtime' import * as apiComposables from 'composables/api' import { getByTestId } from 'root/testUtils' import SiteNavbar from './SiteNavbar.vue' +import { useSessionToken } from '#imports' afterEach(() => { vi.restoreAllMocks() diff --git a/components/blocks/nav/SiteNavbar/SiteNavbar.vue b/components/blocks/nav/SiteNavbar/SiteNavbar.vue index 99f63503..4d0fd643 100644 --- a/components/blocks/nav/SiteNavbar/SiteNavbar.vue +++ b/components/blocks/nav/SiteNavbar/SiteNavbar.vue @@ -9,6 +9,8 @@ import LogInCard from 'blocks/cards/LogInCard/LogInCard.vue' import SignUpCard from 'blocks/cards/SignUpCard/SignUpCard.vue' import BaseModal from 'elements/modals/BaseModal/BaseModal.vue' import SearchBar from 'blocks/SearchBar/SearchBar.vue' +import { useSessionToken } from '#imports' +import { useLogoutUser } from '~/composables/api' interface NavbarState { mobileNavIsActive: boolean diff --git a/components/elements/buttons/Dropdown/Dropdown.vue b/components/elements/buttons/Dropdown/Dropdown.vue index 991f9a3b..84522298 100644 --- a/components/elements/buttons/Dropdown/Dropdown.vue +++ b/components/elements/buttons/Dropdown/Dropdown.vue @@ -1,5 +1,5 @@