Skip to content

Commit

Permalink
test(lazy-sheet): adjust for Firefox
Browse files Browse the repository at this point in the history
Also:
- Improve comment in tobago-sheet.ts.
- Intro.test.js was failing in both Firefox and Webkit.
  • Loading branch information
henningn committed Nov 6, 2024
1 parent c98f9c2 commit 0d28540
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";

it("First section title is 'Intro'", function (done) {
const titleOfFirstSectionHeader = querySelectorFn("tobago-section h1");
const introLinkFn = elementByIdFn("page:navigator:nav:1:cmd");
const introLinkFn = elementByIdFn("page:navigation:nav:1:cmd");

const test = new JasmineTestTool(done);
test.setup(() => titleOfFirstSectionHeader().textContent.trim() === "Intro", null, "click", introLinkFn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import {elementByIdFn, querySelectorFn} from "/script/tobago-test.js";
import {elementByIdFn, isFirefox, querySelectorFn} from "/script/tobago-test.js";
import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";

it("initial load", function (done) {
Expand All @@ -37,7 +37,14 @@ it("focus row index 200 and scroll up", function (done) {
test.wait(() => Date.now() - timestamp > 200);
test.do(() => focusRowIndex(200));
test.wait(() => isLoaded(200));
test.do(() => expect(isLoaded(199)).toBeFalse());

if (isFirefox()) {
test.wait(() => isLoaded(199));
test.do(() => expect(isLoaded(189)).toBeFalse());
test.do(() => expect(isLoaded(190, 199)).toBeTrue());
} else {
test.do(() => expect(isLoaded(199)).toBeFalse());
}
test.do(() => expect(isLoaded(200, 209)).toBeTrue());
test.do(() => expect(isLoaded(210)).toBeFalse());

Expand All @@ -59,15 +66,27 @@ it("focus row index 300 and scroll down", function (done) {
test.wait(() => Date.now() - timestamp > 200);
test.do(() => focusRowIndex(300));
test.wait(() => isLoaded(300));
test.do(() => expect(isLoaded(299)).toBeFalse());

if (isFirefox()) {
test.wait(() => isLoaded(299));
test.do(() => expect(isLoaded(289)).toBeFalse());
test.do(() => expect(isLoaded(290, 299)).toBeTrue());
} else {
test.do(() => expect(isLoaded(299)).toBeFalse());
}
test.do(() => expect(isLoaded(300, 309)).toBeTrue());
test.do(() => expect(isLoaded(310)).toBeFalse());

test.do(() => timestamp = Date.now());
test.wait(() => Date.now() - timestamp > 200);
test.do(() => focusRowIndex(301));
test.wait(() => isLoaded(310));
test.do(() => expect(isLoaded(299)).toBeFalse());
if (isFirefox()) {
test.do(() => expect(isLoaded(289)).toBeFalse());
test.do(() => expect(isLoaded(290, 299)).toBeTrue());
} else {
test.do(() => expect(isLoaded(299)).toBeFalse());
}
test.do(() => expect(isLoaded(300, 319)).toBeTrue());
test.do(() => expect(isLoaded(320)).toBeFalse());
test.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ it("TOBAGO-2349: Lazy sheet: tobago-behavior not initialized", function (done) {
test.setup(() => name().value === "Sun", null, "click", reset);

test.do(() => focusRowIndex(18));
test.wait(() => isLoaded(18, 67));
test.do(() => expect(isLoaded(18, 67)).toBeTrue());
test.do(() => timestamp = Number(timestampElement().textContent));
test.event("click", ajaxButton, () => Number(timestampElement().textContent) > timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ function activeElementFn() {
return document.getElementById("page:testframe").contentWindow.document.activeElement;
}

export {elementByIdFn, querySelectorFn, querySelectorAllFn, activeElementFn};
function isFirefox() {
return navigator.userAgent.toLowerCase().includes('firefox');
}

export {elementByIdFn, querySelectorFn, querySelectorAllFn, activeElementFn, isFirefox};

beforeEach(function (done) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5 * 60 * 1000; //5 minutes
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export class Sheet extends HTMLElement {
const firstVisibleRow
= this.tableBody.querySelector<HTMLTableRowElement>(`tr[row-index='${lazyScrollPosition[0]}']`);
if (firstVisibleRow) {
this.sheetBody.scrollTop
= firstVisibleRow.offsetTop + lazyScrollPosition[1]; //triggers scroll event -> lazyCheck()
this.sheetBody.scrollTop = firstVisibleRow.offsetTop + lazyScrollPosition[1];
//in Firefox setting "scrollTop" triggers scroll event -> lazyCheck()
}
}

Expand Down Expand Up @@ -562,6 +562,7 @@ export class Sheet extends HTMLElement {
= this.tableBody.querySelector<HTMLTableRowElement>(`tr[row-index='${lazyScrollPosition[0]}']`);
if (firstRow) {
this.sheetBody.scrollTop = firstRow.offsetTop + lazyScrollPosition[1];
//in Firefox setting "scrollTop" triggers scroll event -> lazyCheck()
}

this.lazyActive = false;
Expand Down

0 comments on commit 0d28540

Please sign in to comment.