-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Button dropdown with main action creates duplicate performance m…
…ark (#2643)
- Loading branch information
1 parent
bce2ba0
commit d095831
Showing
4 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import * as React from 'react'; | ||
|
||
import ButtonDropdown from '~components/button-dropdown'; | ||
|
||
export default function ButtonDropdownPage() { | ||
return ( | ||
<> | ||
<h1>Button dropdown with main action</h1> | ||
<ButtonDropdown | ||
items={[ | ||
{ | ||
text: 'Launch instance from template', | ||
id: 'launch-instance-from-template', | ||
}, | ||
]} | ||
mainAction={{ text: 'Launch instance' }} | ||
ariaLabel="More launch options" | ||
variant="primary" | ||
/> | ||
</> | ||
); | ||
} |
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,48 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { BasePageObject } from '@cloudscape-design/browser-test-tools/page-objects'; | ||
import useBrowser from '@cloudscape-design/browser-test-tools/use-browser'; | ||
|
||
function setupTest( | ||
pageName: string, | ||
testFn: (parameters: { | ||
page: BasePageObject; | ||
getMarks: () => Promise<PerformanceMark[]>; | ||
getElementByPerformanceMark: (id: string) => Promise<WebdriverIO.Element>; | ||
}) => Promise<void> | ||
) { | ||
return useBrowser(async browser => { | ||
const page = new BasePageObject(browser); | ||
await browser.url(`#/light/button-dropdown/${pageName}`); | ||
const getMarks = async () => { | ||
const marks = await browser.execute(() => performance.getEntriesByType('mark') as PerformanceMark[]); | ||
return marks.filter(m => m.detail?.source === 'awsui'); | ||
}; | ||
const getElementByPerformanceMark = (id: string) => browser.$(`[data-analytics-performance-mark="${id}"]`); | ||
|
||
await testFn({ page, getMarks, getElementByPerformanceMark }); | ||
}); | ||
} | ||
|
||
describe('ButtonDropdown', () => { | ||
test( | ||
'Emits a single mark', | ||
setupTest('main-action', async ({ getMarks, getElementByPerformanceMark }) => { | ||
const marks = await getMarks(); | ||
|
||
expect(marks).toHaveLength(1); | ||
expect(marks[0].name).toBe('primaryButtonRendered'); | ||
expect(marks[0].detail).toMatchObject({ | ||
source: 'awsui', | ||
instanceIdentifier: expect.any(String), | ||
loading: false, | ||
disabled: false, | ||
text: 'Launch instance', | ||
}); | ||
|
||
expect(await getElementByPerformanceMark(marks[0].detail.instanceIdentifier).then(e => e.getText())).toBe( | ||
'Launch instance' | ||
); | ||
}) | ||
); | ||
}); |
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