-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
product-delete.spec.js
159 lines (136 loc) · 4.33 KB
/
product-delete.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
155
156
157
158
159
const { test: baseTest, expect } = require( '../../fixtures/fixtures' );
baseTest.describe( 'Products > Delete Product', () => {
const test = baseTest.extend( {
storageState: process.env.ADMINSTATE,
product: async ( { api }, use ) => {
let product = {
id: 0,
name: `Product ${ Date.now() }`,
type: 'simple',
regular_price: '12.99',
};
await api.post( 'products', product ).then( ( response ) => {
product = response.data;
} );
await use( product );
// permanently delete the product if it still exists
const r = await api.get( `products/${ product.id }` );
if ( r.status !== 404 ) {
await api.delete( `products/${ product.id }`, {
force: true,
} );
}
},
page: async ( { page, wcAdminApi }, use ) => {
// Disable the task list reminder bar, it can interfere with the quick actions
await wcAdminApi.post( 'options', {
woocommerce_task_list_reminder_bar_hidden: 'yes',
} );
await use( page );
},
} );
test( 'can delete a product from edit view', async ( {
page,
product,
} ) => {
const editUrl = `wp-admin/post.php?post=${ product.id }&action=edit`;
await test.step( 'Navigate to product edit page', async () => {
await page.goto( editUrl );
} );
await test.step( 'Move product to trash', async () => {
await page.getByRole( 'link', { name: 'Move to Trash' } ).click();
} );
await test.step( 'Verify product was trashed', async () => {
// Verify displayed message
await expect( page.locator( '#message' ).last() ).toContainText(
'1 product moved to the Trash.'
);
// Verify the product is now in the trash
await page.goto(
`wp-admin/edit.php?post_status=trash&post_type=product`
);
await expect(
page.locator( `#post-${ product.id }` )
).toBeVisible();
// Verify the product cannot be edited via direct URL
await page.goto( editUrl );
await expect(
page.getByText(
'You cannot edit this item because it is in the Trash. Please restore it and try again.'
)
).toBeVisible();
} );
} );
test( 'can quick delete a product from product list', async ( {
page,
product,
} ) => {
await test.step( 'Navigate to products list page', async () => {
await page.goto(
`wp-admin/edit.php?post_type=product&s=${ product.name }`
);
} );
await test.step( 'Move product to trash', async () => {
// mouse over the product row to display the quick actions
await page.locator( `#post-${ product.id }` ).hover();
// move product to trash
await page.locator( `#post-${ product.id } .submitdelete` ).click();
} );
await test.step( 'Verify product was trashed', async () => {
// Verify displayed message
await expect( page.locator( '#message' ).last() ).toContainText(
'1 product moved to the Trash.'
);
// Verify the product is now in the trash
await page.goto(
`wp-admin/edit.php?post_status=trash&post_type=product`
);
await expect(
page.locator( `#post-${ product.id }` )
).toBeVisible();
// Verify the product cannot be edited via direct URL
await page.goto(
`wp-admin/post.php?post=${ product.id }&action=edit`
);
await expect(
page.getByText(
'You cannot edit this item because it is in the Trash. Please restore it and try again.'
)
).toBeVisible();
} );
} );
test( 'can permanently delete a product from trash list', async ( {
page,
product,
api,
} ) => {
// trash the product
await api.delete( `products/${ product.id }`, {
force: false,
} );
await test.step( 'Navigate to products trash list page', async () => {
await page.goto(
`wp-admin/edit.php?post_status=trash&post_type=product`
);
} );
await test.step( 'Permanently delete the product', async () => {
// mouse over the product row to display the quick actions
await page.locator( `#post-${ product.id }` ).hover();
// delete the product
await page.locator( `#post-${ product.id } .submitdelete` ).click();
} );
await test.step( 'Verify product was permanently deleted', async () => {
await expect( page.locator( '#message' ).last() ).toContainText(
'1 product permanently deleted.'
);
await page.goto(
`wp-admin/post.php?post=${ product.id }&action=edit`
);
await expect(
page.getByText(
'You attempted to edit an item that does not exist. Perhaps it was deleted?'
)
).toBeVisible();
} );
} );
} );