From 018959393900c61a90bc084fa6a41e0e95337c11 Mon Sep 17 00:00:00 2001 From: Yuriy Shvorob Date: Fri, 19 Jan 2024 14:12:01 +0200 Subject: [PATCH] added test to check concatenation url with slug --- src/pageObject.test.js | 56 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/pageObject.test.js b/src/pageObject.test.js index 315b338c..7e192ba5 100644 --- a/src/pageObject.test.js +++ b/src/pageObject.test.js @@ -2,47 +2,42 @@ const { Header, PageObject, ArticlePage } = require('./pageObject'); +const logo = 'Conduit logo'; +const url = 'http://test.com'; +const slug = '/article'; +const header = new Header(); +const page = new PageObject(url); +const articlePage = new ArticlePage(url, slug); + describe('Header class', () => { it('should create an instance of Header', () => { - const header = new Header(); - expect(header) .toBeInstanceOf(Header); }); it('should contain a logo element', () => { - const header = new Header(); - expect(header.logo) - .toBe('Conduit logo'); + .toBe(logo); }); }); describe('PageObject class', () => { it('should create an instance of PageObject', () => { - const page = new PageObject('http://test.com'); - expect(page) .toBeInstanceOf(PageObject); }); it('should contain a url property', () => { - const page = new PageObject('http://test.com'); - expect(page.url) - .toBe('http://test.com'); + .toBe(url); }); it('should contain a header element as an instanse of Header', () => { - const page = new PageObject('http://test.com'); - expect(page.header) .toBeInstanceOf(Header); }); it('should contain a "clickOnLogo" method', () => { - const page = new PageObject('http://test.com'); - expect(page.clickOnLogo()) .toBe(`Click on the ${page.header.logo}`); }); @@ -50,37 +45,34 @@ describe('PageObject class', () => { describe('ArticlePage class', () => { it('should create an instance of ArticlePage', () => { - const page = new ArticlePage('http://test.com', '/test-slug'); - - expect(page) + expect(articlePage) .toBeInstanceOf(ArticlePage); }); it('should extend the PageObject class', () => { - const page = new ArticlePage('http://test.com', '/test-slug'); - - expect(page) + expect(articlePage) .toBeInstanceOf(PageObject); + + expect(articlePage.url).toBe(url + slug); }); - it('should contain a "commentButton" property', () => { - const page = new ArticlePage('http://test.com', '/test'); + it('should contain a "url" property contatenated with slug', () => { + expect(articlePage.url) + .toBe(url + slug); + }); - expect(page.commentButton) + it('should contain a "commentButton" property', () => { + expect(articlePage.commentButton) .toBe(`[Publish comment] button`); }); it('should contain a "clickOnCommentButton" method', () => { - const page = new ArticlePage('http://test.com', '/test'); - - expect(page.clickOnCommentButton()) - .toBe(`Click on the ${page.commentButton}`); + expect(articlePage.clickOnCommentButton()) + .toBe(`Click on the ${articlePage.commentButton}`); }); it('should contain a "assertPageOpened" method', () => { - const page = new ArticlePage('http://test.com', '/test'); - - expect(page.assertPageOpened()) - .toBe(`The ${page.url} is opened`); + expect(articlePage.assertPageOpened()) + .toBe(`The ${articlePage.url} is opened`); }); -}); +}); \ No newline at end of file