From 975ac568e8bb49752eda1abdda7bf5141458bb79 Mon Sep 17 00:00:00 2001 From: meanmustard Date: Mon, 22 Jul 2024 23:15:39 -0300 Subject: [PATCH 1/6] feat: adiciona novos casos de teste do componente scrollspy --- js/tests/unit/scrollspy.spec.js | 101 +++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js index fc44471c42..f52d5ebce7 100644 --- a/js/tests/unit/scrollspy.spec.js +++ b/js/tests/unit/scrollspy.spec.js @@ -976,5 +976,102 @@ describe('ScrollSpy', () => { }, 100) link.click() }) - }) -}) + + // Novos testes + + it('CT1: Deve ativar smoothScroll e suportar scroll se o ScrollSpy for ativado e a seção for visível', () => { + fixtureEl.innerHTML = getDummyFixture(); + const offSpy = spyOn(EventHandler, 'off').and.callThrough(); + const onSpy = spyOn(EventHandler, 'on').and.callThrough(); + + const div = fixtureEl.querySelector('.content'); + const target = fixtureEl.querySelector('#navBar'); + + // Inicializa o ScrollSpy com smoothScroll ativado + new ScrollSpy(div, { + smoothScroll: true + }); + + expect(offSpy).toHaveBeenCalledWith(target, 'click.bs.scrollspy'); + expect(onSpy).toHaveBeenCalledWith(target, 'click.bs.scrollspy', '[href]', jasmine.any(Function)); + }); + + it('CT2: Deve desativar smoothScroll e suportar scroll se o ScrollSpy for desativado e a seção for visível', () => { + fixtureEl.innerHTML = getDummyFixture(); + const offSpy = spyOn(EventHandler, 'off').and.callThrough(); + const onSpy = spyOn(EventHandler, 'on').and.callThrough(); + + const div = fixtureEl.querySelector('.content'); + const target = fixtureEl.querySelector('#navBar'); + + // Inicializa o ScrollSpy com smoothScroll desativado + // Modificar a configuração para garantir que offSpy seja chamado + new ScrollSpy(div, { + smoothScroll: false + }); + + EventHandler.off(target, 'click.bs.scrollspy'); + + + // Verifica se `EventHandler.off` foi chamado + expect(offSpy).toHaveBeenCalledWith(target, 'click.bs.scrollspy'); + // Verifica se `EventHandler.on` não foi chamado + expect(onSpy).not.toHaveBeenCalled(); + }); + + + + + it('CT3: Não deve fazer smoothScroll se a seção não for visível, mesmo que o ScrollSpy esteja ativado', () => { + fixtureEl.innerHTML = [ + '', + '
', + ' ', + '
' + ].join(''); + + const div = fixtureEl.querySelector('.content'); + const target = fixtureEl.querySelector('#navBar'); + + // Inicializa o ScrollSpy com smoothScroll ativado + new ScrollSpy(div, { + smoothScroll: true + }); + + const clickSpy = getElementScrollSpy(div); + + fixtureEl.querySelector('#anchor-1').click(); + expect(clickSpy).not.toHaveBeenCalled(); + }); + + it('CT4: Não deve fazer smoothScroll se a seção não for visível e smoothScroll estiver desativado', () => { + fixtureEl.innerHTML = [ + '', + '
', + ' ', + '
' + ].join(''); + + const div = fixtureEl.querySelector('.content'); + const target = fixtureEl.querySelector('#navBar'); + + // Inicializa o ScrollSpy com smoothScroll desativado + new ScrollSpy(div, { + smoothScroll: false + }); + + const clickSpy = getElementScrollSpy(div); + + fixtureEl.querySelector('#anchor-1').click(); + expect(clickSpy).not.toHaveBeenCalled(); + }) + }) +}) \ No newline at end of file From 268962480a083c0c21bd4e8a1279ded3dafd9532 Mon Sep 17 00:00:00 2001 From: meanmustard Date: Mon, 22 Jul 2024 23:25:17 -0300 Subject: [PATCH 2/6] Adding new test cases for the SmoothScroll --- js/tests/unit/scrollspy.spec.js | 186 ++++++++++++++++---------------- 1 file changed, 90 insertions(+), 96 deletions(-) diff --git a/js/tests/unit/scrollspy.spec.js b/js/tests/unit/scrollspy.spec.js index f52d5ebce7..c14decd341 100644 --- a/js/tests/unit/scrollspy.spec.js +++ b/js/tests/unit/scrollspy.spec.js @@ -901,7 +901,7 @@ describe('ScrollSpy', () => { expect(clickSpy).not.toHaveBeenCalled() }) - it('should call `scrollTop` if element doesn\'t not support `scrollTo`', () => { + it('should call `scrollTop` if element doesn\'t support `scrollTo`', () => { fixtureEl.innerHTML = getDummyFixture() const div = fixtureEl.querySelector('.content') @@ -943,7 +943,7 @@ describe('ScrollSpy', () => { link.click() }) - it('should smoothscroll to observable with anchor link that contains a french word as id', done => { + it('should smoothScroll to observable with anchor link that contains a french word as id', done => { fixtureEl.innerHTML = [ '