@@ -115,45 +115,58 @@ test('handling network error', async ({ page }) => {
115115
116116 await expect ( page . locator ( 'text=Ошибка сети' , { } ) ) . toBeVisible ( )
117117} )
118- // test.describe('handle disabling ui elements during loading', () => {
119- // test('handle successful loading', async ({ page }) => {
120- // responseHandler(rssUrl, rss1);
121118
122- // // expect(await page.waitForSelector('input[name="url"][disabled=true]')).toBeVisible();
123- // expect(await page.locator('input[name="url"]')).toBeEditable();
124- // expect(await page.locator('button[type="submit"]')).toBeEnabled();
119+ test . describe ( 'handle disabling ui elements during loading' , ( ) => {
120+ test ( 'handle successful loading' , async ( { page } ) => {
121+ await page . route ( 'https://allorigins.hexlet.app/**' , async ( route ) => {
122+ await new Promise ( resolve => setTimeout ( resolve , 500 ) )
125123
126- // await page.locator('input[name="url"]').type(rssUrl);
127- // await page.locator('button[type="submit"]').click();
124+ return route . fulfill ( {
125+ status : 200 ,
126+ contentType : 'text/xml' ,
127+ body : JSON . stringify ( { contents : rss1 } ) ,
128+ } )
129+ } )
128130
129- // expect(await page.waitForSelector('input[name="url"]', { state: 'disabled' })).toBeTruthy();
130- // expect(await page.locator('input[name="url"][readonly=true]',
131- // { timeout: 1000 })).toBeVisible();
132- // expect(page.locator('button[type="submit"]')).toBeDisabled();
131+ await page . locator ( 'input[aria-label="url"]' ) . type ( rssUrl )
132+ const submitPromise = page . locator ( 'button[type="submit"]' ) . click ( )
133133
134- // expect(await page.locator('input[name="url"]')).toBeEditable();
134+ await expect ( page . locator ( 'input[aria-label="url"]' ) ) . not . toBeEditable ( )
135+ await expect ( page . locator ( 'button[type="submit"]' ) ) . toBeDisabled ( )
135136
136- // expect( await page.locator('button[type="submit"]')).toBeEnabled();
137- // });
137+ await submitPromise
138+ await expect ( page . locator ( 'text=RSS успешно загружен' ) ) . toBeVisible ( )
138139
139- // test('handle failed loading', async ({ page }) => {
140- // responseHandler(htmlUrl, html);
140+ await expect ( page . locator ( 'input[aria-label="url"]' ) ) . toBeEditable ( )
141+ await expect ( page . locator ( 'button[type="submit"]' ) ) . toBeEnabled ( )
142+ } )
141143
142- // expect(await page.locator('input[name="url"]')).toBeEditable();
143- // expect(await page.locator('button[type="submit"]')).toBeEnabled();
144+ test ( 'handle failed loading' , async ( { page } ) => {
145+ await page . route ( 'https://allorigins.hexlet.app/**' , async ( route ) => {
146+ await new Promise ( resolve => setTimeout ( resolve , 500 ) )
144147
145- // await page.locator('input[name="url"]').type(htmlUrl);
146- // await page.locator('button[type="submit"]').click();
148+ return route . fulfill ( {
149+ status : 200 ,
150+ contentType : 'text/html' ,
151+ body : JSON . stringify ( { contents : html } ) ,
152+ } )
153+ } )
147154
148- // expect(await page.locator('input[name="url"]')).not.toBeEditable();
155+ await page . locator ( 'input[aria-label="url"]' ) . type ( htmlUrl )
156+ const submitPromise = page . locator ( 'button[type="submit"]' ) . click ( )
149157
150- // expect(await page.locator('button[type="submit"]')).toBeDisabled();
158+ await expect ( page . locator ( 'input[aria-label="url"]' ) ) . not . toBeEditable ( )
159+ await expect ( page . locator ( 'button[type="submit"]' ) ) . toBeDisabled ( )
151160
152- // expect(await page.locator('input[name="url"]')).toBeEditable();
161+ await submitPromise
162+ await expect (
163+ page . locator ( 'text=Ресурс не содержит валидный RSS' ) ,
164+ ) . toBeVisible ( )
153165
154- // expect(await page.locator('button[type="submit"]')).toBeEnabled();
155- // });
156- // });
166+ await expect ( page . locator ( 'input[aria-label="url"]' ) ) . toBeEditable ( )
167+ await expect ( page . locator ( 'button[type="submit"]' ) ) . toBeEnabled ( )
168+ } )
169+ } )
157170
158171test . describe ( 'load feeds' , ( ) => {
159172 test ( 'render feed and posts' , async ( { page } ) => {
0 commit comments