From 95be0423df7f9692c5bacf79ad1ba864d0139365 Mon Sep 17 00:00:00 2001 From: helenanull Date: Thu, 4 Mar 2021 22:55:17 +0200 Subject: [PATCH] improvements and header spec --- cypress/integration/header.spec.js | 26 +++++++++++++++++++ cypress/integration/register.spec.js | 2 +- ...liases.spec.js => register_better.spec.js} | 2 +- cypress/selectors/header.sel.js | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 cypress/integration/header.spec.js rename cypress/integration/{register_aliases.spec.js => register_better.spec.js} (97%) diff --git a/cypress/integration/header.spec.js b/cypress/integration/header.spec.js new file mode 100644 index 0000000..2460a97 --- /dev/null +++ b/cypress/integration/header.spec.js @@ -0,0 +1,26 @@ +import header from '../selectors/header.sel' + +describe('Header', () => { + it('contains correct elements when logged out', () => { + // when visit is empty, it will visit baseUrl + cy.visit('') + cy.get(header.navbarLinks).should('be.visible') + .and('have.length', 3) + .and('contain', 'Home') + .and('contain', 'Sign in') + .and('contain', 'Sign up') + }) + + it('contains correct elements when logged in', () => { + cy.register().then((email) => { + cy.login(email) + }) + cy.visit('') + cy.get(header.navbarLinks).should('be.visible') + .and('have.length', 4) + .and('contain', 'Home') + .and('contain', 'New Article') + .and('contain', 'Settings') + .and('contain', 'cy') + }) +}) diff --git a/cypress/integration/register.spec.js b/cypress/integration/register.spec.js index e17df69..0a26a88 100644 --- a/cypress/integration/register.spec.js +++ b/cypress/integration/register.spec.js @@ -2,7 +2,7 @@ import registration from '../selectors/register.sel' import header from '../selectors/header.sel' describe('Register', () => { - // actually we should not use let here, check register_aliases.spec + // actually we should not use let here, check register_better.spec for a better solution // https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Aliases let username let email diff --git a/cypress/integration/register_aliases.spec.js b/cypress/integration/register_better.spec.js similarity index 97% rename from cypress/integration/register_aliases.spec.js rename to cypress/integration/register_better.spec.js index 664e641..d6806d7 100644 --- a/cypress/integration/register_aliases.spec.js +++ b/cypress/integration/register_better.spec.js @@ -1,7 +1,7 @@ import registration from '../selectors/register.sel' import header from '../selectors/header.sel' -describe('Register', () => { +describe('Register - duplicate of register.spec', () => { beforeEach(() => { // we need random username and email each test const random = `cy${Math.random().toString().slice(2, 8)}` diff --git a/cypress/selectors/header.sel.js b/cypress/selectors/header.sel.js index b9dfa6a..fc68f6a 100644 --- a/cypress/selectors/header.sel.js +++ b/cypress/selectors/header.sel.js @@ -1,3 +1,4 @@ module.exports = { - settingsLink: '[ui-sref*=settings]' + settingsLink: '[ui-sref*=settings]', + navbarLinks: '.navbar ul > li:visible' }