-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
organization-tab-product-block-editor.spec.js
154 lines (118 loc) · 3.99 KB
/
organization-tab-product-block-editor.spec.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const { test } = require( '../../../../fixtures/block-editor-fixtures' );
const { expect } = require( '@playwright/test' );
const { clickOnTab } = require( '../../../../utils/simple-products' );
const NEW_EDITOR_ADD_PRODUCT_URL =
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;
const productData = {
name: `Simple product Name ${ new Date().getTime().toString() }`,
summary: 'This is a product summary',
productPrice: '100',
salePrice: '90',
};
const categoryName = `my-category-${ new Date().getTime().toString() }`;
const tagName = `my-tag-${ new Date().getTime().toString() }`;
test.describe.configure( { mode: 'serial' } );
test.describe( 'General tab', () => {
test.describe( 'Create product - Organization tab', () => {
let productId;
test.skip(
isTrackingSupposedToBeEnabled,
'The block product editor is not being tested'
);
test( 'can create a simple product with categories, tags and with passowrd required', async ( {
page,
} ) => {
await page.goto( NEW_EDITOR_ADD_PRODUCT_URL );
await clickOnTab( 'General', page );
await page
.getByPlaceholder( 'e.g. 12 oz Coffee Mug' )
.fill( productData.name );
await page
.locator(
'[data-template-block-id="basic-details"] .components-summary-control'
)
.last()
.fill( productData.summary );
await clickOnTab( 'Pricing', page );
const regularPrice = page
.locator( 'input[name="regular_price"]' )
.first();
await regularPrice.waitFor( { state: 'visible' } );
await regularPrice.click();
await regularPrice.fill( productData.productPrice );
const salePrice = page
.locator( 'input[name="sale_price"]' )
.first();
await salePrice.waitFor( { state: 'visible' } );
await salePrice.click();
await salePrice.fill( productData.salePrice );
await clickOnTab( 'Organization', page );
await page
.locator( '[id^="woocommerce-taxonomy-select-"]' )
.click();
await page.locator( 'text=Create new' ).click();
await page
.locator( '[id^="taxonomy_name-"]' )
.first()
.fill( categoryName );
await page
.locator( '.woocommerce-create-new-taxonomy-modal__buttons' )
.getByRole( 'button', {
name: 'Create',
} )
.click();
await page.locator( '[id^="tag-field-"]' ).click();
await page.locator( 'text=Create new' ).click();
await page
.locator( '[id^="inspector-text-control-"]' )
.first()
.fill( tagName );
await page
.locator( '.woocommerce-create-new-tag-modal__buttons' )
.getByRole( 'button', {
name: 'Save',
} )
.click();
await page
.getByRole( 'checkbox', { name: 'Require a password' } )
.first()
.check();
await page
.locator( '[id^="post_password-"]' )
.first()
.fill( 'password' );
await page
.locator( '.woocommerce-product-header__actions' )
.getByRole( 'button', {
name: 'Publish',
} )
.click();
const element = page.locator( 'div.components-snackbar__content' );
const textContent = await element.innerText();
await expect( textContent ).toMatch( /Product published/ );
const title = page.locator( '.woocommerce-product-header__title' );
// Save product ID
const productIdRegex = /product%2F(\d+)/;
const url = page.url();
const productIdMatch = productIdRegex.exec( url );
productId = productIdMatch ? productIdMatch[ 1 ] : null;
await expect( productId ).toBeDefined();
await expect( title ).toHaveText( productData.name );
await page.goto( `/?post_type=product&p=${ productId }` );
await page
.locator( 'input[name="post_password"]' )
.fill( 'password' );
await page.getByRole( 'button', { name: 'Enter' } ).click();
await expect(
page.getByRole( 'heading', { name: productData.name } )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: categoryName } )
).toBeVisible();
await expect(
page.getByRole( 'link', { name: tagName } )
).toBeVisible();
} );
} );
} );