-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor anchor-button to use element internals and anchor prox…
…y element (#31653)
- Loading branch information
1 parent
197ceb2
commit 46c3369
Showing
9 changed files
with
232 additions
and
589 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-08396f27-5b99-4a5e-b427-ddb0cc48e2be.json
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,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "refactor anchor-button to use ElementInternals, remove disabled and disabledFocusable", | ||
"packageName": "@fluentui/web-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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
120 changes: 38 additions & 82 deletions
120
packages/web-components/src/anchor-button/anchor-button.spec.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 |
---|---|---|
@@ -1,124 +1,80 @@ | ||
import { spinalCase } from '@microsoft/fast-web-utilities'; | ||
import { expect, test } from '@playwright/test'; | ||
import type { Locator, Page } from '@playwright/test'; | ||
import { fixtureURL } from '../helpers.tests.js'; | ||
|
||
// Regular Attributes | ||
const attributes = { | ||
appearance: 'primary', | ||
shape: 'rounded', | ||
size: 'medium', | ||
const proxyAttributes = { | ||
href: 'href', | ||
ping: 'ping', | ||
hreflang: 'en-GB', | ||
referrerpolicy: 'no-referrer', | ||
rel: 'external', | ||
target: '_blank', | ||
type: 'foo', | ||
ariaControls: 'testId', | ||
ariaCurrent: 'page', | ||
ariaDescribedby: 'testId', | ||
ariaDetails: 'testId', | ||
ariaErrormessage: 'test', | ||
ariaFlowto: 'testId', | ||
ariaInvalid: 'spelling', | ||
ariaKeyshortcuts: 'F4', | ||
ariaLabel: 'foo', | ||
ariaLabelledby: 'testId', | ||
ariaLive: 'polite', | ||
ariaOwns: 'testId', | ||
ariaRelevant: 'removals', | ||
ariaRoledescription: 'slide', | ||
}; | ||
|
||
// Regular Attributes | ||
const attributes = { | ||
appearance: 'primary', | ||
shape: 'rounded', | ||
size: 'medium', | ||
...proxyAttributes, | ||
}; | ||
|
||
// Boolean Attributes | ||
const booleanAttributes = { | ||
iconOnly: true, | ||
disabled: true, | ||
disabledFocusable: true, | ||
ariaAtomic: true, | ||
ariaBusy: false, | ||
ariaDisabled: true, | ||
ariaExpanded: true, | ||
ariaHaspopup: true, | ||
ariaHidden: true, | ||
}; | ||
|
||
test.describe('Anchor Button - Regular Attributes', () => { | ||
let page: Page; | ||
let element: Locator; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
await page.goto(fixtureURL('components-button-anchor--anchor-button', attributes)); | ||
element = page.locator('fluent-anchor-button'); | ||
}); | ||
test.describe('Anchor Button', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto(fixtureURL('components-button-anchor--anchor-button')); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
await page.waitForFunction(() => customElements.whenDefined('fluent-anchor-button')); | ||
}); | ||
|
||
for (const [attribute, value] of Object.entries(attributes)) { | ||
const attributeSpinalCase = spinalCase(attribute); | ||
|
||
test(`should set the regular attribute: \`${attributeSpinalCase}\` to \`${value}\` on the internal control`, async () => { | ||
await element.evaluate( | ||
(node: any, { attribute, value }) => { | ||
node.setAttribute(attribute, value); | ||
}, | ||
{ attribute: attributeSpinalCase, value }, | ||
); | ||
test(`should set the regular attribute: \`${attributeSpinalCase}\` to \`${value}\` on the element`, async ({ | ||
page, | ||
}) => { | ||
const element = page.locator('fluent-anchor-button'); | ||
|
||
await page.setContent(/* html */ ` | ||
<fluent-anchor-button ${attributeSpinalCase}="${value}"></fluent-anchor-button> | ||
`); | ||
|
||
await expect(element).toHaveJSProperty(`${attribute}`, `${value}`); | ||
}); | ||
} | ||
}); | ||
|
||
test.describe('Anchor Button - Boolean Attributes', () => { | ||
let page: Page; | ||
let element: Locator; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
await page.goto(fixtureURL('components-button-anchor--anchor-button', booleanAttributes)); | ||
element = page.locator('fluent-anchor-button'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
// Boolean attributes | ||
for (const [attribute, value] of Object.entries(booleanAttributes)) { | ||
const attributeSpinalCase = spinalCase(attribute); | ||
|
||
test(`should set the boolean attribute: \`${attributeSpinalCase}\` to \`${value}\``, async () => { | ||
await element.evaluate( | ||
(node: any, { attribute, value }) => { | ||
node[attribute] = value; | ||
}, | ||
{ attribute, value }, | ||
); | ||
test(`should set the boolean attribute: \`${attributeSpinalCase}\` to \`${value}\``, async ({ page }) => { | ||
const element = page.locator('fluent-anchor-button'); | ||
|
||
await page.setContent(/* html */ ` | ||
<fluent-anchor-button ${attributeSpinalCase}></fluent-anchor-button> | ||
`); | ||
|
||
await expect(element).toHaveJSProperty(attribute, value); | ||
}); | ||
} | ||
|
||
test(`should have transparent border when the \`disabled\` or \`disabled-focus\` attribute is present`, async ({ | ||
page, | ||
}) => { | ||
await element.evaluate((node: any) => { | ||
node.setAttribute('appearance', 'primary'); | ||
node.setAttribute('disabled', true); | ||
}); | ||
for (const [attribute, value] of Object.entries(proxyAttributes)) { | ||
test(`should set the regular attribute: \`${attribute}\` to \`${value}\` on the internal proxy`, async ({ | ||
page, | ||
}) => { | ||
const element = page.locator('fluent-anchor-button'); | ||
const proxy = element.locator('a'); | ||
|
||
await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)'); | ||
await page.setContent(/* html */ ` | ||
<fluent-anchor-button ${attribute}="${value}"></fluent-anchor-button> | ||
`); | ||
|
||
await element.evaluate((node: any) => { | ||
node.setAttribute('disabled', false); // Reset | ||
node.setAttribute('disabled-focusable', true); | ||
await expect(proxy).toHaveAttribute(`${attribute}`, `${value}`); | ||
}); | ||
|
||
await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)'); | ||
}); | ||
} | ||
}); |
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
Oops, something went wrong.