-
Notifications
You must be signed in to change notification settings - Fork 18
test(documentation): added basic e2e tests for the new palette implementation #5338
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
Open
oliverschuerch
wants to merge
4
commits into
feat/tokens-integration-test
Choose a base branch
from
test/add-palettes-2.0-e2e-tests
base: feat/tokens-integration-test
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ffab1e9
chore(documentation): add color-scheme to documentation body
oliverschuerch 2cf59dc
chore(documentation): remove palette class from story scheme decorator
oliverschuerch 18c581e
test(documentation): add some basic e2e tests for the new palette impβ¦
oliverschuerch 9dab7c0
Merge branch 'feat/tokens-integration-test' into test/add-palettes-2.β¦
oliverschuerch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
<script src="/assets/scripts/storybook-preview-events.js"></script> | ||
<body data-color-scheme="light"> | ||
<script src="/assets/scripts/storybook-preview-events.js"></script> | ||
</body> |
This file contains hidden or 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
159 changes: 151 additions & 8 deletions
159
packages/documentation/cypress/e2e/components/palette.cy.ts
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,156 @@ | ||
describe('Palette', () => { | ||
describe('Accessibility', () => { | ||
beforeEach(() => { | ||
cy.visit('/iframe.html?id=snapshots--palette'); | ||
cy.get('.palette-default', { timeout: 30000 }).should('be.visible'); | ||
cy.injectAxe(); | ||
interface PaletteDefinition { | ||
name: string; | ||
scheme: 'even' | 'swapped' | 'light' | 'dark'; | ||
} | ||
|
||
interface ThemeDefinition { | ||
name: string; | ||
palettes: PaletteDefinition[]; | ||
} | ||
|
||
const THEME_PALETTE_DEFINITIONS: ThemeDefinition[] = [ | ||
{ | ||
name: 'Post', | ||
palettes: [ | ||
{ name: 'Default', scheme: 'even' }, | ||
{ name: 'Alternate', scheme: 'even' }, | ||
{ name: 'Accent', scheme: 'dark' }, | ||
{ name: 'Brand', scheme: 'light' }, | ||
], | ||
}, | ||
{ | ||
name: 'Cargo', | ||
palettes: [ | ||
{ name: 'Default', scheme: 'even' }, | ||
{ name: 'Aternate', scheme: 'even' }, | ||
{ name: 'Accent', scheme: 'light' }, | ||
{ name: 'Brand', scheme: 'dark' }, | ||
], | ||
}, | ||
]; | ||
|
||
function testGenerator( | ||
callback: (theme: string, scheme: string, palette: PaletteDefinition) => void, | ||
) { | ||
THEME_PALETTE_DEFINITIONS.forEach(theme => { | ||
['light', 'dark'].forEach(scheme => { | ||
theme.palettes.forEach(palette => { | ||
callback(theme.name, scheme, palette); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function isDark(color: string) { | ||
const rgb = color.match(/\d+/g); | ||
|
||
if (rgb) { | ||
const [r, g, b] = rgb.map(Number); | ||
const brightness = (r * 299 + g * 587 + b * 114) / 1000; | ||
return brightness < 128; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
describe('Palette', () => { | ||
testGenerator((theme, scheme, palette) => { | ||
const THEME_STYLES_URL = `/styles/${theme.toLowerCase()}-default.css`; | ||
|
||
describe(`${theme}: ${scheme} - Palette ${palette.name}`, () => { | ||
beforeEach(() => { | ||
cy.visit('/iframe.html?id=43481535-5b39-40b5-a273-478b07dc3b31--default'); | ||
|
||
cy.get('[data-color-scheme]', { timeout: 30000 }) | ||
.as('schemecontainer') | ||
.should('be.visible'); | ||
cy.get('link[href="/styles/post-default.css"]').as('theme-css'); | ||
cy.get('.palette').as('palette'); | ||
|
||
it('Has no detectable a11y violations on load for all variants', () => { | ||
cy.checkA11y('#root-inner'); | ||
// update theme stylesheet (if needed) | ||
cy.get('@theme-css') | ||
.invoke('attr', 'href') | ||
.then(href => { | ||
if (href !== THEME_STYLES_URL) { | ||
cy.intercept('GET', THEME_STYLES_URL).as('load-theme-styles'); | ||
cy.get('@theme-css').invoke('attr', 'href', THEME_STYLES_URL); | ||
cy.wait('@load-theme-styles'); | ||
} | ||
}); | ||
|
||
// update page color-scheme | ||
cy.get('@schemecontainer').invoke('attr', 'data-color-scheme', scheme); | ||
|
||
// update palette variant | ||
cy.get('@palette') | ||
.invoke('removeClass', 'palette-default') | ||
.invoke('addClass', `palette-${palette.name.toLowerCase()}`); | ||
}); | ||
|
||
it(`should have a color-scheme "${palette.scheme}"`, () => { | ||
cy.get('@schemecontainer').then($container => { | ||
const containerStyles = window.getComputedStyle($container.get(0)); | ||
const containerScheme = containerStyles.getPropertyValue('color-scheme'); | ||
|
||
cy.get('@palette').then($palette => { | ||
const paletteStyles = window.getComputedStyle($palette.get(0)); | ||
const paletteScheme = paletteStyles.getPropertyValue('color-scheme'); | ||
|
||
// check if palette color-scheme is set correctly, according to the page color-scheme | ||
switch (palette.scheme) { | ||
case 'even': | ||
// light on light | dark on dark | ||
expect(paletteScheme).to.equal(containerScheme); | ||
break; | ||
case 'swapped': | ||
// dark on light | light on dark | ||
expect(paletteScheme).to.not.equal(containerScheme); | ||
break; | ||
case 'light': | ||
// light on light | light on dark | ||
expect(paletteScheme).to.equal('light'); | ||
break; | ||
case 'dark': | ||
// dark on light | dark on dark | ||
expect(paletteScheme).to.equal('dark'); | ||
break; | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
it(`should have a background- and foreground-color matching its color-scheme`, () => { | ||
cy.get('@palette').then($palette => { | ||
const paletteStyles = window.getComputedStyle($palette.get(0)); | ||
const paletteScheme = paletteStyles.getPropertyValue('color-scheme'); | ||
const paletteBg = paletteStyles.getPropertyValue('background-color'); | ||
const paletteFg = paletteStyles.getPropertyValue('color'); | ||
|
||
// check if palette background- and foreground-color are set correctly, according to the palette color-scheme | ||
switch (paletteScheme) { | ||
case 'light': | ||
expect(isDark(paletteBg)).to.be.false; | ||
expect(isDark(paletteFg)).to.be.true; | ||
break; | ||
case 'dark': | ||
expect(isDark(paletteBg)).to.be.true; | ||
expect(isDark(paletteFg)).to.be.false; | ||
break; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Accessibility', () => { | ||
beforeEach(() => { | ||
cy.visit('/iframe.html?id=snapshots--palette'); | ||
cy.get('.palette-default', { timeout: 30000 }).should('be.visible'); | ||
cy.injectAxe(); | ||
}); | ||
|
||
it('Has no detectable a11y violations on load for all variants', () => { | ||
cy.checkA11y('#root-inner'); | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -17,8 +17,6 @@ export function schemes(renderFn: (scheme: string) => TemplateResult, options: I | |
return html`${[...additionalSchemes, ...Object.values(COLOR_SCHEMES)] | ||
.filter(filter) | ||
.map( | ||
scheme => html` <div data-color-scheme="${scheme}" class="p-16 palette-default"> | ||
${renderFn(scheme)} | ||
</div>`, | ||
scheme => html` <div data-color-scheme="${scheme}" class="p-16">${renderFn(scheme)}</div>`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to test how the palettes behave without a defined |
||
)}`; | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
light dark
should be the default without having the specify adata-color-scheme
attribute. Do you know why it is necessary here?