forked from jd-solanki/anu
-
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.
test: added basic test infrastructure (jd-solanki#93)
- Loading branch information
Showing
14 changed files
with
724 additions
and
7 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
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,19 @@ | ||
name: "Test Report" | ||
|
||
on: | ||
workflow_run: | ||
# runs after CI workflow | ||
workflows: ["Check build on various systems and node versions"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
report: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: dorny/test-reporter@v1 | ||
with: | ||
artifact: /test-results-(.*)/ | ||
name: "Test report $1" | ||
path: "*.xml" | ||
reporter: jest-junit |
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
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,66 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import { describe, expect, it } from 'vitest' | ||
import { ABtn } from '../src/components/btn/ABtn' | ||
|
||
describe('Testing ABtn', () => { | ||
it('can mount component', () => { | ||
const wrapper = shallowMount(ABtn, { props: {}, slots: { default: 'Click me' } }) | ||
|
||
expect(wrapper.find('button').exists()).toBe(true) | ||
expect(wrapper.find('button').text()).toBe('Click me') | ||
expect(wrapper.classes()).toContain('a-btn') | ||
expect(window.getComputedStyle(wrapper.find('button').element).getPropertyValue('--a-layer-color')).toContain('--a-primary') | ||
|
||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
it('has proper classes', () => { | ||
const wrapper = shallowMount(ABtn, { props: {}, slots: { default: 'Click me' } }) | ||
expect(wrapper.classes()).toMatchSnapshot() | ||
}) | ||
|
||
it('handles click event', async () => { | ||
const wrapper = shallowMount(ABtn, { props: {}, slots: { default: 'Click me' } }) | ||
|
||
await wrapper.trigger('click') | ||
expect(wrapper.emitted('click')).toBeDefined() | ||
}) | ||
|
||
it('color prop changes button color', () => { | ||
const wrapper = shallowMount(ABtn, { props: { color: 'warning' }, slots: { default: 'Click me' } }) | ||
|
||
expect(window.getComputedStyle(wrapper.find('button').element).getPropertyValue('--a-layer-color')).toContain('--a-warning') | ||
}) | ||
|
||
it('icon prop adds an icon', () => { | ||
const wrapper = shallowMount(ABtn, { props: { icon: 'i-bx-heart' }, slots: { default: 'Click me' } }) | ||
|
||
expect(wrapper.findAll('button i')[0].classes()).toContain('i-bx-heart') | ||
}) | ||
|
||
it('appendIcon prop adds an icon after the text', () => { | ||
const wrapper = shallowMount(ABtn, { props: { icon: 'i-bx-heart', appendIcon: 'i-bx-star' }, slots: { default: 'Click me' } }) | ||
|
||
expect(wrapper.findAll('button i')[0].classes()).toContain('i-bx-heart') | ||
expect(wrapper.findAll('button i')[1].classes()).toContain('i-bx-star') | ||
}) | ||
|
||
it('iconOnly prop applies a-btn-icon-only style', () => { | ||
const wrapper = shallowMount(ABtn, { props: { icon: 'i-bx-heart', iconOnly: true }, slots: { default: 'Click me' } }) | ||
|
||
expect(wrapper.findAll('button i')[0].classes()).toContain('i-bx-heart') | ||
expect(wrapper.classes()).not.toContain('a-btn') | ||
expect(wrapper.classes()).toContain('a-btn-icon-only') | ||
}) | ||
|
||
it('disabled prop disables cursor, decreases opacity and set tabindex to -1', async () => { | ||
const wrapper = shallowMount(ABtn, { props: { disabled: true }, slots: { default: 'Click me' } }) | ||
|
||
expect(wrapper.classes()).toContain('opacity-50') | ||
expect(wrapper.classes()).toContain('pointer-events-none') | ||
expect(wrapper.find('button').element.tabIndex).toBe(-1) | ||
|
||
await wrapper.trigger('click') | ||
expect(wrapper.emitted('click')).toBeUndefined() | ||
}) | ||
}) |
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,52 @@ | ||
import type { VueWrapper } from '@vue/test-utils' | ||
import { mount } from '@vue/test-utils' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { ATable } from '../src/components/table/ATable' | ||
|
||
const nameList = Array.from(Array(10).keys()).map(x => { | ||
return { name: `name${x + 1}` } | ||
}) | ||
|
||
// 馃憠 Mock ResizeObserver | ||
// This is needed for ASelect autoupdate | ||
const ResizeObserverMock = vi.fn(() => ({ | ||
observe: vi.fn(), | ||
unobserve: vi.fn(), | ||
disconnect: vi.fn(), | ||
})) | ||
|
||
vi.stubGlobal('ResizeObserver', ResizeObserverMock) | ||
|
||
describe('Testing ATable', async () => { | ||
let wrapper: VueWrapper | ||
beforeEach(() => { | ||
wrapper = mount(ATable, | ||
{ props: { rows: nameList, pageSize: 5 }, slots: { } }, | ||
) | ||
}) | ||
it('mount component', () => { | ||
// check header | ||
expect(wrapper.findAll('table thead tr th').at(0)?.text()).toBe('name') | ||
|
||
// check rows | ||
expect(wrapper.findAll('table tbody tr td').at(0)?.text()).toBe('name1') | ||
expect(wrapper.findAll('table tbody tr td').at(1)?.text()).toBe('name2') | ||
|
||
// check pagination | ||
expect(wrapper.find('.a-table-pagination-meta')?.text()).toBe('1 - 5 of 10') | ||
|
||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
|
||
it('paging should update content and paging indicator', async () => { | ||
// trigger next page | ||
await wrapper.find('.a-table-footer-next-page-btn').trigger('click') | ||
|
||
// check rows | ||
expect(wrapper.findAll('table tbody tr td').at(0)?.text()).toBe('name6') | ||
expect(wrapper.findAll('table tbody tr td').at(1)?.text()).toBe('name7') | ||
|
||
// check pagination | ||
expect(wrapper.find('.a-table-pagination-meta')?.text()).toBe('6 - 10 of 10') | ||
}) | ||
}) |
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,27 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Testing ABtn > can mount component 1`] = ` | ||
"<button class=\\"a-btn whitespace-nowrap inline-flex justify-center items-center states [--un-bg-opacity:1] text-white typography-title-white typography-subtitle-white typography-text-white typography-subtitle-opacity-100 typography-text-opacity-100 bg-$a-layer-color\\" style=\\"--a-layer-color: hsla(var(--a-primary),var(--un-bg-opacity)); --un-ring-color: hsl(var(--a-primary)); --a-spacing: 1;\\" tabindex=\\"0\\"> | ||
<!---->Click me | ||
<!----> | ||
</button>" | ||
`; | ||
exports[`Testing ABtn > has proper classes 1`] = ` | ||
[ | ||
"a-btn", | ||
"whitespace-nowrap", | ||
"inline-flex", | ||
"justify-center", | ||
"items-center", | ||
"states", | ||
"[--un-bg-opacity:1]", | ||
"text-white", | ||
"typography-title-white", | ||
"typography-subtitle-white", | ||
"typography-text-white", | ||
"typography-subtitle-opacity-100", | ||
"typography-text-opacity-100", | ||
"bg-$a-layer-color", | ||
] | ||
`; |
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,72 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Testing ATable > mount component 1`] = ` | ||
"<div class=\\"a-card overflow-hidden uno-layer-base-bg-[hsl(var(--a-layer))] a-table\\" style=\\"--a-spacing: 1;\\"> | ||
<!----> | ||
<!----> | ||
<!----> | ||
<div class=\\"overflow-x-auto\\"> | ||
<table class=\\"a-table-table overflow-x-auto w-full max-w-full\\"> | ||
<thead> | ||
<tr> | ||
<th class=\\"a-table-table-th whitespace-nowrap cursor-pointer select-none\\"> | ||
<div class=\\"inline-flex items-center\\"><span>name</span> | ||
<div class=\\"i-bx-up-arrow-alt\\" style=\\"display: none;\\"></div> | ||
<div class=\\"i-bx-down-arrow-alt\\" style=\\"display: none;\\"></div> | ||
</div> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class=\\"a-table-table-td whitespace-nowrap\\"><span class=\\"a-table-td-text\\">name1</span></td> | ||
</tr> | ||
<tr> | ||
<td class=\\"a-table-table-td whitespace-nowrap\\"><span class=\\"a-table-td-text\\">name2</span></td> | ||
</tr> | ||
<tr> | ||
<td class=\\"a-table-table-td whitespace-nowrap\\"><span class=\\"a-table-td-text\\">name3</span></td> | ||
</tr> | ||
<tr> | ||
<td class=\\"a-table-table-td whitespace-nowrap\\"><span class=\\"a-table-td-text\\">name4</span></td> | ||
</tr> | ||
<tr> | ||
<td class=\\"a-table-table-td whitespace-nowrap\\"><span class=\\"a-table-td-text\\">name5</span></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class=\\"a-table-footer flex items-center\\"> | ||
<div class=\\"uno-layer-base-text-base gap-4 flex flex-col a-table-pagination-meta\\"> | ||
<!----><span class=\\"uno-layer-base-text-[hsla(var(--a-typography-text-color),var(--a-typography-text-opacity))]\\"><span class=\\"text-xs\\">1 - 5 of 10</span></span> | ||
</div> | ||
<div class=\\"flex-grow\\"></div> | ||
<div class=\\"a-table-footer-per-page-container flex items-center\\"><span class=\\"sm:inline hidden\\">per page</span> | ||
<div class=\\"a-base-input-root i:children:focus-within:text-primary flex flex-col flex-grow flex-shrink-0 a-table-footer-per-page-select a-base-input-interactive\\" style=\\"--a-spacing: 0.8;\\"> | ||
<!----> | ||
<div class=\\"a-base-input-input-container flex items-center\\"> | ||
<!----> | ||
<div class=\\"focus-within:border-primary a-base-input-input-wrapper cursor-text em:spacing:px-4 spacing:gap-x-2 relative i:focus-within:text-primary items-center border border-solid border-a-border w-full a-table-footer-per-page-select--input-wrapper-classes\\"> | ||
<!----><input class=\\"a-base-input-child w-full h-full inset-0 rounded-inherit bg-transparent a-base-input-wo-prepend-inner a-base-input-w-append-inner\\" readonly=\\"\\"><i class=\\"a-base-input-append-inner-icon ml-auto transition duration-150 ease -in i-bx-chevron-down\\"></i> | ||
</div> | ||
<!----> | ||
</div> | ||
<transition-stub name=\\"expand\\" appear=\\"false\\" persisted=\\"false\\" css=\\"true\\" data-v-0762f2f7=\\"\\"> | ||
<div class=\\"h-8\\" style=\\"display: none;\\"><small class=\\"inline-block text-light-emphasis\\"> | ||
<!----> | ||
</small></div> | ||
</transition-stub> | ||
</div> | ||
<!--teleport start--> | ||
<!--teleport end--> | ||
</div> | ||
<div><button class=\\"a-btn-icon-only whitespace-nowrap inline-flex justify-center items-center opacity-50 pointer-events-none states [--un-bg-opacity:1] text-primary typography-title-primary typography-subtitle-primary typography-text-primary typography-subtitle-opacity-100 typography-text-opacity-100 a-table-footer-previous-page-btn\\" disabled=\\"\\" style=\\"--a-layer-color: hsla(var(--a-primary),var(--un-bg-opacity)); --un-ring-color: hsl(var(--a-primary)); --a-spacing: 1;\\" tabindex=\\"-1\\"><i class=\\"i-bx-left-arrow-alt\\"></i> | ||
<!----> | ||
<!----> | ||
</button><button class=\\"a-btn-icon-only whitespace-nowrap inline-flex justify-center items-center states [--un-bg-opacity:1] text-primary typography-title-primary typography-subtitle-primary typography-text-primary typography-subtitle-opacity-100 typography-text-opacity-100 a-table-footer-next-page-btn\\" style=\\"--a-layer-color: hsla(var(--a-primary),var(--un-bg-opacity)); --un-ring-color: hsl(var(--a-primary)); --a-spacing: 1;\\" tabindex=\\"0\\"><i class=\\"i-bx-right-arrow-alt\\"></i> | ||
<!----> | ||
<!----> | ||
</button></div> | ||
</div> | ||
</div>" | ||
`; |
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 |
---|---|---|
|
@@ -23,7 +23,10 @@ | |
"anu-vue": [ | ||
"./src" | ||
] | ||
} | ||
}, | ||
"types": [ | ||
"vitest/globals" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
|
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
Oops, something went wrong.