Skip to content

Commit

Permalink
fix(unify): fixing icons and supporting router within the shared cypr…
Browse files Browse the repository at this point in the history
…ess commands package
  • Loading branch information
JessicaSachs committed Sep 24, 2021
1 parent fdfc993 commit 3676263
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 128 deletions.
43 changes: 26 additions & 17 deletions packages/app/.windicss/icon-color-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import createPlugin from 'windicss/plugin'
import { reduce, kebabCase, isObject } from 'lodash'
import Colors from 'windicss/colors'

interface RuleConfig {
name: string
theme?: (key: string) => string
weight?: string
color?: string
}
interface RuleConfig {
name: string
theme?: (key: string) => string
weight?: string
color?: string
}

const makeRuleForClass = ({ name, theme, weight, color }: RuleConfig) => {
const resolvedColor = color ? color : weight ? theme(`colors.${name}.${weight}`) : theme(`colors.${name}`)
Expand All @@ -37,14 +37,23 @@ const makeRuleForClass = ({ name, theme, weight, color }: RuleConfig) => {
'> *[stroke].icon-light': {
stroke: resolvedColor,
},
'> *[fill][stroke].icon-light-fill': {
fill: resolvedColor,
},
},
[darkKey]: {
'> *[fill].icon-dark-fill': {
fill: resolvedColor,
},
'> *[fill].icon-dark': {
fill: resolvedColor,
},
'> *[stroke].icon-dark': {
stroke: resolvedColor,
},
'> *[fill][stroke].icon-dark-stroke': {
stroke: resolvedColor,
},
},
}
}
Expand Down Expand Up @@ -73,17 +82,17 @@ function addIconUtilityClasses (theme) {
// Output is an object where each new class is a key
// And the selectors and values affected are values
/**
* {
* `.icon-light-green-500`: {
* '> *[stroke].icon-light': {
* stroke: resolvedColor
* },
* '> *[fill].icon-light': {
* fill: resolvedColor
* }
* }
* }
*/
* {
* `.icon-light-green-500`: {
* '> *[stroke].icon-light': {
* stroke: resolvedColor
* },
* '> *[fill].icon-light': {
* fill: resolvedColor
* }
* }
* }
*/
return { ...acc, ...additionalClasses }
}, {

Expand Down
5 changes: 4 additions & 1 deletion packages/app/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@packages/frontend-shared/cypress/support/commands'
import { registerMountFn } from '@packages/frontend-shared/cypress/support/commands'
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
Expand All @@ -20,3 +20,6 @@ import 'virtual:windi.css'
import '../../src/main.scss'
import '@iconify/iconify'
import '@purge-icons/generated'
import { createRouter } from '../../src/router/router'

registerMountFn({ plugins: [() => createRouter()] })
2 changes: 1 addition & 1 deletion packages/app/src/assets/icons/play-large_x16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/app/src/assets/icons/play-small_x16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/app/src/assets/icons/settings_x24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions packages/app/src/navigation/SidebarNavigationRow.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SidebarNavigationRow from './SidebarNavigationRow.vue'
import BookIcon from '~icons/cy/book_x16'
import SettingsIcon from '~icons/mdi/settings'
import HeartIcon from '~icons/mdi/heart'
import BookmarkIcon from '~icons/bi/bookmark-star'
import BookIcon from '~icons/cy/book_x24'
import SettingsIcon from '~icons/cy/settings_x24'
import TestResultsIcon from '~icons/cy/test-results_x24'
import PlaceholderIcon from '~icons/cy/placeholder_x24'

describe('SidebarNavigationRow', () => {
it('renders something', () => {
Expand All @@ -12,8 +12,8 @@ describe('SidebarNavigationRow', () => {
<h2 class="text-white text-sm uppercase truncate">Tab Style</h2>
<SidebarNavigationRow icon={BookIcon} active/>
<SidebarNavigationRow icon={SettingsIcon} />
<SidebarNavigationRow icon={HeartIcon} />
<SidebarNavigationRow icon={BookmarkIcon} active/>
<SidebarNavigationRow icon={TestResultsIcon} />
<SidebarNavigationRow icon={PlaceholderIcon} />
</div>))
})
})
204 changes: 104 additions & 100 deletions packages/frontend-shared/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { testUrqlClient } from '@packages/frontend-shared/src/graphql/testUrqlCl
import { Component, computed, watch, defineComponent, h } from 'vue'
import { ClientTestContext } from '../../src/graphql/ClientTestContext'
import type { TestSourceTypeLookup } from '@packages/graphql/src/testing/testUnionType'
import { createI18n } from '@packages/launchpad/src/locales/i18n'
import { each } from 'lodash'
import 'cypress-file-upload'

/**
Expand All @@ -19,9 +19,45 @@ import 'cypress-file-upload'
send: () => {},
}

Cypress.Commands.add(
'mount',
<C extends Parameters<typeof mount>[0]>(comp: C, options: CyMountOptions<C> = {}) => {
export const registerMountFn = ({ plugins }) => {
Cypress.Commands.add(
'mount',
<C extends Parameters<typeof mount>[0]>(comp: C, options: CyMountOptions<C> = {}) => {
const context = new ClientTestContext({
config: {},
cwd: '/dev/null',
// @ts-ignore
browser: null,
global: false,
project: '/dev/null',
projectRoot: '/dev/null',
invokedFromCli: true,
testingType: 'e2e',
os: 'darwin',
_: [''],
}, {})

options.global = options.global || {}
options.global.stubs = options.global.stubs || {}
options.global.stubs.transition = false
options.global.plugins = options.global.plugins || []
each(plugins, (pluginFn: () => any) => {
options?.global?.plugins?.push(pluginFn())
})

options.global.plugins.push({
install (app) {
app.use(urql, testUrqlClient({
context,
}))
},
})

return mount(comp, options)
},
)

function mountFragment<Result, Variables, T extends TypedDocumentNode<Result, Variables>> (source: T, options: MountFragmentConfig<T>, list: boolean = false): Cypress.Chainable<ClientTestContext> {
const context = new ClientTestContext({
config: {},
cwd: '/dev/null',
Expand All @@ -36,111 +72,79 @@ Cypress.Commands.add(
_: [''],
}, {})

options.global = options.global || {}
options.global.stubs = options.global.stubs || {}
options.global.stubs.transition = false
options.global.plugins = options.global.plugins || []
options.global.plugins.push(createI18n())
options.global.plugins.push({
install (app) {
app.use(urql, testUrqlClient({
context,
}))
},
})

return mount(comp, options)
},
)

function mountFragment<Result, Variables, T extends TypedDocumentNode<Result, Variables>> (source: T, options: MountFragmentConfig<T>, list: boolean = false): Cypress.Chainable<ClientTestContext> {
const context = new ClientTestContext({
config: {},
cwd: '/dev/null',
// @ts-ignore
browser: null,
global: false,
project: '/dev/null',
projectRoot: '/dev/null',
invokedFromCli: true,
testingType: 'e2e',
os: 'darwin',
_: [''],
}, {})

let hasMounted = false

return mount(defineComponent({
name: `mountFragment`,
setup () {
const fieldName = list ? 'testFragmentMemberList' : 'testFragmentMember'
const result = useQuery({
query: `
query MountFragmentTest {
${fieldName} {
...${(source.definitions[0] as FragmentDefinitionNode).name.value}
let hasMounted = false

return mount(defineComponent({
name: `mountFragment`,
setup () {
const fieldName = list ? 'testFragmentMemberList' : 'testFragmentMember'
const result = useQuery({
query: `
query MountFragmentTest {
${fieldName} {
...${(source.definitions[0] as FragmentDefinitionNode).name.value}
}
}
}
${print(source)}
`,
})

if (!options.expectError) {
watch(result.error, (o) => {
if (result.error.value) {
cy.log('GraphQL Error', result.error.value).then(() => {
throw result.error.value
})
}
${print(source)}
`,
})
}

return {
gql: computed(() => result.data.value?.[fieldName]),
}
},
render: (props) => {
if (props.gql && !hasMounted) {
hasMounted = true
Cypress.log({
displayName: 'gql',
message: (source.definitions[0] as FragmentDefinitionNode).name.value,
consoleProps () {
return {
gql: props.gql,
source: print(source),
if (!options.expectError) {
watch(result.error, (o) => {
if (result.error.value) {
cy.log('GraphQL Error', result.error.value).then(() => {
throw result.error.value
})
}
},
}).end()
}
})
}

return props.gql ? options.render(props.gql) : h('div')
},
}), {
global: {
stubs: {
transition: false,
return {
gql: computed(() => result.data.value?.[fieldName]),
}
},
plugins: [
createI18n(),
{
install (app) {
app.use(urql, testUrqlClient({
context,
rootValue: options.type(context),
}))
},
render: (props) => {
if (props.gql && !hasMounted) {
hasMounted = true
Cypress.log({
displayName: 'gql',
message: (source.definitions[0] as FragmentDefinitionNode).name.value,
consoleProps () {
return {
gql: props.gql,
source: print(source),
}
},
}).end()
}

return props.gql ? options.render(props.gql) : h('div')
},
}), {
global: {
stubs: {
transition: false,
},
],
},
}).then(() => context)
}
plugins: [
{
install (app) {
app.use(urql, testUrqlClient({
context,
rootValue: options.type(context),
}))
},
},
],
},
}).then(() => context)
}

Cypress.Commands.add('mountFragment', mountFragment)
Cypress.Commands.add('mountFragment', mountFragment)

Cypress.Commands.add('mountFragmentList', (source, options) => {
return mountFragment(source, options, true)
})
Cypress.Commands.add('mountFragmentList', (source, options) => {
return mountFragment(source, options, true)
})
}

type GetRootType<T> = T extends TypedDocumentNode<infer U, any>
? U extends { __typename?: infer V }
Expand Down
5 changes: 4 additions & 1 deletion packages/launchpad/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import '@packages/frontend-shared/cypress/support/commands'
import { registerMountFn } from '@packages/frontend-shared/cypress/support/commands'
import { createI18n } from '@packages/launchpad/src/locales/i18n'

registerMountFn({ plugins: [() => createI18n()] })

0 comments on commit 3676263

Please sign in to comment.