All files / src/apps/dictionaries/pages/tests/e2e testUtils.ts

0% Statements 0/24
0% Branches 0/1
0% Functions 0/5
0% Lines 0/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                                                                                                                                                                 
/// <reference types="cypress" />
/// <reference types="../../../../../../cypress/support" />
 
import IDGenerator from "shortid";
 
const shortRandomID = () => {
  IDGenerator.characters(
    "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-."
  );
  return IDGenerator.generate();
};
 
export interface TestDictionary {
  name: string;
  shortCode: string;
  description: string;
  preferredSource: string;
  owner: string;
  ownerDisplayValue: string;
  ownerType: string;
  visibility: string;
  preferredLanguage: string;
  otherLanguages: string[];
}
 
export function newDictionary(): [TestDictionary, string] {
  const owner = "admin";
  const dictionary = {
    name: "Test Dictionary",
    shortCode: "TD" + shortRandomID(),
    description: "Test dictionary",
    preferredSource: "CIEL", // todo stop hard coding this, pick the nth
    owner,
    ownerDisplayValue: `${owner}(You)`,
    ownerType: "users",
    visibility: "Public",
    preferredLanguage: "English (en)",
    otherLanguages: ["French (fr)", "German (de)"]
  };
 
  return [
    dictionary,
    `/${dictionary.ownerType}/${dictionary.owner}/collections/${dictionary.shortCode}/`
  ];
}
 
function select(labelText: string, item: string) {
  cy.findByLabelText(labelText).click();
  cy.findByText(item).click();
}
 
export function createDictionary(
  dictionaryAndUrl = newDictionary()
): [TestDictionary, string] {
  const [dictionary, dictionaryUrl] = dictionaryAndUrl;
 
  cy.visit("/user/collections/");
 
  cy.findByTitle("Create new dictionary").click();
 
  cy.findByLabelText("Dictionary Name").type(dictionary.name);
  cy.findByLabelText("Short Code").type(dictionary.shortCode);
  cy.findByLabelText("Description").type(dictionary.description);
  select("Preferred Source", dictionary.preferredSource);
  select("Owner", dictionary.ownerDisplayValue);
  select("Visibility", dictionary.visibility);
  select("Preferred Language", dictionary.preferredLanguage);
  dictionary.otherLanguages.forEach(language => {
    select("Other Languages", language);
    cy.get("body").type("{esc}");
  });
 
  cy.findByText("Submit").click();
 
  // wait for request to get done
  cy.findByText("General Details");
 
  // for other test files that makes use of us
  return [dictionary, dictionaryUrl];
}