-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init annotations factory for usage in cypress tests
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |