import DynamicFooter from './DynamicFooter.vue';
import { Flavor } from '@/helpers/flavor.stubabble';
import { defaultFlavorValues, dhaValues, dhfValues, myKvValues } from '@/helpers/app-flavor.constants';

const checkLinks = (baseUrl, simple = true) => {
  cy.viewport('macbook-15');
  cy.mount(DynamicFooter, {
    props: {
      simple,
    },
  });
  cy.get('a')
    .eq(0)
    .should('contain', 'Datenschutz')
    .and('have.attr', 'href')
    .and('include', `https://${baseUrl}/datenschutz`);
  cy.get('a')
    .eq(1)
    .should('contain', 'Impressum')
    .and('have.attr', 'href')
    .and('include', `https://${baseUrl}/impressum`);
  cy.get('a').eq(2).should('contain', 'AGB').and('have.attr', 'href').and('include', `https://${baseUrl}/agb`);
  cy.get('a').eq(3).should('contain', 'Support').and('have.attr', 'href').and('include', `https://${baseUrl}/support`);
};

describe('<SimpleFooter />', () => {
  it('renders for MySkillbox', () => {
    cy.viewport('macbook-15');
    // see: https://on.cypress.io/mounting-vue
    cy.stub(Flavor, 'getFlavor').returns(defaultFlavorValues);
    cy.mount(DynamicFooter, { props: { simple: true } });
    cy.get('p').eq(0).should('contain', 'Copyright');
  });
  it('renders for MyKV', () => {
    cy.stub(Flavor, 'getFlavor').returns(myKvValues);
    checkLinks('mykv.ch');
  });
  it('renders for MyDHA', () => {
    cy.stub(Flavor, 'getFlavor').returns(dhaValues);
    checkLinks('mydetailhandel.ch');
  });
  it('renders for MyDHF', () => {
    cy.stub(Flavor, 'getFlavor').returns(dhfValues);
    checkLinks('mydetailhandel.ch');
  });
});

describe('<DefaultFooter />', () => {
  it('renders for MySkillbox', () => {
    cy.viewport('macbook-15');
    // see: https://on.cypress.io/mounting-vue
    cy.stub(Flavor, 'getFlavor').returns(defaultFlavorValues);
    cy.mount(DynamicFooter, { props: { simple: false } });
    cy.get('h5').should('contain', 'Wer sind wir');
  });
  it('renders for MyKV', () => {
    cy.stub(Flavor, 'getFlavor').returns(myKvValues);
    checkLinks('mykv.ch', false);
  });
  it('renders for MyDHA', () => {
    cy.stub(Flavor, 'getFlavor').returns(dhaValues);
    checkLinks('mydetailhandel.ch', false);
  });
  it('renders for MyDHF', () => {
    cy.stub(Flavor, 'getFlavor').returns(dhfValues);
    checkLinks('mydetailhandel.ch', false);
  });
});
