11/// <reference types="@wdio/globals/types" />
22import { $ , $$ , expect , browser } from '@wdio/globals'
3- import { render } from '@testing-library/vue'
3+ import { render , cleanup } from '@testing-library/vue'
44import CircleDrawer from '../components/CircleDrawer.vue'
55
66describe ( 'Vue Component Testing' , ( ) => {
7- let root : HTMLElement
8-
9- beforeEach ( async ( ) => {
10- const { baseElement } = render ( CircleDrawer )
11- root = baseElement as HTMLElement
12- baseElement . setAttribute ( 'style' , 'height: 500px' )
7+ afterEach ( ( ) => {
8+ cleanup ( )
139 } )
1410
15- async function setCircle ( x ?: number , y ?: number ) {
16- const $root = await $ ( root )
11+ async function setCircle ( x ?: number , y ?: number , root ?: HTMLElement ) {
12+ const $root = await $ ( root ! )
1713 await browser . action ( 'pointer' )
1814 . move ( x && y ? { x, y } : { origin : $root } )
1915 . down ( )
@@ -29,43 +25,62 @@ describe('Vue Component Testing', () => {
2925 . perform ( )
3026 }
3127
32- beforeEach ( async ( ) => {
33- await browser . pause ( 100 )
34- } )
35-
3628 it ( 'can set a circle' , async ( ) => {
37- await setCircle ( )
38- const circle = await $ ( 'circle' )
39- expect ( await circle . getAttribute ( 'cy' ) ) . toBe ( '250' )
40- expect ( await circle . getAttribute ( 'r' ) ) . toBe ( '50' )
41- expect ( await circle . getAttribute ( 'fill' ) ) . toBe ( '#fff' )
29+ const { baseElement, container } = render ( CircleDrawer )
30+ const root = baseElement as HTMLElement
31+ baseElement . setAttribute ( 'style' , 'height: 500px' )
32+ await browser . pause ( 100 )
33+
34+ await setCircle ( undefined , undefined , root )
35+ const $container = await $ ( container )
36+ let circles = await $container . $$ ( 'circle' )
37+ expect ( circles ) . toHaveLength ( 1 )
38+ expect ( await circles [ 0 ] . getAttribute ( 'cy' ) ) . toBe ( '250' )
39+ expect ( await circles [ 0 ] . getAttribute ( 'r' ) ) . toBe ( '50' )
40+ expect ( await circles [ 0 ] . getAttribute ( 'fill' ) ) . toBe ( '#fff' )
4241
43- await setCircle ( 200 , 200 )
44- const circles = await $$ ( 'circle' )
42+ await setCircle ( 200 , 200 , root )
43+ circles = await $container . $$ ( 'circle' )
4544
4645 expect ( circles ) . toHaveLength ( 2 )
47- expect ( await circle . getAttribute ( 'fill' ) ) . toBe ( '#fff' )
46+ // After adding a second circle, no circle should be selected
47+ expect ( await circles [ 0 ] . getAttribute ( 'fill' ) ) . toBe ( '#fff' )
48+ expect ( await circles [ 1 ] . getAttribute ( 'fill' ) ) . toBe ( '#fff' )
4849
49- await $ ( 'button=Undo' ) . click ( )
50- await expect ( $$ ( 'circle' ) ) . toBeElementsArrayOfSize ( 1 )
50+ await $container . $ ( 'button=Undo' ) . click ( )
51+ circles = await $container . $$ ( 'circle' )
52+ expect ( circles ) . toHaveLength ( 1 )
5153
52- await $ ( 'button=Redo' ) . click ( )
53- await expect ( $$ ( 'circle' ) ) . toBeElementsArrayOfSize ( 2 )
54+ await $container . $ ( 'button=Redo' ) . click ( )
55+ circles = await $container . $$ ( 'circle' )
56+ expect ( circles ) . toHaveLength ( 2 )
5457 } )
5558
5659 it ( 'pop up modal for adjusting circle size' , async ( ) => {
57- await setCircle ( )
58- const circle = await $ ( 'circle' )
60+ const { baseElement, container } = render ( CircleDrawer )
61+ const root = baseElement as HTMLElement
62+ baseElement . setAttribute ( 'style' , 'height: 500px' )
63+ await browser . pause ( 100 )
64+
65+ await setCircle ( undefined , undefined , root )
66+ const $container = await $ ( container )
67+ const circle = await $container . $ ( 'circle' )
5968 await openAdjustMenu ( circle )
60- expect ( $ ( '.dialog' ) ) . toBeExisting ( )
69+ expect ( $container . $ ( '.dialog' ) ) . toBeExisting ( )
6170 } )
6271
6372 it ( 'can modify size of circle' , async ( ) => {
64- await setCircle ( )
65- const circle = await $ ( 'circle' )
73+ const { baseElement, container } = render ( CircleDrawer )
74+ const root = baseElement as HTMLElement
75+ baseElement . setAttribute ( 'style' , 'height: 500px' )
76+ await browser . pause ( 100 )
77+
78+ await setCircle ( undefined , undefined , root )
79+ const $container = await $ ( container )
80+ const circle = await $container . $ ( 'circle' )
6681 await openAdjustMenu ( circle )
6782
68- const menu = await $ ( '.dialog input' )
83+ const menu = await $container . $ ( '.dialog input' )
6984 const size = await menu . getSize ( )
7085 const location = await menu . getLocation ( )
7186 await browser . action ( 'pointer' )
0 commit comments