Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeline feature error when base url is set #402

Merged
merged 11 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ jobs:
working-directory: ui-tests
run: |
jlpm test
TIMELINE_FEATURE=1 jlpm test:timeline
- name: Upload Playwright Test report
if: always()
uses: actions/upload-artifact@v3
Expand Down
3 changes: 2 additions & 1 deletion packages/docprovider-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
fullPath,
provider,
provider.contentType,
provider.format
provider.format,
DOCUMENT_TIMELINE_URL
);

const elt = document.getElementById('jp-slider-status-bar');
Expand Down
6 changes: 5 additions & 1 deletion packages/docprovider/src/TimelineSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ export class TimelineWidget extends ReactWidget {
private provider: IForkProvider;
private contentType: string;
private format: string;
private documentTimelineUrl: string;

constructor(
apiURL: string,
provider: IForkProvider,
contentType: string,
format: string
format: string,
documentTimelineUrl: string
) {
super();
this.apiURL = apiURL;
this.provider = provider;
this.contentType = contentType;
this.format = format;
this.documentTimelineUrl = documentTimelineUrl;
this.addClass('jp-timelineSliderWrapper');
}

Expand All @@ -36,6 +39,7 @@ export class TimelineWidget extends ReactWidget {
provider={this.provider}
contentType={this.contentType}
format={this.format}
documentTimelineUrl={this.documentTimelineUrl}
/>
);
}
Expand Down
17 changes: 12 additions & 5 deletions packages/docprovider/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ type Props = {
provider: IForkProvider;
contentType: string;
format: string;
documentTimelineUrl: string;
};

export const TimelineSliderComponent: React.FC<Props> = ({
apiURL,
provider,
contentType,
format
format,
documentTimelineUrl
}) => {
const [data, setData] = useState({
roomId: '',
Expand Down Expand Up @@ -147,16 +149,21 @@ export const TimelineSliderComponent: React.FC<Props> = ({
function determineAction(currentTimestamp: number): 'undo' | 'redo' {
return currentTimestamp < currentTimestampIndex ? 'undo' : 'redo';
}

function extractFilenameFromURL(url: string): string {
try {
const parsedURL = new URL(url);
const pathname = parsedURL.pathname;
const segments = pathname.split('/');

return segments.slice(4 - segments.length).join('/');
const apiIndex = pathname.lastIndexOf(documentTimelineUrl);
if (apiIndex === -1) {
throw new Error(
`API segment "${documentTimelineUrl}" not found in URL.`
);
}

return pathname.slice(apiIndex + documentTimelineUrl.length);
} catch (error) {
console.error('Invalid URL:', error);
console.error('Invalid URL or unable to extract filename:', error);
return '';
}
}
Expand Down
4 changes: 3 additions & 1 deletion ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"private": true,
"scripts": {
"start": "jupyter lab --config jupyter_server_test_config.py",
"test": "npx playwright test",
"start:timeline": "jupyter lab --config jupyter_server_test_config.py --ServerApp.base_url=/api/collaboration/timeline/",
"test": "npx playwright test --config=playwright.config.js",
"test:timeline": "npx playwright test --config=playwright.timeline.config.js",
"test:update": "npx playwright test --update-snapshots"
},
"devDependencies": {
Expand Down
33 changes: 33 additions & 0 deletions ui-tests/playwright.timeline.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

/**
* Configuration for Playwright using default from @jupyterlab/galata
*/
const baseConfig = require('@jupyterlab/galata/lib/playwright-config');

module.exports = {
...baseConfig,
workers: 1,
webServer: {
command: 'jlpm start:timeline',
url: 'http://localhost:8888/api/collaboration/timeline/lab',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI
},
expect: {
toMatchSnapshot: {
maxDiffPixelRatio: 0.01
}
},
projects: [
{
name: 'timeline-tests',
testMatch: 'tests/**/timeline-*.spec.ts',
testIgnore: '**/.ipynb_checkpoints/**',
timeout: 120 * 1000
}
]
};
40 changes: 37 additions & 3 deletions ui-tests/tests/timeline-slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,51 @@ async function openNotebook(page: Page, notebookPath: string) {
await page.waitForSelector('.jp-Notebook', { state: 'visible' });
}

test.describe('Open from Path', () => {

test('should fail if there are console errors', async ({ page, tmpPath }) => {
const isTimelineEnv = process.env.TIMELINE_FEATURE || "0";
const isTimeline = parseInt(isTimelineEnv)

test.describe('Timeline Slider', () => {

isTimeline && test.use({ autoGoto: false })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I found that even with different configuration, somehow playwright overwrites the baseurl and goes to the default one (http://localhost:8888) by default so we need to use this test.use({ autoGoto: false })

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the part isTimeline && ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTimeline is the environment variable used to determine whether we are testing with the new environment or the default one. So we need to do this test.use({ autoGoto: false }) only if we are testing with the new env (when isTimeline is true like in here TIMELINE_FEATURE=1 jlpm test:timeline )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what you mean by "new environment" and "default environment"?

Copy link
Contributor Author

@Meriem-BenIsmail Meriem-BenIsmail Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "new environment" refers to the testing setup needed for this PR, which uses a custom baseUrl (/api/collaboration/timeline/) as opposed to the "default environment," where tests run with the standard baseUrl (/lab or /). The new environment is specifically configured to validate the Timeline functionality in isolation, whereas the default environment is used for general tests without the Timeline-specific context.

isTimeline is used to identify which environment is active. If isTimeline is true, we disable the automatic navigation (test.use({ autoGoto: false })) that Playwright performs, as this navigation doesn’t respect the custom baseUrl and defaults to http://localhost:8888. Disabling it allows us to manually control the navigation to the appropriate custom environment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think this is clearer:

Suggested change
isTimeline && test.use({ autoGoto: false })
if (isTimeline) {
test.use({ autoGoto: false });
}


test('should fail if there are console errors when opening from path', async ({ page, tmpPath }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this test does. It seems that you do nothing if isTimeline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to execute this test in the added timeline test environment (with the set baseurl)
but this is the test for this PR that was merged #401

if (isTimeline) {
console.log('Skipping this test.');
return;
}
const pageErrors = await capturePageErrors(page);

await page.notebook.createNew();
await page.notebook.save();
await page.notebook.close();

if(!isTimeline)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!isTimeline)

await openNotebook(page, `${tmpPath}/Untitled.ipynb`);

expect(pageErrors).toHaveLength(0);
});

test('should display in status bar without console errors when baseUrl is set', async ({ page, baseURL }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.


if (!isTimeline) {
console.log('Skipping this test.');
return;
}

await page.goto('http://localhost:8888/api/collaboration/timeline')

const pageErrors = await capturePageErrors(page);

await page.notebook.createNew();

const historyIcon = page.locator('.jp-mod-highlighted[title="Document Timeline"]');
await expect(historyIcon).toBeVisible();

await historyIcon.click();

const slider = page.locator('.jp-timestampDisplay');
await expect(slider).toBeVisible();

expect(pageErrors).toHaveLength(0);
});
});
Loading