Skip to content

Commit

Permalink
Merge pull request #124 from PrestaShopCorp/feat/test-coverage
Browse files Browse the repository at this point in the history
[Feat] Add test coverage
  • Loading branch information
cnavarro-prestashop authored Jul 11, 2023
2 parents 1f33f7e + 2e2488c commit 1637b1c
Show file tree
Hide file tree
Showing 8 changed files with 2,198 additions and 1,731 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ jobs:

- name: Run tests 🧪
run: pnpm test

- name: Run coverage 📈
run: pnpm coverage
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ Example:
$ pnpm test
```

This project uses [v8](https://v8.dev/blog/javascript-code-coverage) as test coverage provider. Run the following command to check the current coverage. Min coverage rate is at 60%

Example:

```sh
$ pnpm coverage
```

### Storybook

If you are adding a new feature, refactoring or changing the behavior of a component
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"cz": "git-cz",
"test": "vitest --no-threads",
"coverage": "vitest run --coverage",
"gen:version": "tsx scripts/gen-version.ts",
"update:version": "tsx scripts/update-version.ts",
"clean": "pnpm clean:dist && pnpm -r --parallel clean",
Expand Down Expand Up @@ -79,6 +80,7 @@
"@typescript-eslint/eslint-plugin": "5.58.0",
"@typescript-eslint/parser": "5.58.0",
"@vitejs/plugin-vue": "^4.1.0",
"@vitest/coverage-v8": "^0.32.4",
"@vue/test-utils": "^2.3.2",
"@vue/tsconfig": "^0.1.3",
"chalk": "^5.2.0",
Expand All @@ -105,7 +107,7 @@
"type-fest": "^2.19.0",
"typescript": "^5.0.4",
"unplugin-vue-define-options": "^1.3.3",
"vitest": "^0.30.1",
"vitest": "^0.32.4",
"vue": "^3.2.47",
"vue-router": "^4.1.6",
"vue-tsc": "^1.2.0"
Expand Down
69 changes: 67 additions & 2 deletions packages/components/accordion/test/accordion-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
import PuikAccordionGroup from '../src/accordion-group.vue'
Expand All @@ -17,8 +18,11 @@ const factory = (template: string, options: MountingOptions<any> = {}) => {
})
}

const rootClass = 'puik-accordion'
const expandedClass = 'puik-accordion--expanded'

const getAccordionGroup = () => wrapper.find('.puik-accordion-group')
const getAccordions = () => wrapper.findAll('.puik-accordion')
const getAccordions = () => wrapper.findAll(`.${rootClass}`)

describe('AccordionGroup collapse/expand tests', () => {
it('should be a vue instance', () => {
Expand Down Expand Up @@ -50,7 +54,7 @@ describe('AccordionGroup collapse/expand tests', () => {
factory(template)

const accordion = getAccordion(wrapper)
expect(accordion.classes()).toContain('puik-accordion--expanded')
expect(accordion.classes()).toContain(expandedClass)
})

it('should accordions title have aria-expanded', () => {
Expand Down Expand Up @@ -113,4 +117,65 @@ describe('AccordionGroup props tests', () => {
const group = getAccordionGroup()
expect(group.classes()).toContain('puik-accordion-group--contained')
})
it('should change expanded accordion on v-model change', async () => {
const template = `
<puik-accordion-group v-model="expandedAccordions">
<puik-accordion name="accordion-1" title="title 1">
Content 1
</puik-accordion>
<puik-accordion name="accordion-2" title="title 2">
Content 2
</puik-accordion>
<puik-accordion name="accordion-3" title="title 3">
Content 3
</puik-accordion>
</puik-accordion-group>
`

factory(template, {
data() {
return { expandedAccordions: 'accordion-1' }
},
})

wrapper.setData({ expandedAccordions: 'accordion-2' })
await nextTick()

const accordions = getAccordions()
expect(accordions[1].classes()).toEqual([rootClass, expandedClass])
expect(accordions[2].classes()).toEqual([rootClass])

wrapper.setData({ expandedAccordions: ['accordion-3'] })
await nextTick()
expect(accordions[1].classes()).toEqual([rootClass])
expect(accordions[2].classes()).toEqual([rootClass, expandedClass])
})
it('should change expanded accordion on click on multiple mode', async () => {
const template = `
<puik-accordion-group multiple>
<puik-accordion name="accordion-1" title="title 1">
Content 1
</puik-accordion>
<puik-accordion name="accordion-2" title="title 2">
Content 2
</puik-accordion>
<puik-accordion name="accordion-3" title="title 3">
Content 3
</puik-accordion>
</puik-accordion-group>
`

factory(template)

const accordions = getAccordions()
const accordionButtons = wrapper.findAll('.puik-accordion__header')

accordionButtons[0].trigger('click')
accordionButtons[1].trigger('click')
await nextTick()

expect(accordions[0].classes()).toEqual([rootClass, expandedClass])
expect(accordions[1].classes()).toEqual([rootClass, expandedClass])
expect(accordions[2].classes()).toEqual([rootClass])
})
})
16 changes: 16 additions & 0 deletions packages/components/accordion/test/accordion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const getAccordionSubTitle = (component) =>
component.find('.puik-accordion__header__content__sub-title')
export const getAccordionExpandIcon = (component) =>
component.find('.puik-accordion__header__expand__icon')
export const getAccordionIcon = (component) =>
component.find('.puik-accordion__header__icon')

describe('Accordion tests', () => {
it('should be a vue instance', () => {
Expand Down Expand Up @@ -136,4 +138,18 @@ describe('Accordion tests', () => {
expect(accordion.classes()).toContain('puik-accordion--disabled')
expect(getAccordionHeader(accordion).attributes('disabled')).toBeDefined()
})

it('should have icon', () => {
const icon = 'home'
const template = `
<puik-accordion-group>
<puik-accordion name="accordion-1" icon="${icon}">
Content
</puik-accordion>
</puik-accordion-group>
`
factory(template)

expect(getAccordionIcon(wrapper).text()).toBe(icon)
})
})
2 changes: 1 addition & 1 deletion packages/components/breadcrumb/test/breadcrumb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Breadcrumb tests', () => {
expect(wrapper).toBeTruthy()
})
it('should not display without items', () => {
factory({ items: [] })
factory()
expect(wrapper.element.tagName).toBeFalsy()
})
it('should first item be A with href', () => {
Expand Down
Loading

0 comments on commit 1637b1c

Please sign in to comment.