|
| 1 | +import { defineComponent, ref } from "vue"; |
| 2 | +import BaseDirectionPad from "./BaseDirectionPad.vue"; |
| 3 | + |
| 4 | +describe('<BaseDirectionPad />', () => { |
| 5 | + it('renders correctly with default props', () => { |
| 6 | + cy.mount(defineComponent({ |
| 7 | + components: { BaseDirectionPad }, |
| 8 | + template: '<BaseDirectionPad />', |
| 9 | + })); |
| 10 | + cy.get('button').should('have.length', 5); |
| 11 | + cy.get('button').first().should('have.css', 'position', 'absolute'); |
| 12 | + cy.get('button').first().should('have.css', 'left', '0px'); |
| 13 | + cy.get('[data-cy="base-icon"]').each(icon => { |
| 14 | + cy.wrap(icon).as('icon') |
| 15 | + cy.get('@icon').find('path').eq(0).should($path => { |
| 16 | + const stroke = $path.attr('stroke'); |
| 17 | + const fill = $path.attr('fill'); |
| 18 | + if (stroke !== 'none') { |
| 19 | + expect(stroke).to.eq('#1A1A1A'); |
| 20 | + } else if (fill) { |
| 21 | + expect(fill).to.eq('#1A1A1A'); |
| 22 | + } |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + }); |
| 27 | + |
| 28 | + it('emits', () => { |
| 29 | + const moveLeft = cy.stub(); |
| 30 | + const moveTop = cy.stub(); |
| 31 | + const moveRight = cy.stub(); |
| 32 | + const moveBottom = cy.stub(); |
| 33 | + const reset = cy.stub(); |
| 34 | + |
| 35 | + cy.mount(defineComponent({ |
| 36 | + components: { BaseDirectionPad }, |
| 37 | + setup() { |
| 38 | + return { moveLeft, moveTop, moveRight, moveBottom, reset }; |
| 39 | + }, |
| 40 | + template: ` |
| 41 | + <BaseDirectionPad |
| 42 | + @moveLeft="moveLeft" |
| 43 | + @moveTop="moveTop" |
| 44 | + @moveRight="moveRight" |
| 45 | + @moveBottom="moveBottom" |
| 46 | + @reset="reset" |
| 47 | + /> |
| 48 | + ` |
| 49 | + })); |
| 50 | + cy.get('[data-cy="direction-pad-left"]').click(); |
| 51 | + cy.wrap(moveLeft).should('have.been.calledOnce'); |
| 52 | + cy.get('[data-cy="direction-pad-top"]').click(); |
| 53 | + cy.wrap(moveTop).should('have.been.calledOnce'); |
| 54 | + cy.get('[data-cy="direction-pad-right"]').click(); |
| 55 | + cy.wrap(moveRight).should('have.been.calledOnce'); |
| 56 | + cy.get('[data-cy="direction-pad-bottom"]').click(); |
| 57 | + cy.wrap(moveBottom).should('have.been.calledOnce'); |
| 58 | + cy.get('[data-cy="direction-pad-reset"]').click(); |
| 59 | + cy.wrap(reset).should('have.been.calledOnce'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('handles color prop', () => { |
| 63 | + cy.mount(defineComponent({ |
| 64 | + components: { BaseDirectionPad }, |
| 65 | + setup() { |
| 66 | + const color = ref('#FF0000'); |
| 67 | + return { color }; |
| 68 | + }, |
| 69 | + template: ` |
| 70 | + <BaseDirectionPad :color="color" /> |
| 71 | + ` |
| 72 | + })); |
| 73 | + |
| 74 | + cy.get('[data-cy="base-icon"]').each(icon => { |
| 75 | + cy.wrap(icon).as('icon') |
| 76 | + cy.get('@icon').find('path').eq(0).should($path => { |
| 77 | + const stroke = $path.attr('stroke'); |
| 78 | + const fill = $path.attr('fill'); |
| 79 | + if (stroke !== 'none') { |
| 80 | + expect(stroke).to.eq('#FF0000'); |
| 81 | + } else if (fill) { |
| 82 | + expect(fill).to.eq('#FF0000'); |
| 83 | + } |
| 84 | + }); |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments