-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrate react Highlight component to Vue (#23973)
* add test. * Add Highlight vue component + remove react component. * Remove floating-ui dependency. * fix test failure Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
- Loading branch information
1 parent
53eef4f
commit 0bb705c
Showing
15 changed files
with
221 additions
and
225 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,71 @@ | ||
function launchApp () { | ||
cy.scaffoldProject('selector-playground') | ||
cy.openProject('selector-playground') | ||
cy.startAppServer('e2e') | ||
cy.visitApp() | ||
cy.get(`[data-cy-row="spec.cy.js"]`).click() | ||
|
||
cy.waitForSpecToFinish() | ||
} | ||
|
||
describe('selector playground', () => { | ||
it('highlight the element when hover over it.', () => { | ||
launchApp() | ||
|
||
cy.get('[data-cy="playground-activator"]').click() | ||
|
||
const backgroundColor = 'rgba(159, 196, 231, 0.6)' | ||
|
||
cy.getAutIframe().within(() => { | ||
cy.get('h1').realHover() | ||
cy.get('.__cypress-selector-playground').shadow().within(() => { | ||
// Test highlight exists | ||
cy.get('.highlight').should('exist') | ||
cy.get('.highlight').should('have.css', 'background-color', backgroundColor) | ||
|
||
// Test tooltip text is correct | ||
cy.get('.tooltip').should('have.text', 'h1') | ||
|
||
// Test placement of tooltip | ||
let highlightTop: any | ||
let tooltipTop: any | ||
|
||
cy.get('.highlight').then(($el) => { | ||
highlightTop = parseFloat($el.css('top')) | ||
}) | ||
|
||
cy.get('.tooltip').then(($el) => { | ||
tooltipTop = parseFloat($el.css('top')) | ||
|
||
expect(tooltipTop).to.be.greaterThan(highlightTop) | ||
}) | ||
}) | ||
}) | ||
|
||
cy.getAutIframe().within(() => { | ||
cy.get('h2').realHover() | ||
cy.get('.__cypress-selector-playground').shadow().within(() => { | ||
// Test highlight exists | ||
cy.get('.highlight').should('exist') | ||
cy.get('.highlight').should('have.css', 'background-color', backgroundColor) | ||
|
||
// Test tooltip text is correct | ||
cy.get('.tooltip').should('have.text', '[data-cy="h2-contents"]') | ||
|
||
// Test placement of tooltip | ||
let highlightTop: any | ||
let tooltipTop: any | ||
|
||
cy.get('.highlight').then(($el) => { | ||
highlightTop = parseFloat($el.css('top')) | ||
}) | ||
|
||
cy.get('.tooltip').then(($el) => { | ||
tooltipTop = parseFloat($el.css('top')) | ||
|
||
expect(tooltipTop).to.be.lessThan(highlightTop) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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
81 changes: 81 additions & 0 deletions
81
packages/app/src/runner/selector-playground/Highlight.ce.vue
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,81 @@ | ||
<template> | ||
<div | ||
class="highlight" | ||
:style="highlightStyle" | ||
/> | ||
<div | ||
class="tooltip" | ||
:style="tooltipStyle" | ||
> | ||
<span>{{ selector }}</span> | ||
<div | ||
class="arrow" | ||
:style="arrowStyle" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { StyleValue, CSSProperties } from 'vue' | ||
const props = defineProps <{ | ||
selector: string | ||
style: StyleValue | ||
}>() | ||
const highlightStyle = props.style as CSSProperties || {} | ||
const highlightTop = parseFloat(highlightStyle.top as string) | ||
const highlightLeft = parseFloat(highlightStyle.left as string) | ||
const highlightHeight = parseFloat(highlightStyle.height as string) | ||
const placeOnBottom = highlightTop < 35 | ||
const tooltipStyle = | ||
placeOnBottom | ||
? { | ||
top: `${highlightTop + highlightHeight + 10}px`, | ||
left: `${highlightLeft}px`, | ||
} | ||
: { | ||
top: `${highlightTop - 33}px`, | ||
left: `${highlightLeft}px`, | ||
} | ||
const arrowStyle = | ||
placeOnBottom | ||
? { | ||
left: `8px`, | ||
top: `-6px`, | ||
transform: 'rotate(0deg)', | ||
} | ||
: { | ||
left: `8px`, | ||
top: `24px`, | ||
transform: 'rotate(180deg)', | ||
} | ||
</script> | ||
|
||
<style> | ||
.highlight { | ||
background: rgba(159, 196, 231, 0.6); | ||
border: solid 2px #9FC4E7; | ||
cursor: pointer; | ||
} | ||
.tooltip { | ||
position: absolute; | ||
background: #333; | ||
border: solid 1px #333; | ||
border-radius: 3px; | ||
color: #e3e3e3; | ||
font-size: 12px; | ||
padding: 4px 6px; | ||
text-align: center; | ||
} | ||
.arrow { | ||
position: absolute; | ||
width: 0; | ||
height: 0; | ||
border-style: solid; | ||
border-width: 0 6px 6px 6px; | ||
border-color: transparent transparent #333 transparent; | ||
} | ||
</style> |
17 changes: 17 additions & 0 deletions
17
packages/app/src/runner/selector-playground/HighlightApp.ce.vue
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,17 @@ | ||
<template> | ||
<Highlight | ||
v-for="(style, i) in styles" | ||
:key="i" | ||
:selector="selector" | ||
:style="style" | ||
/> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import Highlight from './Highlight.ce.vue' | ||
defineProps <{ | ||
selector: string | ||
styles: any[] | ||
}>() | ||
</script> |
19 changes: 19 additions & 0 deletions
19
packages/app/src/runner/selector-playground/highlight-mounter.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { App, createApp } from 'vue' | ||
import HighlightApp from './HighlightApp.ce.vue' | ||
|
||
let app: App<Element> | null = null | ||
|
||
export default { | ||
mount (container: Element, selector: string, styles: any[]) { | ||
if (app) { | ||
app.unmount() | ||
} | ||
|
||
app = createApp(HighlightApp, { | ||
selector, | ||
styles, | ||
}) | ||
|
||
app.mount(container) | ||
}, | ||
} |
Oops, something went wrong.
0bb705c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
0bb705c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
0bb705c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
0bb705c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
0bb705c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: