Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aut centering and height calculation #21019

Merged
merged 37 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3d9427f
fix aut centering and height calculation
marktnoonan Apr 10, 2022
2dd05d2
group similar imports together
marktnoonan Apr 11, 2022
4a7a2c6
group similar imports together
marktnoonan Apr 11, 2022
e04639f
add tests for dragging and resizing
marktnoonan Apr 11, 2022
f39e1d0
add comments in test
marktnoonan Apr 11, 2022
5ac60ab
remove unused params - let store set default
marktnoonan Apr 11, 2022
6ebe382
reorder call to useRunnerStyle
marktnoonan Apr 11, 2022
7ec25e9
simplify useRunnerStyle to just what gets used
marktnoonan Apr 11, 2022
df901dd
get width from store instead of composable
marktnoonan Apr 11, 2022
6031870
fix extra pixel on left of screenshots
marktnoonan Apr 12, 2022
d66712f
avoid using margin to center during screenshot
marktnoonan Apr 12, 2022
33b3060
Merge branch '10.0-release' into UNIFY-1380-aut-initial-size
marktnoonan Apr 12, 2022
56f3927
Merge branch '10.0-release' into UNIFY-1380-aut-initial-size
marktnoonan Apr 12, 2022
c569d52
make sure run mode header is reactive to height changes also
marktnoonan Apr 12, 2022
b120ac6
add missing ref
marktnoonan Apr 12, 2022
b239279
update reference screenshots
marktnoonan Apr 13, 2022
85f1ab8
fix folder name
marktnoonan Apr 13, 2022
0860480
Revert "fix folder name"
marktnoonan Apr 13, 2022
50c5666
fix folder name
marktnoonan Apr 13, 2022
b612ecc
test uploading of screenshot jpgs to percy
marktnoonan Apr 13, 2022
136de62
remove slash
marktnoonan Apr 13, 2022
80c1714
upload screenshots from latest run
marktnoonan Apr 13, 2022
0940ce7
add readme
marktnoonan Apr 13, 2022
953b174
avoid
marktnoonan Apr 13, 2022
9db3f6d
put back finalize command
marktnoonan Apr 13, 2022
2153bff
Merge branch '10.0-release' into UNIFY-1380-aut-initial-size
marktnoonan Apr 13, 2022
3845bc1
set reporter size again before end of test
marktnoonan Apr 13, 2022
ef29546
fix comment
marktnoonan Apr 13, 2022
c82ae5d
Merge branch '10.0-release' into UNIFY-1380-aut-initial-size
marktnoonan Apr 13, 2022
c150d3e
add fn to clarify what cy.contains('%)') is
marktnoonan Apr 17, 2022
7a7e276
clean up based on PR feedback
marktnoonan Apr 17, 2022
ef79ae0
rename "remove positioning" component
marktnoonan Apr 17, 2022
608e83f
move store invocation inside function
marktnoonan Apr 17, 2022
da8a161
add comment
marktnoonan Apr 17, 2022
7bce0e3
Merge branch '10.0-release' into UNIFY-1380-aut-initial-size
marktnoonan Apr 17, 2022
9091766
use immediate watcher for AUT header height
marktnoonan Apr 18, 2022
15e75ea
use new composable in run mode
marktnoonan Apr 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 93 additions & 12 deletions packages/app/cypress/e2e/cypress-in-cypress.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import type { DraggablePanel } from '../../src/runner/useRunnerStyle'

const testingTypes = ['component', 'e2e'] as const

const dragHandleToClientX = (panel: DraggablePanel, x: number) => {
return cy.get(`[data-cy="${panel}ResizeHandle"]`).trigger('mousedown', { eventConstructor: 'MouseEvent' })
.trigger('mousemove', { clientX: x })
.trigger('mouseup', { eventConstructor: 'MouseEvent' })
}

function startAtSpecsPage (testingType: typeof testingTypes[number]) {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.startAppServer(testingType)
cy.visitApp()
}

// For Cypress-in-Cypress tests that do not vary based on testing type
describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 10000 }, () => {
const testingTypes = ['component', 'e2e'] as const

testingTypes.forEach((testingType) => {
it(`handles automation disconnects in ${testingType}`, () => {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.startAppServer(testingType)
cy.visitApp()
startAtSpecsPage(testingType)

cy.get('[data-cy="spec-item"]').first().click()
// Let runner stabilize
Expand Down Expand Up @@ -36,11 +48,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
it(`handles automation missing in ${testingType}`, () => {
let connectedCallback: any

cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.startAppServer(testingType)
cy.visitApp()
startAtSpecsPage(testingType)

cy.window().then((win) => {
if (!win.ws) {
Expand Down Expand Up @@ -84,5 +92,78 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
expect(ctx.actions.project.launchProject).to.have.been.called
})
})

it(`scales the AUT correctly in ${testingType}`, () => {
const assertNoScaleShown = () => {
// check that no message about scale % is shown,
// meaning the AUT is at 100% scale
cy.contains('%)').should('not.exist')
}

cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.withCtx((ctx) => {
ctx.coreData.localSettings.preferences.reporterWidth = 800
})

cy.startAppServer(testingType)
cy.visitApp()

cy.get('[data-cy="spec-item"]').first().click()
// Let runner stabilize
cy.get('#unified-reporter').should('be.visible')

// validate that the width we set in `withCtx` above is the starting point
cy.get(`[data-cy="reporter-panel"]`).invoke('outerWidth').should('eq', 800)
cy.percySnapshot('initial state')

// we will move the right-hand handle of the Reporter
// to these positions from the left of the screen
const dragPositions = [1000, 1090, 900, 600]

// based on viewport sizes for CT and e2e tests in the `cypress-in-cypress`
// projects, we expect certain scale % values to be shown
marktnoonan marked this conversation as resolved.
Show resolved Hide resolved
const testingTypeExpectedScales = {
component: ['93%', '75%'],
e2e: ['46%', '37%', '56%', '85%'],
componentShortViewport: '61%',
e2eShortViewport: '46%',
}

// resize the reporter using each of the dragPositions and take Percy snapshots
dragPositions.forEach((position, index) => {
dragHandleToClientX('panel2', position).then(() => {
const expectedScale = testingTypeExpectedScales[testingType][index]

// CT hits 100% scale "earlier" than E2E, so sometimes there is no expected scale
if (expectedScale) {
cy.contains(expectedScale).should('be.visible')
} else {
assertNoScaleShown()
}

cy.percySnapshot(`panel 2 at ${ position } px`)
})
})

// now check vertical scaling with viewport resize, and take some snapshots too

// this viewport should be tall enough to not scale even the e2e test
cy.viewport(1500, 1300)

// make sure the reporter is narrow enough (should be, but don't want to depend on leftover state from above)
dragHandleToClientX('panel2', 400).then(() => {
// but we have to also collapse the Specs List to remove any reason to scale horizontally
cy.contains('[aria-controls=reporter-inline-specs-list]', 'Specs').click()

assertNoScaleShown()
cy.percySnapshot('tall viewport')

cy.viewport(1500, 400)
cy.contains(testingTypeExpectedScales[`${ testingType }ShortViewport`]).should('exist')
cy.percySnapshot('short viewport')
})
})
})
})
11 changes: 7 additions & 4 deletions packages/app/src/runner/SpecRunnerHeaderOpenMode.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div
id="spec-runner-header"
ref="autHeaderEl"
class="min-h-64px text-14px"
:style="{ width: `${props.width}px` }"
>
Expand Down Expand Up @@ -130,15 +131,15 @@
<script lang="ts" setup>
import { computed, ref, watchEffect } from 'vue'
import { useRoute } from 'vue-router'
import { useAutStore, useSpecStore } from '../store'
import { useAutStore, useSpecStore, useSelectorPlaygroundStore } from '../store'
import { useAutHeader } from './useAutHeader'
import { gql } from '@urql/vue'
import { useI18n } from 'vue-i18n'
import type { SpecRunnerHeaderFragment } from '../generated/graphql'
import SelectorPlayground from './selector-playground/SelectorPlayground.vue'
import { useSelectorPlaygroundStore } from '../store/selector-playground-store'
import type { EventManager } from './event-manager'
import type { AutIframe } from './aut-iframe'
import { togglePlayground as _togglePlayground } from './utils'
import { useI18n } from 'vue-i18n'
import SelectorPlayground from './selector-playground/SelectorPlayground.vue'
import ExternalLink from '@packages/frontend-shared/src/gql-components/ExternalLink.vue'
import Alert from '@packages/frontend-shared/src/components/Alert.vue'
import Button from '@packages/frontend-shared/src/components/Button.vue'
Expand Down Expand Up @@ -180,6 +181,8 @@ const props = defineProps<{

const showAlert = ref(false)

const { autHeaderEl } = useAutHeader()

watchEffect(() => {
showAlert.value = route.params.shouldShowTroubleRenderingAlert === 'true'
})
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/runner/SpecRunnerHeaderRunMode.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div
id="spec-runner-header"
ref="autHeaderEl"
class="min-h-64px px-16px text-14px"
:style="{ width: `${props.width}px` }"
>
Expand Down Expand Up @@ -58,6 +59,7 @@ import { useAutStore } from '../store'
import type { EventManager } from './event-manager'
import SpecRunnerDropdown from './SpecRunnerDropdown.vue'
import { allBrowsersIcons } from '@packages/frontend-shared/src/assets/browserLogos'
import { useAutHeader } from './useAutHeader'

const props = defineProps<{
eventManager: EventManager
Expand All @@ -70,6 +72,8 @@ const displayScale = computed(() => {

const autStore = useAutStore()

const { autHeaderEl } = useAutHeader()

const selectedBrowser = window.__CYPRESS_BROWSER__
const testingType = window.__CYPRESS_TESTING_TYPE__

Expand Down
46 changes: 24 additions & 22 deletions packages/app/src/runner/SpecRunnerOpenMode.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<RemovePositioningDuringScreenshot
<AdjustRunnerStyleDuringScreenshot
id="main-pane"
class="flex border-gray-900 border-l-1"
class="flex border-gray-900"
>
<AutomationElement />
<AutomationDisconnected
Expand Down Expand Up @@ -75,7 +75,7 @@
<div
v-show="!autStore.scriptError"
:id="RUNNER_ID"
class="origin-top-left viewport"
class="origin-top viewport"
:style="viewportStyle"
/>
</RemoveClassesDuringScreenshotting>
Expand All @@ -86,7 +86,7 @@
<ScreenshotHelperPixels />
</template>
</ResizablePanels>
</RemovePositioningDuringScreenshot>
</AdjustRunnerStyleDuringScreenshot>
</template>

<script lang="ts" setup>
Expand All @@ -100,7 +100,7 @@ import SnapshotControls from './SnapshotControls.vue'
import SpecRunnerHeaderOpenMode from './SpecRunnerHeaderOpenMode.vue'
import HideDuringScreenshot from './screenshot/HideDuringScreenshot.vue'
import RemoveClassesDuringScreenshotting from './screenshot/RemoveClassesDuringScreenshotting.vue'
import RemovePositioningDuringScreenshot from './screenshot/RemovePositioningDuringScreenshot.vue'
import AdjustRunnerStyleDuringScreenshot from './screenshot/AdjustRunnerStyleDuringScreenshot.vue'
import ScreenshotHelperPixels from './screenshot/ScreenshotHelperPixels.vue'
import { useScreenshotStore } from '../store/screenshot-store'
import ChooseExternalEditorModal from '@packages/frontend-shared/src/gql-components/ChooseExternalEditorModal.vue'
Expand Down Expand Up @@ -160,14 +160,6 @@ const autStore = useAutStore()
const screenshotStore = useScreenshotStore()
const runnerUiStore = useRunnerUiStore()
const preferences = usePreferences()

const {
viewportStyle,
windowWidth,
reporterWidth,
specListWidth,
} = useRunnerStyle()

const {
handlePanelWidthUpdated,
handleResizeEnd,
Expand All @@ -179,21 +171,32 @@ const {
cleanupRunner,
} = useEventManager()

const specsListWidthPreferences = computed(() => {
return props.gql.localSettings.preferences.specListWidth ?? runnerUiStore.specListWidth
})

const reporterWidthPreferences = computed(() => {
return props.gql.localSettings.preferences.reporterWidth ?? runnerUiStore.reporterWidth
})

// we must update preferences before calling useRunnerStyle, to make sure that values from GQL
// will be available during the initial calculation that useRunnerStyle does

preferences.update('reporterWidth', reporterWidthPreferences.value)
preferences.update('specListWidth', specsListWidthPreferences.value)

const {
viewportStyle,
windowWidth,
} = useRunnerStyle()

// watch active spec, and re-run if it changes!
startSpecWatcher()

onMounted(() => {
initializeRunnerLifecycleEvents()
})

const specsListWidthPreferences = computed(() => {
return props.gql.localSettings.preferences.specListWidth ?? specListWidth.value
})

const reporterWidthPreferences = computed(() => {
return props.gql.localSettings.preferences.reporterWidth ?? reporterWidth.value
})

preferences.update('autoScrollingEnabled', props.gql.localSettings.preferences.autoScrollingEnabled ?? true)
preferences.update('isSpecsListOpen', props.gql.localSettings.preferences.isSpecsListOpen ?? true)
preferences.update('reporterWidth', reporterWidthPreferences.value)
Expand All @@ -219,7 +222,6 @@ function openFile () {
},
})
}

onMounted(() => {
const eventManager = getEventManager()

Expand Down
13 changes: 6 additions & 7 deletions packages/app/src/runner/SpecRunnerRunMode.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<RemovePositioningDuringScreenshot
<AdjustRunnerStyleDuringScreenshot
id="main-pane"
class="flex border-gray-900 border-l-1"
class="flex border-gray-900"
>
<AutomationElement />
<AutomationDisconnected
Expand All @@ -14,7 +14,7 @@
v-else
:max-total-width="windowWidth"
:initial-panel1-width="0"
:initial-panel2-width="reporterWidth"
:initial-panel2-width="runnerUiStore.reporterWidth"
:show-panel1="false"
:show-panel2="!screenshotStore.isScreenshotting"
@resize-end="handleResizeEnd"
Expand Down Expand Up @@ -57,7 +57,7 @@
<div
v-show="!autStore.scriptError"
:id="RUNNER_ID"
class="origin-top-left viewport"
class="origin-top viewport"
:style="viewportStyle"
/>
</RemoveClassesDuringScreenshotting>
Expand All @@ -68,7 +68,7 @@
<ScreenshotHelperPixels />
</template>
</ResizablePanels>
</RemovePositioningDuringScreenshot>
</AdjustRunnerStyleDuringScreenshot>
</template>

<script lang="ts" setup>
Expand All @@ -79,7 +79,7 @@ import { useAutStore, useRunnerUiStore } from '../store'
import SnapshotControls from './SnapshotControls.vue'
import HideDuringScreenshot from './screenshot/HideDuringScreenshot.vue'
import RemoveClassesDuringScreenshotting from './screenshot/RemoveClassesDuringScreenshotting.vue'
import RemovePositioningDuringScreenshot from './screenshot/RemovePositioningDuringScreenshot.vue'
import AdjustRunnerStyleDuringScreenshot from './screenshot/AdjustRunnerStyleDuringScreenshot.vue'
import ScreenshotHelperPixels from './screenshot/ScreenshotHelperPixels.vue'
import { useScreenshotStore } from '../store/screenshot-store'
import ScriptError from './ScriptError.vue'
Expand All @@ -105,7 +105,6 @@ const runnerUiStore = useRunnerUiStore()
const {
viewportStyle,
windowWidth,
reporterWidth,
} = useRunnerStyle()

const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div :style="style">
<div
:style="style"
:class="screenshotStore.isScreenshotting ? '' : 'border-l-1'"
>
<slot />
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
These screenshots are checked into git as a good reference for what the output of the tests in screenshot.cy.tsx should be. It is sometimes useful to have easy access to compare known "good" screenshots with the real generated screenshots when developing locally.

That said, since these are manually maintained, they could easily become out of sync with the test over time. So this folder is a convenience, not a absolute source of truth.

TODO: UNIFY-1566 - add these screenshots to Percy for diffing.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions packages/app/src/runner/useAutHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useElementSize } from '@vueuse/core'
import { ref, watch } from 'vue'
import { useAutStore } from '../store'

export function useAutHeader () {
const autStore = useAutStore()
const autHeaderEl = ref<HTMLDivElement>()
const { height } = useElementSize(autHeaderEl)

watch(height, () => {
autStore.setSpecRunnerHeaderHeight(height.value)
}, {
immediate: true,
})
marktnoonan marked this conversation as resolved.
Show resolved Hide resolved

return {
autHeaderEl,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider building a full-on AutHeader component at some point (not this PR). There's enough shared logic now that is would clean up the header containers quite a bit, even if we have to disable most of the functionality in run mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

}
Loading