-
Notifications
You must be signed in to change notification settings - Fork 8
/
open-document-settings-panel.ts
46 lines (41 loc) · 1.41 KB
/
open-document-settings-panel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { capitalize } from '../functions/capitalize';
import { ucFirst } from '../functions/uc-first';
/**
* Open Document Settings Panel
*
* @param name - Panel name
* @param tab - Settings tab
*
* @example
* Open featured image panel of the Post editor
* ```
* cy.openDocumentSettingsPanel('Featured image')
* ```
*
* @example
* Open Permalink panel of the Page editor
* ```
* cy.openDocumentSettingsPanel('Permalink', 'Page')
* ```
*/
export const openDocumentSettingsPanel = (name: string, tab = 'Post'): void => {
// Open Settings tab
cy.openDocumentSettingsSidebar(tab);
// WordPress prior to 5.4 is using upper-case-words for panel names
// WordPress 5.3 and below: "Status & Visibility"
// WordPress 5.4 and after: "Status & visibility"
const ucFirstName = ucFirst(name);
const ucWordsName = capitalize(name);
const panelButtonSelector = `.components-panel__body .components-panel__body-title button:contains("${ucWordsName}"),.components-panel__body .components-panel__body-title button:contains("${ucFirstName}")`;
cy.get(panelButtonSelector).then($button => {
// Find the panel container
const $panel = $button.parents('.components-panel__body');
// Only click the button if the panel is collapsed
if (!$panel.hasClass('is-opened')) {
cy.wrap($button)
.click()
.parents('.components-panel__body')
.should('have.class', 'is-opened');
}
});
};