Skip to content

Commit

Permalink
Init annotations factory for usage in cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Aug 10, 2024
1 parent 0c602b4 commit cd642dc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/cypress/e2e/annotations_overview_spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import FactoryBot from "../support/factorybot";

describe("Annotations Overview", () => {
describe("Generic user", () => {
beforeEach(function () {
cy.createUser("teacher");
cy.createUser("admin");
cy.createUserAndLogin("generic").as("genericUser");

cy.then(() => {
FactoryBot.createNoValidate("lesson_medium", "with_video", "released").then((medium) => {
FactoryBot.create("annotation", "with_text",
{ medium_id: medium.id, user_id: this.genericUser.id });
FactoryBot.create("annotation", "with_text",
{ medium_id: medium.id, user_id: this.genericUser.id });
});

FactoryBot.createNoValidate("lesson_medium", "with_video", "released").then((medium) => {
FactoryBot.create("annotation", "with_text",
{ medium_id: medium.id, user_id: this.genericUser.id });
});
});
});

it("can view own annotations", function () {
cy.visit("/annotations/overview");
});
});
});
29 changes: 29 additions & 0 deletions spec/factories/annotations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FactoryBot.define do
factory :annotation do
medium_id { |id| id }
user_id { |id| id }

transient do
annotation_time do
# Pick a random number such that the annotation is still within the length
# of the sample video (which is around 42s seconds long)
seconds = nil
while seconds.nil? || seconds.to_f > 40.00
seconds = Faker::Number.decimal(l_digits: 2, r_digits: 2)
end
seconds
end
end

timestamp do
build(:time_stamp, total_seconds: annotation_time)
end

color { Annotation.colors.values.sample }
category { Annotation.categories.keys.sample }

trait :with_text do
comment { Faker::Lorem.sentence }
end
end
end

0 comments on commit cd642dc

Please sign in to comment.