scratch-www/test/integration/my-stuff.test.js

137 lines
5.4 KiB
JavaScript
Raw Normal View History

// These tests sign in as user #1
const SeleniumHelper = require('./selenium-helpers.js');
const {
buildDriver,
clickText,
clickXpath,
findByXpath,
navigate,
signIn,
urlMatches,
waitUntilDocumentReady
} = new SeleniumHelper();
const username = `${process.env.SMOKE_USERNAME}1`;
const password = process.env.SMOKE_PASSWORD;
const rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
const myStuffURL = `${rootUrl}/mystuff`;
const rateLimitCheck = process.env.RATE_LIMIT_CHECK || rootUrl;
2021-12-03 09:14:25 -05:00
jest.setTimeout(60000);
let driver;
describe('www-integration my_stuff', () => {
beforeAll(async () => {
driver = await buildDriver('www-integration my_stuff');
await navigate(rootUrl);
await signIn(username, password);
await findByXpath('//span[contains(@class, "profile-name")]');
});
afterAll(() => driver.quit());
test('verify My Stuff structure (tabs, title)', async () => {
await navigate(myStuffURL);
const header = await findByXpath('//div[@class="box-head"]/h2');
const headerVisible = await header.isDisplayed();
expect(headerVisible).toBe(true);
const allTab = await findByXpath('//li[@data-tab="projects"]/a');
const allTabVisible = await allTab.isDisplayed();
expect(allTabVisible).toBe(true);
const sharedTab = await findByXpath('//li[@data-tab="shared"]/a');
const sharedTabVisible = await sharedTab.isDisplayed();
expect(sharedTabVisible).toBe(true);
const unsharedTab = await findByXpath('//li[@data-tab="unshared"]/a');
const unsharedTabVisible = await unsharedTab.isDisplayed();
expect(unsharedTabVisible).toBe(true);
const studios = await findByXpath('//li[@data-tab="galleries"]/a');
const studiosVisible = await studios.isDisplayed();
expect(studiosVisible).toBe(true);
const trash = await findByXpath('//li[@data-tab="trash"]/a');
const trashVisible = await trash.isDisplayed();
expect(trashVisible).toBe(true);
});
test('clicking a project title should take you to the project page', async () => {
await navigate(myStuffURL);
await clickXpath('//span[@class="media-info-item title"]');
await waitUntilDocumentReady();
const gui = await findByXpath('//div[@class="guiPlayer"]');
const guiVisible = await gui.isDisplayed();
expect(guiVisible).toBe(true);
});
test('clicking "see inside" should take you to the editor', async () => {
await navigate(myStuffURL);
await clickXpath('//a[@data-control="edit"]');
await waitUntilDocumentReady();
const gf = await findByXpath('//img[@class="green-flag_green-flag_1kiAo"]');
const gfVisible = await gf.isDisplayed();
expect(gfVisible).toBe(true);
});
test('Add To button should bring up a list of studios', async () => {
await navigate(myStuffURL);
await clickXpath('//div[@id="sidebar"]/ul/li[@data-tab="shared"]');
await clickXpath('//div[@data-control="add-to"]');
const dropDown = await findByXpath('//div[@class="dropdown-menu"]/ul/li');
const dropDownVisible = await dropDown.isDisplayed();
expect(dropDownVisible).toBe(true);
});
test('+ New Project button should open the editor', async () => {
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickText('+ New Project');
await waitUntilDocumentReady();
const gf = await findByXpath('//img[@class="green-flag_green-flag_1kiAo"]');
const gfVisible = await gf.isDisplayed();
expect(gfVisible).toBe(true);
2021-07-19 12:01:23 -04:00
});
test('+ New Studio button should take you to the studio page', async () => {
await navigate(rateLimitCheck);
await navigate(myStuffURL);
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await waitUntilDocumentReady();
const tabs = await findByXpath('//div[@class="studio-tabs"]');
const tabsVisible = await tabs.isDisplayed();
expect(tabsVisible).toBe(true);
});
test('New studio rate limited to five', async () => {
await navigate(rateLimitCheck);
2021-07-19 12:01:23 -04:00
// 1st studio
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await urlMatches(/\/studios\//);
2021-07-19 12:01:23 -04:00
// 2nd studio
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await urlMatches(/\/studios\//);
2021-07-19 12:01:23 -04:00
// 3rd studio
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await urlMatches(/\/studios\//);
2021-07-19 12:01:23 -04:00
// 4th studio
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await urlMatches(/\/studios\//);
2021-07-19 12:01:23 -04:00
// 5th studio
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
await urlMatches(/\/studios\//);
2021-07-19 12:01:23 -04:00
// 6th studio should fail
await navigate(myStuffURL);
2021-07-19 12:01:23 -04:00
await clickXpath('//form[@id="new_studio"]/button[@type="submit"]');
// findByXpath checks for both presence and visibility
const alertMessage = await findByXpath('//div[contains(@class, "alert-error")]');
expect(alertMessage).toBeTruthy();
2021-07-19 12:01:23 -04:00
await navigate(rateLimitCheck);
});
});