Skip to content

Fix tests #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion web/site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pnpm test:unit

Run Playwright e2e tests in headless mode
```bash
cd sbc-apigw
pnpm test:e2e
```

Expand Down
2 changes: 1 addition & 1 deletion web/site/app/components/Sbc/Dashboard/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ watch(modalOpen, () => {
</template>
<span class="text-bcGovColor-midGray dark:text-[#d1d5db]">{{ content }}</span>
<template #footer>
<UForm :state="state" class="space-y-4" autocomplete="off" @submit="submitFn">
<UForm :state="state" class="space-y-4" autocomplete="off" @submit="submitFn()">
<UFormGroup label="Name" name="name">
<UInput v-model="state.name" />
</UFormGroup>
Expand Down
2 changes: 1 addition & 1 deletion web/site/app/components/Sbc/Docs/ProductCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function goToProduct () {
<template>
<li
data-testid="product-card"
class="flex h-[420px] w-[390px] cursor-pointer flex-col overflow-hidden rounded bg-white shadow-md transition-transform focus-within:-translate-y-1 focus-within:ring-2 focus-within:ring-bcGovGray-500 hover:-translate-y-1 hover:shadow-lg hover:ring-2 hover:ring-bcGovGray-500 dark:border dark:border-gray-300/50 dark:bg-bcGovColor-darkGray dark:focus-within:ring-1 dark:focus-within:ring-bcGovGray-100 dark:hover:ring-1 dark:hover:ring-bcGovGray-100"
class="flex h-[420px] w-[390px] cursor-pointer flex-col overflow-hidden rounded bg-white shadow-md transition-transform focus-within:-translate-y-1 focus-within:ring-2 focus-within:ring-bcGovBlue-350 hover:-translate-y-1 hover:shadow-lg hover:ring-2 hover:ring-bcGovBlue-350 dark:border dark:border-gray-300/50 dark:bg-bcGovColor-darkGray dark:focus-within:ring-1 dark:focus-within:ring-bcGovGray-100 dark:hover:ring-1 dark:hover:ring-bcGovGray-100"
@click="goToProduct"
>
<div class="relative flex h-[60px] items-center bg-bcGovBlue-350 px-4 py-3.5 font-semibold tracking-wide lg:px-7 dark:border-b dark:border-gray-300/50 dark:bg-bcGovColor-darkGray">
Expand Down
2 changes: 1 addition & 1 deletion web/site/app/components/Sbc/Docs/SideNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defineProps<{
}>()
</script>
<template>
<aside class="mx-2 min-w-48 max-w-min py-4">
<aside class="mx-2 min-w-48 max-w-min py-4" data-testid="docs-side-navigation">
<SbcDocsAccordianNavigation :nav-items="navItems" />
</aside>
</template>
8 changes: 2 additions & 6 deletions web/site/app/composables/docPageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ export function useDocPageData () {
// update data when locale or route changes
watch([locale, routeWithoutLocale], async () => {
await initDocPageData()
})
}, { immediate: true })

// return current page data table of contents
const tocLinks = computed<TocLink[]>(() => docPageData.value?.body?.toc?.links ?? [])

const currentDir = computed<string | undefined>(() => docPageData.value?._path)

onMounted(() => {
initDocPageData()
})

return { docPageData, tocLinks, currentDir, createPageHead }
return { docPageData, tocLinks, currentDir, createPageHead, initDocPageData }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from '@playwright/test'

test('test', async ({ page }) => {
test.skip('test', async ({ page }) => {
await page.goto('http://localhost:3467/en-CA')
await page.getByRole('link', { name: 'Dashboard' }).click()
const page1Promise = page.waitForEvent('popup')
Expand All @@ -9,9 +9,9 @@ test('test', async ({ page }) => {
await page1.getByLabel('Log in with Test with').click()
await page1.getByLabel('Email or username').click()
await page1.getByLabel('Email or username').press('CapsLock')
await page1.getByLabel('Email or username').fill('BCREG4000')
await page1.getByLabel('Email or username').fill('') // username
await page1.getByLabel('Password').click()
await page1.getByLabel('Password').fill('98940000')
await page1.getByLabel('Password').fill('') // password
await page1.getByLabel('Password').press('Tab')
await page1.getByRole('button', { name: 'Continue' }).click()
await page.goto('http://localhost:3467/en-CA')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@ test.describe('products page', () => {
await page.goto('/en-CA/products')
})

test('page contents', async ({ page }) => {
const h1 = await page.textContent('h1')
expect(h1).toBe('All Products')
await expect(page.getByTestId('product-card')).toHaveCount(7) // there should be 7 product cards
})

test('accessibility', async ({ page }) => {
await page
.getByText('All Products')
.first()
.click() // wait for page load before runnign a11y checks? fails without this

test.afterEach(async ({ page }) => {
const a11yResults = await new AxeBuilder({ page })
.exclude('#locale-select-dropdown') // headless ui dropdown fails the axe check
.analyze()

expect(a11yResults.violations).toEqual([])
})

test('page contents', async ({ page }) => {
const h1 = await page.textContent('h1')
expect(h1).toBe('All Products')
await expect(page.getByTestId('product-card')).toHaveCount(7) // there should be 7 product cards
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test'
import AxeBuilder from '@axe-core/playwright'

test.describe('dashboard page', () => {
test.describe.skip('dashboard page', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/en-CA/sbc/dashboard')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ test.describe('docs page', () => {
await page.goto('/en-CA/products/get-started')
})

test('page contents', async ({ page }) => {
const h1 = await page.textContent('h1')
expect(h1).toBe('Account Setup')
})

test('accessibility', async ({ page }) => {
await page
.getByText('Account Setup')
.first()
.click() // wait for page load before runnign a11y checks? fails without this

test.afterEach(async ({ page }) => {
const a11yResults = await new AxeBuilder({ page })
.exclude('#locale-select-dropdown') // headless ui dropdown fails the axe check
.analyze()

expect(a11yResults.violations).toEqual([])
})

test('page contents', async ({ page }) => {
const h1 = await page.textContent('h1')
expect(h1).toBe('Account Setup')
expect(page.getByTestId('docs-side-navigation')).toBeDefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ test.describe('home page', () => {
await page.goto('/en-CA')
})

test.afterEach(async ({ page }) => {
const a11yResults = await new AxeBuilder({ page })
.exclude('#locale-select-dropdown') // headless ui dropdown fails the axe check
.analyze()

expect(a11yResults.violations).toEqual([])
})

test('page contents', async ({ page }) => {
const h1 = await page.textContent('h1')
const p = await page.textContent('p')
Expand All @@ -14,12 +22,4 @@ test.describe('home page', () => {
expect(h1).toBe('BC Registries API Gateway')
expect(p).toBe('Welcome to the BC Registries API Gateway! Access API information for all BC Registries services here.')
})

test('accessibility', async ({ page }) => {
const a11yResults = await new AxeBuilder({ page })
.exclude('#locale-select-dropdown') // headless ui dropdown fails the axe check
.analyze()

expect(a11yResults.violations).toEqual([])
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test'
import AxeBuilder from '@axe-core/playwright'

test.describe('terms of use page', () => {
test.describe.skip('terms of use page', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/en-CA/sbc/tos')
})
Expand Down
2 changes: 1 addition & 1 deletion web/site/app/tests/setup/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '@vue/test-utils'
import { createI18n } from 'vue-i18n'
import en from '~/app/locales/en-CA'
import en from '~~/app/locales/en-CA'

export const mockedI18n = createI18n({
locale: 'en-CA',
Expand Down
45 changes: 45 additions & 0 deletions web/site/app/tests/unit/components/SbcDocsProductCard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, it, expect, vi } from 'vitest'
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import { SbcDocsProductCard } from '#components'
import { enI18n } from '~/tests/mocks/i18n'

const { navigateToMock } = vi.hoisted(() => ({ navigateToMock: vi.fn() }))
mockNuxtImport('navigateTo', () => navigateToMock)

describe('SbcDocsProductCard', () => {
const props = {
name: 'Test Product',
description: 'This is a test product',
badge: 'New',
bulletPoints: ['Feature 1', 'Feature 2'],
directory: 'test-product'
}

it('renders', async () => {
const wrapper = await mountSuspended(SbcDocsProductCard, {
props,
global: {
plugins: [enI18n]
}
})

expect(wrapper.find('[data-testid="product-card"]').exists()).toBe(true)
expect(wrapper.text()).toContain(props.name)
expect(wrapper.text()).toContain(props.description)
expect(wrapper.text()).toContain(props.badge)
expect(wrapper.text()).toContain(props.bulletPoints[0])
expect(wrapper.text()).toContain(props.bulletPoints[1])
})

it('navigates when clicked', async () => {
const wrapper = await mountSuspended(SbcDocsProductCard, {
props,
global: {
plugins: [enI18n]
}
})

await wrapper.trigger('click')
expect(navigateTo).toHaveBeenCalledWith('/en-CA/products/test-product/overview')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, it, expect } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { SbcDocsTableOfContents } from '#components'

describe('TableOfContents', () => {
const props = {
tocLinks: [
{ id: 'section-1', text: 'Section 1', children: [], depth: 1 },
{ id: 'section-2', text: 'Section 2', children: [{ id: 'section-2-1', text: 'Section 2.1', depth: 2 }], depth: 1 }
],
currentDir: '/docs',
activeTocId: 'section-1',
hideLabel: false
}

it('renders', async () => {
const wrapper = await mountSuspended(SbcDocsTableOfContents, {
props
})

expect(wrapper.find('nav[aria-label="table of contents"]').exists()).toBe(true)
expect(wrapper.text()).toContain('Table of Contents')
expect(wrapper.text()).toContain('Section 1')
expect(wrapper.text()).toContain('Section 2')
expect(wrapper.text()).toContain('Section 2.1')
})

it('highlights the active link', async () => {
const wrapper = await mountSuspended(SbcDocsTableOfContents, {
props
})

const activeLink = wrapper.find('.text-primary-500')
expect(activeLink.exists()).toBe(true)
expect(activeLink.text()).toBe('Section 1')
})
})
71 changes: 71 additions & 0 deletions web/site/app/tests/unit/composables/docPageData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mockNuxtImport } from '@nuxt/test-utils/runtime'
import { useDocPageData } from '#imports'

mockNuxtImport('useI18n', () => {
return () => {
return { locale: ref('en') }
}
})

mockNuxtImport('useRoute', () => {
return () => (
{
path: '/en-CA/products',
meta: {
layout: 'docs'
}
}
)
})

const queryContentMockData = {
_path: '/products/test',
_dir: 'get-started',
title: 'Test Title',
body: { toc: { links: [{ id: '1', text: 'Introduction', href: '#introduction' }] } }
}

const { queryContentMock } = vi.hoisted(() => ({
queryContentMock: vi.fn(() => ({
where: vi.fn().mockReturnThis(),
findOne: vi.fn(() => Promise.resolve(queryContentMockData))
}))
}))
mockNuxtImport('queryContent', () => queryContentMock)

describe('useDocPageData', () => {
let composable: ReturnType<typeof useDocPageData>

beforeEach(async () => {
composable = useDocPageData()
// wait for promises to resolve
await new Promise(resolve => setTimeout(resolve, 0))
})
it('should return correct values based off route', () => {
// assert doc page data
expect(composable.docPageData.value).toEqual(queryContentMockData)
// assert toc links
expect(composable.tocLinks.value).toEqual(queryContentMockData.body.toc.links)
// assert current dir
expect(composable.currentDir.value).toEqual(queryContentMockData._path)
// assert generated page head
expect(composable.createPageHead()).toBe('Get Started - Test Title')
})

// TODO: figure out how to test the watcher reacting to route changes
it.skip('should handle route changes', async () => {
const { docPageData, currentDir, tocLinks, createPageHead } = useDocPageData()
// wait for promises to resolve
await new Promise(resolve => setTimeout(resolve, 0))

// assert doc page data
expect(docPageData.value).toEqual(queryContentMockData)
// assert toc links
expect(tocLinks.value).toEqual(queryContentMockData.body.toc.links)
// assert current dir
expect(currentDir.value).toEqual(queryContentMockData._path)
// assert generated page head
expect(createPageHead()).toBe('Get Started - Test Title')
})
})
Loading
Loading