Skip to content

Commit

Permalink
test: use api to create bot in e2e tests (#3081)
Browse files Browse the repository at this point in the history
* fix todo spec

* use base url config instead of env variable

* update createBot to use api instead of UI
  • Loading branch information
a-b-r-o-w-n authored May 15, 2020
1 parent 7b618dd commit 3a6466c
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 43 deletions.
4 changes: 1 addition & 3 deletions Composer/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@
"viewportWidth": 1600,
"viewportHeight": 1200,
"defaultCommandTimeout": 8000,
"env": {
"COMPOSER_URL": "http://localhost:3000"
}
"baseUrl": "http://localhost:3000"
}
2 changes: 1 addition & 1 deletion Composer/cypress/integration/Breadcrumb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('breadcrumb', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');

// Return to Main.dialog
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/CreateNewBot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Creating a new bot', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.findByTestId('LeftNav-CommandBarButtonHome').click();
cy.findByTestId('homePage-ToolBar-New').within(() => {
cy.findByText('New').click();
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/HomePage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Home Page ', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
});

it('can open buttons in home page', () => {
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/LGPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('LG Page', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');
});

Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/LUPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('LU Page', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('ToDoBotWithLuisSample');
});

Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/LeftNavBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Left Nav Bar', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');
});

Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/LuisDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('Luis Deploy', () => {
cy.route('POST', '/api/publish/*/publish/default', { endpointURL: 'anything' });
cy.route('POST', '/api/projects/*/settings', 'OK');
cy.route('GET', '/api/publish/*/status/default', { endpointURL: 'anything' });
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('ToDoBotWithLuisSample');
});

Expand Down
8 changes: 4 additions & 4 deletions Composer/cypress/integration/NavigateUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

context('Navigate Url', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
});

it('should open Create From Scratch/Template window from a url', () => {
cy.visit(`${Cypress.env('COMPOSER_URL')}/projects/create`);
cy.visit('/projects/create');
cy.get('[data-testid="Create from scratch"]').should('be.visible');
cy.get('[data-testid="Create from template"]').should('be.visible');
});

it('should open Define Conversations window from a url', () => {
cy.visit(`${Cypress.env('COMPOSER_URL')}/projects/create/TodoSample`);
cy.visit('/projects/create/TodoSample');
cy.get('[data-testid="NewDialogName"]').should('be.visible');
});

it('should create the Open a Bot window from a location through the specified url', () => {
cy.visit(`${Cypress.env('COMPOSER_URL')}/projects/open`);
cy.visit('/projects/open');
cy.get('[data-testid="SelectLocation"]').should('be.visible');
});
});
2 changes: 1 addition & 1 deletion Composer/cypress/integration/NewDialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Creating a new Dialog', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');
cy.findByTestId('LeftNav-CommandBarButtonDesign Flow').click();
});
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/NotificationPage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Notification Page', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('ToDoBotWithLuisSample');
cy.visitPage('Notifications');
});
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/Onboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Onboarding', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample', 'Onboarding');

//enable onboarding setting
Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/RemoveDialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('RemoveDialog', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('ToDoBotWithLuisSample');
});

Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/SaveAs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Saving As', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('EchoBot', 'TestBot');
});

Expand Down
18 changes: 5 additions & 13 deletions Composer/cypress/integration/ToDoBot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('ToDo Bot', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');
});

Expand All @@ -22,9 +22,7 @@ context('ToDo Bot', () => {
cy.findByText('addtodo').click();
});

cy.withinEditor('PropertyEditor', () => {
cy.findByDisplayValue('addtodo').should('exist');
});
cy.url().should('contain', 'addtodo');
});

it('can open the ClearToDos dialog', () => {
Expand All @@ -33,9 +31,7 @@ context('ToDo Bot', () => {
cy.findByText('cleartodos').click();
});

cy.withinEditor('PropertyEditor', () => {
cy.findByDisplayValue('cleartodos').should('exist');
});
cy.url().should('contain', 'cleartodos');
});

it('can open the DeleteToDo dialog', () => {
Expand All @@ -44,9 +40,7 @@ context('ToDo Bot', () => {
cy.findByText('deletetodo').click();
});

cy.withinEditor('PropertyEditor', () => {
cy.findByDisplayValue('deletetodo').should('exist');
});
cy.url().should('contain', 'deletetodo');
});

it('can open the ShowToDos dialog', () => {
Expand All @@ -55,8 +49,6 @@ context('ToDo Bot', () => {
cy.findByText('showtodos').click();
});

cy.withinEditor('PropertyEditor', () => {
cy.findByDisplayValue('showtodos').should('exist');
});
cy.url().should('contain', 'showtodos');
});
});
2 changes: 1 addition & 1 deletion Composer/cypress/integration/TriggerCreation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Creating a new trigger', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('EmptyBot');
});

Expand Down
2 changes: 1 addition & 1 deletion Composer/cypress/integration/VisualDesigner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

context('Visual Designer', () => {
beforeEach(() => {
cy.visit(Cypress.env('COMPOSER_URL'));
cy.visit('/home');
cy.createBot('TodoSample');
// Return to Main.dialog
cy.findByTestId('ProjectTree').within(() => {
Expand Down
22 changes: 13 additions & 9 deletions Composer/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

import '@testing-library/cypress/add-commands';

Cypress.Commands.add('createBot', (bobotId: string, botName?: string) => {
cy.findByTestId('LeftNav-CommandBarButtonHome').click();
cy.findByTestId('homePage-ToolBar-New').within(() => {
cy.findByText('New').click();
Cypress.Commands.add('createBot', (botId: string, botName?: string) => {
const name = `__Test${botName || botId}`;

const params = {
storageId: 'default',
name,
description: '',
templateId: botId,
};

cy.request('post', '/api/projects', params).then(res => {
const { id: projectId } = res.body;
cy.visit(`/bot/${projectId}/dialogs/${name.toLowerCase()}`);
});
cy.findByTestId('Create from template').click({ force: true });
cy.findByTestId(`${bobotId}`).click({ force: true });
cy.findByTestId('NextStepButton').click();
cy.enterTextAndSubmit('NewDialogName', `__Test${botName || bobotId}`, 'SubmitNewBotBtn');
cy.url().should('match', /\/bot\/.*\/dialogs/);
});

Cypress.Commands.add('withinEditor', (editorName, cb) => {
Expand Down

0 comments on commit 3a6466c

Please sign in to comment.