<commit_before>import DataResourceCard from 'app/component/data-resource-card';
import Modal from 'app/component/modal';
import NotebookPreviewPage from 'app/page/notebook-preview-page';
import WorkspaceDataPage from 'app/page/workspace-data-page';
import {LinkText, ResourceCard} from 'app/text-labels';
import {extractNamespace, makeRandomName} from 'utils/str-utils';
import {findWorkspace, signIn} from 'utils/test-utils';

// Notebook server start may take a long time. Set maximum test running time to 20 minutes.
jest.setTimeout(20 * 60 * 1000);

describe('Workspace owner Jupyter notebook action tests', () => {

  beforeEach(async () => {
    await signIn(page);
  });

  /**
   * Test:
   * - Create new Workspace as the copy-to destination Workspace.
   * - Create new Workspace as copy-from Workspace and create new notebook in this Workspace.
   * - Run code to print WORKSPACE_NAMESPACE. It should match Workspace namespace from Workspace URL.
   * - Copy notebook to destination Workspace and give copied notebook a new name.
   * - Verify copied notebook is in destination Workspace.
   * - Open copied notebook and run code to print WORKSPACE_NAMESPACE. It should match destination Workspace namespace.
   * - Delete notebooks.
   */
  test('Copy notebook to another Workspace', async () => {
    // Create destination workspace
    const toWorkspace = await findWorkspace(page, {create: true}).then(card => card.getWorkspaceName());

    // Create copy-from workspace
    await findWorkspace(page, {create: true}).then(card => card.clickWorkspaceName());

    // Create notebook in copy-from workspace.
    const copyFromNotebookName = makeRandomName('pytest');
    const dataPage = new WorkspaceDataPage(page);

    // Get the billing project name from page url.
    const fromWorkspaceNamespace = extractNamespace(new URL(page.url()));

    const copyFromNotebookPage = await dataPage.createNotebook(copyFromNotebookName);

    // Run code to print out Workspace namespace.
    const code =
       'import os\n' +
       'print(os.getenv(\'WORKSPACE_NAMESPACE\'))';

    const codeOutput1 = await copyFromNotebookPage.runCodeCell(1, {code});
    expect(codeOutput1).toEqual(fromWorkspaceNamespace);

    // Exit notebook and returns to the Workspace Analysis tab.
    const analysisPage = await copyFromNotebookPage.goAnalysisPage();

    // Copy to destination Workspace and give notebook a new name.
    const copiedNotebookName = makeRandomName('copy-of');
    await analysisPage.copyNotebookToWorkspace(copyFromNotebookName, toWorkspace, copiedNotebookName);

    // Verify Copy Success modal.
    const modal = new Modal(page);
    await modal.waitForButton(LinkText.GoToCopiedNotebook);
    const textContent = await modal.getTextContent();
    const successMsg = `Successfully copied ${copyFromNotebookName}  to ${toWorkspace} . Do you want to view the copied Notebook?`;
    expect(textContent).toContain(successMsg);
    // Dismiss modal.
    await modal.clickButton(LinkText.StayHere, {waitForClose: true});

    // Delete notebook
    const deleteModalTextContent = await analysisPage.deleteResource(copyFromNotebookName, ResourceCard.Notebook);
    expect(deleteModalTextContent).toContain(`Are you sure you want to delete Notebook: ${copyFromNotebookName}?`);

    // Perform actions in copied notebook.
    // Open destination Workspace
    await findWorkspace(page, {workspaceName: toWorkspace}).then(card => card.clickWorkspaceName());
    // Get the destination Workspace namespace.
    const toWorkspaceNamespace = extractNamespace(new URL(page.url()));

    // Verify copy-to notebook exists in destination Workspace
    await dataPage.openAnalysisPage();
    const dataResourceCard = new DataResourceCard(page);
    const notebookCard = await dataResourceCard.findCard(copiedNotebookName, ResourceCard.Notebook);
    expect(notebookCard).toBeTruthy();

    // Open copied notebook and run code to verify billing project name.
    await notebookCard.clickResourceName();
    const notebookPreviewPage = new NotebookPreviewPage(page);
    await notebookPreviewPage.waitForLoad();
    const copyNotebookPage = await notebookPreviewPage.openEditMode(copiedNotebookName);

    // Run same code and compare namespace.
    const codeOutput2 = await copyNotebookPage.runCodeCell(-1, {code});
    expect(codeOutput2).toEqual(toWorkspaceNamespace);

    // Exit notebook. Returns to the Workspace Analysis tab.
    await copyNotebookPage.goAnalysisPage();
    // Delete notebook
    const modalTextContent = await analysisPage.deleteResource(copiedNotebookName, ResourceCard.Notebook);
    expect(modalTextContent).toContain('This will permanently delete the Notebook.');
  })

});<commit_msg>remove unnecessary steps (#4021)<commit_after>import DataResourceCard from 'app/component/data-resource-card';
import Modal from 'app/component/modal';
import WorkspaceDataPage from 'app/page/workspace-data-page';
import {LinkText, ResourceCard} from 'app/text-labels';
import {makeRandomName} from 'utils/str-utils';
import {findWorkspace, signIn} from 'utils/test-utils';

// Notebook server start may take a long time. Set maximum test running time to 20 minutes.
jest.setTimeout(20 * 60 * 1000);

describe('Workspace owner Jupyter notebook action tests', () => {

  beforeEach(async () => {
    await signIn(page);
  });

  /**
   * Test:
   * - Create new Workspace as the copy-to destination Workspace.
   * - Create new Workspace as copy-from Workspace and create new notebook in this Workspace.
   * - Run code to print WORKSPACE_NAMESPACE. It should match Workspace namespace from Workspace URL.
   * - Copy notebook to destination Workspace and give copied notebook a new name.
   * - Verify copied notebook is in destination Workspace.
   * - Open copied notebook and run code to print WORKSPACE_NAMESPACE. It should match destination Workspace namespace.
   * - Delete notebooks.
   */
  test('Copy notebook to another Workspace', async () => {
    // Create destination workspace
    const toWorkspace = await findWorkspace(page, {create: true}).then(card => card.getWorkspaceName());

    // Create copy-from workspace
    await findWorkspace(page, {create: true}).then(card => card.clickWorkspaceName());

    // Create notebook in copy-from workspace.
    const copyFromNotebookName = makeRandomName('pytest');
    const dataPage = new WorkspaceDataPage(page);

    const copyFromNotebookPage = await dataPage.createNotebook(copyFromNotebookName);

    // Exit notebook and returns to the Workspace Analysis tab.
    const analysisPage = await copyFromNotebookPage.goAnalysisPage();

    // Copy to destination Workspace and give notebook a new name.
    const copiedNotebookName = makeRandomName('copy-of');
    await analysisPage.copyNotebookToWorkspace(copyFromNotebookName, toWorkspace, copiedNotebookName);

    // Verify Copy Success modal.
    const modal = new Modal(page);
    await modal.waitForButton(LinkText.GoToCopiedNotebook);
    const textContent = await modal.getTextContent();
    const successMsg = `Successfully copied ${copyFromNotebookName}  to ${toWorkspace} . Do you want to view the copied Notebook?`;
    expect(textContent).toContain(successMsg);
    // Dismiss modal.
    await modal.clickButton(LinkText.StayHere, {waitForClose: true});

    // Delete notebook
    const deleteModalTextContent = await analysisPage.deleteResource(copyFromNotebookName, ResourceCard.Notebook);
    expect(deleteModalTextContent).toContain(`Are you sure you want to delete Notebook: ${copyFromNotebookName}?`);

    // Perform actions in copied notebook.
    // Open destination Workspace
    await findWorkspace(page, {workspaceName: toWorkspace}).then(card => card.clickWorkspaceName());

    // Verify copy-to notebook exists in destination Workspace
    await dataPage.openAnalysisPage();
    const dataResourceCard = new DataResourceCard(page);
    const notebookCard = await dataResourceCard.findCard(copiedNotebookName, ResourceCard.Notebook);
    expect(notebookCard).toBeTruthy();

    // Delete notebook
    const modalTextContent = await analysisPage.deleteResource(copiedNotebookName, ResourceCard.Notebook);
    expect(modalTextContent).toContain('This will permanently delete the Notebook.');
  })

});
{'fraction_non_alphanumeric': 0.09424147108637794, 'fraction_numerical': 0.0036293249455601256, 'mean_word_length': 4.37516254876463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3220291', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2208, 'n_words': 676}